1
$\begingroup$

In this case, the shop want to maximise the profit that is there $n$ products the shop can procure, but the shop only has $w$ budget. The cost of each product $x_i$ is $c_i$.

I used prediction model and predict each product $x_i$ will have total $N_i$ sales in the future 10 days. The selling price of each product $x_i$ is $s_i$.

So, I give the objective function $f$:

$$ max f=\sum_{i}^{n}(s_i - c_i)x_i \\ s.t.\\ x_i \in Z \\ \sum_{i}^{n} c_ix_i \leq w \\ x_i \leq N_i\\ i = 1,2, ..., n $$

where $n$, $w$, $s_i$, $c_i$ and $N_i$ are all constants.

I want to solve this integer programming by python. But what I find online is more about linear programming. Is there any friendly Python package solver?

$\endgroup$
5
  • $\begingroup$ Hi @mmmm, are you trying to model that $x_i$ cannot exceed $N_i$? In that case you should impose $x_i\leq N_i$ directly $\endgroup$
    – Sune
    Nov 7, 2022 at 21:17
  • $\begingroup$ Your Maxf is the function that you are going to maximize. You'd need a solver either scipy/optimize or commercial ones like Gurobi/CPLEX\ I am not sure about the 2nd constraint. Assuming $x_i$ is your decision variable then is it like either $x_i$ retains its value or takes $N_i$ if $N_i$<$x_i$? $\endgroup$
    – Sutanu
    Nov 7, 2022 at 22:25
  • $\begingroup$ hi, I am editing my question, please check the latest version $\endgroup$
    – mmmm
    Nov 7, 2022 at 22:47
  • $\begingroup$ As stated by @prubin you need to use a solver like gurobipy. But one thing, your sales forecast says $N_i$. Do you really want to produce $x_i$ fewer than $N_i$? While there are more complicated cost like waste or lost sales but I guess it should be $x_i>=N_i$ while constraining the budget. Otherwise depending upon revenue & cost solver may take most of x as 0.\ Gurobi has python API or you can try scipy /optimize as problem is linear. $\endgroup$
    – Sutanu
    Nov 7, 2022 at 23:44
  • $\begingroup$ @Sutanu You cannot sell more than the demand, so $x_i \le N_i$ is correct. $\endgroup$
    – RobPratt
    Nov 8, 2022 at 0:47

1 Answer 1

2
$\begingroup$

Both PuLP and Pyomo are widely used open-source Python modeling libraries with links to a variety of solver packages, both open-source and commercial.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.