Possibility of conditional constraint

155 views
Skip to first unread message

Giovanni Perin

unread,
Sep 17, 2021, 11:40:07 AM9/17/21
to CasADi

Hi,

I'm trying to define a conditional equality constraint in an optimization problem. The closest atom I could find for this purpose is the if_else atom. However, this requires an else, as long as I understand, whereas I don't need (must not!) to do anything if the condition is not satisfied. What I am doing is:

condition = cs.if_else(x[0] < k, x[1], NOTHING) # where x are state variables
# with the package do-mpc (python):
mpc.set_nl_cons(condition, soft_constraint=True)
mpc.set_nl_cons(-condition, soft_constraint=True)

What I am trying to reach is that the control variable is equal x[1] when x[0] < k,  and is free otherwise. How do I reach this?

Thank you,

Giovanni

Joel Andersson

unread,
Sep 21, 2021, 9:31:38 PM9/21/21
to CasADi
An expression always has to be assigned something. The "if-else" atomic is not "if" in a procedural programming sense but in a functional programming sense.
The "else" can be set equal to zeros, nan, x or something else, depending on context. But it has to be assigned something.

Joel

Reply all
Reply to author
Forward
0 new messages