# Doesn't Pyscipopt handle nonlinear objective functions?

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 ###
for pat in Pattern:
### 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])
**(el[r,p,s]-1)) for (r,p,s) in RouteTimeStop[:200])
for pat in RTSPdict[r,p,s])**el[r,p,s] for (r,p,s) in RouteTimeStop[:200]),
'maximize')
### 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]$$.

• Without looking in detail in your specific function, it might help to introduce an auxiliary variable $z$ for your objective and then add the nonlinear constraint $z \le f(x)$ where $f$ is the objective function. SCIP supports nonlinear constraints but only linear objectives. – Robert Schwarz Jan 20 at 8:50
• Well tried it, but starting to believe if Scip is a hoax. It shows running but nothing happening (no output logs) for hours. I have 10,000 variables. Maybe, it is because of that... – tcokyasar Jan 20 at 17:50
• Is your model supposed to be convex if you ignore the integer constraints. – ErlingMOSEK Jan 21 at 9:24
• Since you use Scip I assumed some variables had to be integer constrained e.g. binary. If that is not case then Scip is may not be best option. Also the best option is very much dependent on whether your model is convex. – ErlingMOSEK Jan 22 at 6:28
• Ok. If there are no integer variables then using something like Ipopt or Knitro might be your best option. – ErlingMOSEK Jan 22 at 14:38