opti.set_initial: Retrieving initial values later

820 views
Skip to first unread message

Wesley Roozing

unread,
Aug 12, 2021, 11:26:43 AM8/12/21
to CasADi
First off, thanks for the great work on the opti stack (and Casadi itself), it's been a pleasure to use!

I have a problem in which I give some parameters an initial value using opti.set_initial(). However, I would like to retrieve the set value somewhere else in the code, preferably without manually storing it somewhere myself. The same goes for expressions. The reason is that I'm computing other initial guesses (state trajectories) based on the initial guess of this parameter, elsewhere in the code. Is there functionality to do this?

In short, I would like to be able to do:
opti.set_initial(x, 1.0)
opti.set_initial(y, 2.0)
opti.get_initial(x+y) // Should yield 3

Wesley Roozing

unread,
Aug 13, 2021, 7:55:47 AM8/13/21
to CasADi
Perhaps to clarify; when I say 'parameter' I don't mean an opti stack 'parameter' object. Rather, I mean one of the decision variables in the problem is given an initial guess value.

Joris Gillis

unread,
Aug 13, 2021, 8:12:07 AM8/13/21
to CasADi
opti.debug.value(x+y, opti.initial()) iirc

Wesley Roozing

unread,
Aug 13, 2021, 8:44:36 AM8/13/21
to CasADi
Thanks Joris, that works indeed. While looking up the documentation for opti.debug.value() I noticed that is even mentioned under extras, doh!

Wesley Roozing

unread,
Aug 13, 2021, 8:46:13 AM8/13/21
to CasADi
Perhaps worth noting; 'debug' is not necessary either; simply opti.value(x, opti.initial()) works.
Reply all
Reply to author
Forward
0 new messages