# [Ipopt] Are piecewise functions constraints depending of a state variable allowed?

Pablo Perez pabloperez555 at hotmail.com
Tue Oct 11 20:06:14 EDT 2016

```Hello,

I am researching in nlp applied to optimal control, specifically in an very simple electric point mass vehicle model based in the ampl example provide by Ipopt source code and defined by the next dae:

# min tf
# dx/dt = v
# dv/dt = u - R*v^2
# x(0)=0; x(tf)=L
# v(0)=0; v(tf)=0
# -3 <= u <= 1 (engine constraint)
#
#          {v <= 7m/s ===> u < 1
# u <= {                                                (electric car constraint)
#          {v >  7m/s ===> u < 1*7/v
#
# -1.5 <= dv/dt <= 0.8 (comfort constraint -> smooth driving)
# -0.5 <= d2v/dt2 <= 0.5 (comfort constraint -> jerk)
# v <= Vmax (40 kmh[0-500m] + 25 kmh(500-1000m])

As you can see, the acceleration provided by the electric engine (the only control variable, by the way) must be modelled as a piecewise equation, because it is define by constant acceleration until reaching a specific speed, and then by a constant power hyperbola depending of the vehicle speed (a state variable). Something close happens with the maximum allowed speed constraint, it is a piesewise constraint depending of the distance run by the vehicle (another state variable)

I could model that easily in AMPL, but I would like to migrate to an open source library, so I first tried Pyomo, but it does not work due that this kind of constraints are not allowed by it, due that constrain are not defined as callbacks that are called by the solver in every iteration, but as a container filler called once at model creation, so I wonder if I could use Ipopt c++ interface directly.

1) If so, I have not found anything even close to this in the examples repository, could someone show me how to do it using some code example?

2) Does retaping be used for solving this issue?