I wanna learn how to solve non-linear programs using the docplex library. according to this link
I should be able to run the model as a QP. But when running the model I got the error: DOcplexException: Model<portfolio_miqp> has not been solved yet
. So I'm wondering if it is because of some theory that I'm not aware of (I'm just starting to study optimization) or if it is because I'm making a syntax error. Below the problem I'm trying to solve:
- A retailer buys an item from a supplier for $c=\\\$500$ and sells it to its customers for $p=\\\$700$.
- The retailer experiences a constant daily demand of $d=20$ units per day for the item.
- If the retailers spend $\\\$x$ dollars on advertisement daily, it will increase daily demand by $\sqrt{x}/10$ units.
- Lead time for procuring the item from the supplier is two days.
- There is a fixed cost of $f=\\\$2,000$ for placing an order. This cost does not depend on the number of units ordered.
- There is a variable cost of $h=\\\$5$ per day associated with holding an item in the retailer’s inventory.
- Customers' demands must be met without backorders.
- The retailer wishes to maximize profit.
- Lead time can be assumed to be zero.
- Retailer orders only when inventory drops to zero.
- The optimal order quantity does not change with time.
- Optimum quantity of items to order $Q$.
- Period between order (days) $T$.
- Advertisement investment $x$.
- Demand must be equal to the order $(d+\alpha{(x)})T=Q$.
- Maximize profits: $(p-c)(d+\alpha{(x)})-\frac{hQ}{2}-\frac{f}{T}-x$ Then the algebraic model can be written as follows:
\begin{aligned}
\text{Maximize:} \quad & \; (p-c)(d+\alpha{(x)})-\frac{hQ}{2}-\frac{f}{T}-x \\
\text{Subject to:} \quad & (d+\alpha{(x)})T=Q\\
\quad & Q >0\\
\quad & x\geq 0
\end{aligned}
Note that the objective function was derivate from the problem. I didn't include how the objective function was developed. Because I'm extracting the problem from an example solved in class which was solved using the GRG Nonlinear method that comes with the solver extension in excel.
The code I'm running is:
from docplex.mp.model import Model
import math
mdl = Model(name='portfolio_miqp')
Q = mdl.continuous_var(name='Quantity of Items')
T = mdl.continuous_var(name='Period in days')
x = mdl.continuous_var(name='Advertisement per day')
alpha = 0.1
c = 500
p = 700
d = 20
f = 2000
h = 5
mdl.add_constraint((d + alpha*math.sqrt(x))*T == Q)
profit = (p-c)*(d + alpha*math.sqrt(x)) - (h*Q)/2 - f/T-x
mdl.maximize(profit)
mdl.solve()