How can I solve the chain constraints error in LQ problem?

103 views
Skip to first unread message

Yu Ren

unread,
Feb 24, 2021, 4:40:25 AM2/24/21
to cvxpy
I met a problem when I try to use cvxpy to solve the LQ problem.   Let me give a simple example. My objective function is x^2 
and the constraints is x<1 or x>5


So I  use the penalty function method to add the two constraints.

the new objective function :   x**2 + np.sign(np.min([np.max([0,x-1]),np.max([]5-x,0)]))

That means if x<1 or x>5, the later term np.sign(np.min([np.max([0,x-1]),np.max([]5-x,0)])) is equall to 0.

However, when I run it, I get a error:  
 Exception: Cannot evaluate the truth value of a constraint or chain constraints, e.g., 1 >= x >= 0.  
 Could any friend help me solve this problem? thanks very much previously.
Reply all
Reply to author
Forward
0 new messages