I am trying to solve a large-scale nonlinear problem. Below is the objective function coded for pyscipopt. I have some loops over a list of tuples (r,p,s) in the list RouteTimeStop, and the only variable is headway[pat]. When I looped over RouteTimeStop, the solver stuck at the objective function creation and did not produce any progress for quite a long time. Then, I tried to see what is going on and considered first 200 tuples of the list.
### BEGIN DECLARING THE MODEL ###
m = Model('CTA')
### END DECLARING THE MODEL ###
### BEGIN ADDING VARIABLES INTO THE MODEL m ###
headway = {}
for pat in Pattern:
headway[pat] = m.addVar(vtype = "C", lb = 1, ub = 30, name = "headway (%s)"%(pat))
print("Added the variables.")
### END ADDING VARIABLES INTO THE MODEL m ###
### BEGIN INTRODUCING THE OBJECTIVE FUNCTION INTO m ###
m.setObjective(quicksum(b/2/(1-el[r,p,s])*con2[r,p,s]*(30**(1-el[r,p,s])
-(quicksum(pattern_ratio[r,p,s,pat]*30*headway[pat] for pat in RTSPdict[r,p,s])/30)
**(el[r,p,s]-1)) for (r,p,s) in RouteTimeStop[:200])
+ quicksum(con[r,p,s]*quicksum(pattern_ratio[r,p,s,pat]*30*headway[pat]
for pat in RTSPdict[r,p,s])**el[r,p,s] for (r,p,s) in RouteTimeStop[:200]),
'maximize')
print("Added the objective function.")
### END INTRODUCING THE OBJECTIVE FUNCTION ###
The solver produced the following error.
Added the variables.
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-40-164bed181b42> in <module>
11
12 ### BEGIN INTRODUCING THE OBJECTIVE FUNCTION INTO m ###
---> 13 m.setObjective(quicksum(b/2/(1-el[r,p,s])*con2[r,p,s]*(30**(1-el[r,p,s])
14 -(quicksum(pattern_ratio[r,p,s,pat]*30*headway[pat] for pat in RTSPdict[r,p,s])/30)
15 **(el[r,p,s]-1)) for (r,p,s) in RouteTimeStop[:200])
src/pyscipopt/scip.pyx in pyscipopt.scip.Model.setObjective()
AssertionError: given coefficients are neither Expr or number but SumExpr
After playing a bit with the objective function, I realized number / variable and variable ^ number are not accepted in the objective function. How can I deal with this issue?
Below is a math formulation of the objective function (some notation names do differ between the code and the math formulation):
$$max \sum_{(r,p,s)\in RTS}e_{r,p,s}(h_{pat})+b w_{r,p,s}(h_{pat})\tag{1}$$
where
$$\tag{2}e_{r,p,s}(h_{pat})=C_{r,p,s}\left(\sum_{pat\in \pi_{r,p,s}}l_{pat}^{r,p,s}\frac{30}{h_{pat}}\right)^{\beta_{r,p,s}}$$
$$\tag{3}w_{r,p,s}(h_{pat})=\frac{C_{r,p,s}^\prime}{2\left(1-\beta_{r,p,s}\right)}\left[30^{\left(1-\beta_{r,p,s}\right)}-\left(\frac{\sum_{pat\in \pi_{r,p,s}}l_{pat}^{r,p,s}\frac{30}{h_{pat}}}{30}\right)^{\beta_{r,p,s}-1}\right]$$
Here, $h_{pat}\in\mathbb{R}^+$ and is the only variable. The parameter $\beta_{r,p,s}\in[0.01,0.95]$.