Framing constraints conditioned on values of optimization variables

308 views
Skip to first unread message

NISHCHAL HOYSAL G

unread,
Feb 17, 2021, 3:24:25 AM2/17/21
to CasADi
Hi,

Is there a way to apply constraints over an optimization variable depending on the value of another optimization variable? For example, I want to implement some thing like the following (I use python).

x = opti.variable(1,10)
y = opti.variable(1,10)

# constrain value of elements of x to be less than 0 if the corresponding element (of the same index) in y id in the range [0, 5]#

I tried to use conditional() and if_else(). But I guess they do not support evaluating conditions with symbolic variables.

Any way to do this?

Regards,
Nishchal Hoysal G

Jonas Hjulstad

unread,
Feb 17, 2021, 5:18:50 AM2/17/21
to CasADi

I think you will have to use binary variables, but I haven't implemented it in CasADI before myself. Basically, you create a binary variable B (in dimension [1,10])

B.T @ x <= 0  (10 Inequality constraints, will always be 0 when B_i is 0)
B.T @ y - 5 <= 0 (Will also be fulfilled when B_i is 0, depends on y when B_i = 1)
0 - B.T @ y <= 0 

It requires a solver which handles binary variables, like bonmin.

Regards,
Jonas Hjulstad

NISHCHAL HOYSAL G

unread,
Feb 18, 2021, 9:14:26 AM2/18/21
to CasADi
Thank you Jonas. I have used a different round-about approach to handle the constraints for now using ipopt. I will surely check bonmin.

Regards,
Nishchal Hoysal G 

Reply all
Reply to author
Forward
0 new messages