Variable scaling and "Maximum_Iterations_Exceeded"

700 views
Skip to first unread message

Rémy MARION

unread,
Mar 8, 2018, 1:02:36 PM3/8/18
to CasADi
Hello,

I'm a new user of Casadi in Python. Especially with Opti stack.

I'm playing with Casadi to make a modelisation of a runner. My modelisation works fine for 100m race and 1500m. When I want to increase the lenght of the race (for example for a Marathon : 42195m), I have the message "Maximum_Iterations_Exceeded". I tried to increase the maximum iteration by using :

opti.solver("ipopt", {"expand":True}, {"max_iter":5000})

I have the same message "
Maximum_Iterations_Exceeded". The solver should not converge. I decided so to try 2 solutions :

  • Variable scaling for may be optimize the reaction of the solver (thre is an example in the Casadi blog) :

X = repmat([45000;7;2500],1,N).*opti.variable(3,N+1)        # variables d'état
pos    = X[0,:]                                                               # position
speed  = X[1,:]                                                             # vitesse
energy  = X[2,:]                                                            # energie
f = 15*opti.variable(1,N)                                                 # force
T = opti.variable()                                                         # temps final de la course


I took the wording in the Matlab example but it doesn't work with Python. What is the right wording for Python? pos is 42195 max, speed is 7 max, energy is 2500 max and f is 15 max.

I have the message :


    X = repmat([45000;7;2500],1,N).*opti.variable(3,N+1)        # variables d'état
                     ^
SyntaxError: invalid syntax


  • Debugging using Callback function for trying understand why the solver doen't converge:

I tried the following code for trying catch the evolution of the T variable  :


opti.solver("ipopt", {"expand":True}, {"max_iter":5000})
sol = opti.solve()                                                        # lancement du solver

plt.figure(1)
opti.callback(lambda i: plt.plot(opti.debug.value(T)))
plt.show()


But no graph, nothing.


Do you have ideas ?


Thanks by advance.


Rémy





Joris Gillis

unread,
Mar 8, 2018, 4:16:52 PM3/8/18
to CasADi
Hi Remy,

".*" means element-wise multiplication in Matlab. The Python equivalent is "*".
The callback command should be put before the solve call.

You may need to look up some tutorial on interactive plotting in matplotlib to tweak it a little bit.

Best regards,
   Joris

Rémy MARION

unread,
Mar 10, 2018, 5:54:05 AM3/10/18
to CasADi
Hi Joris,

The Variable Scaling is very powerful. The calculation time decrease a lot for a more efficient results. It is clearly a key point. Everybody needs to read your blog.

But sometimes, the code doesn't converge. It is OK for 100m, 400m, 800m, 1500m, 10km and semi-marathon but when I want to make a calculation for 42195m (marathon), the solver failed (infeasible problem). It is however the same code !!! Of course, for each case, I tweak finely the Variable Scaling.

I saw that there is a new function in Opti.stack Casadi 3.4 to catch the infeasible problems. I will play with it for trying understand.

Thanks for your kelp. Step by step, I'm learning Optimisation, Casadi and for sure, one day, my code will be setted.

Rémy
Reply all
Reply to author
Forward
0 new messages