Modifying Existing Constraints

20 views
Skip to first unread message

XB G

unread,
Jan 16, 2019, 9:52:28 PM1/16/19
to YALMIP
Dear Johan,
Here is a toy example of my question.

% this is the initial problem
sdpvar x;
obj = -x;
constr0 = [ x <= 1];
optimize(constr0, obj)
value(x)

% some additional changes required, and I prefer to modify existing constraint constr0
% I want to solve minimize -x, subject to x+s <= 1, s>= 0
% Is the code below correct?
a = sdpvar(constr0);
sdpvar s;
constr1 = [a-s >= 0, s>=0] ;
optimize(constr1, obj)
value(x), value(a), value(s)


A more general version: currently I have the constraint F = [f(x) <= 0];
let a = sdpvar(F), what I need is the constraint like F1 = [ f(x)+g(y) <=0 ], where y are new variables. What is the right way to formulate it using a and F ?

Thanks!


Johan Löfberg

unread,
Jan 17, 2019, 1:55:52 AM1/17/19
to YALMIP
All constraints are internally saved as f(x) >= 0, so to change F = [fx <= 0] to fx + gy <= 0 you would have to do -sdpvar(F) + gy <= 0

Although that looks like good way to make your code unreadable. Why not simply define the constraints using standard code.

XB G

unread,
Jan 17, 2019, 9:02:21 AM1/17/19
to YALMIP
The constraint constr0 is passed into a function, is there any way for YALMIP to modify it using standard code?

Johan Löfberg

unread,
Jan 17, 2019, 9:03:56 AM1/17/19
to YALMIP
No, then you would have to restructure your code if you want to keep it clean
Reply all
Reply to author
Forward
0 new messages