|
plotting Constraint Set 2 Years, 2 Months ago
|
Karma: 0
|
|
I have just checked an example from a book. Its optimal value is -310 and I get the answer. I attach the code (unable to attach the figures)
I tried plotting the Constraint set.
Q1) Why is it that I get different figure each time I run the program ?
Q2) Is it the feasible set/cone for the problem ?
Q3) What does the length of the each axis define ?
Q4) What are the lines inside the figure and the edges define ?
Q5) I have 6 variables x1 to x6 and order 2 and the figure is 3D how does the number of variables and their order affect the figure ?
Q6) Can I locate the optimal value from the figure ?
yalmip('clear')
x=sdpvar(6,1);
obj=-25*(x(1,1)-2).^2 - (x(2,1)-2).^2 - (x(3,1)-1).^2 -(x(4,1)-4).^2 -(x(5,1)-1).^2 -(x(6,1)-4).^2;
f=set((x(3,1)-3).^2 + x(4,1) >=4);
f=f+set((x(5,1)-3).^2 +x(6,1) >=4);
f=f+set(x(1,1)-3*x(2,1)<=2);
f=f+set(-x(1,1)+x(2,1)<=2);
f=f+set(x(1,1)+x(2,1)>=2);
f=f+set(x(1,1)+x(2,1)<=6);
f=f+set(1<=x(3,1)<=5);
f=f+set(0<=x(4,1)<=6);
f=f+set(1<=x(5,1)<=5);
f=f+set(0<=x(6,1)<=10);
f=f+set(x(1,1)>=0);
f=f+set(x(2,1)>=0);
solvesdp(f,obj,sdpsettings('solver','bmibnb'))
checkset(f)
plot(f)
|
|
|
|
|
|
|
Re: plotting Constraint Set 2 Years, 2 Months ago
|
Karma: 32
|
Q1: YALMIP uses a randomized ray-shooting algorithm to draw the set (see below).
Q2: No. The plot command assumes the feasible set is convex. If not, if you are lucky and the solver used finds the optimal point in every ray it shoots, it will plot the convex hull of the nonconvex set. If the solver happens to find local minimizers, you simply get a garbage set.
Q3-Q4: ??
Q5: YALMIP projects (by shooting rays in these dimensions) on the first three variables defined (i.e. the ones with lowest internal indicies). You can select in which dimension the projection is performed by using more arguments to plot
Q6: No.
| Code: |
sdpvar x y
p1 = 1-((x-1)^2+y^2);
p2 = 1-((x+1)^2+y^2);
% Plot first ball
plot(p1>0);
hold on
% Plot second ball
plot(p2>0);
% Plot the union of them, i.e. a nonconvex set
% However, this will only work if the solver used actually finds global
% optimizers along each ray. On my machine, with fmincon, I was apparantly
% lucky
plot(p1*p2<0)
% We can guarantee the generation of the convex hull by using a global
% solver. This will be slow though...
plot([p1*p2<0,-100<[x y]<100],[],[],[],sdpsettings('solver','bmibnb'))
% Manually generate a plot of a ball
points = [];
for i = 1:100
direction = randn(2,1);
solvesdp(p1>0,direction'*[x;y]);
points = [points double([x;y])];
end
K = convhulln(points');
p = patch('Vertices', points', 'Faces', K);
|
|
|
lofberg
Platinum Boarder
Posts: 2280
|
|
|
|
|
Re: plotting Constraint Set 2 Years, 2 Months ago
|
Karma: 32
|
|
Hence, the code to plot the convex hull in x3,x4,x5
plot(f,x(3:5),[],[],sdpsettings('solver','bmibnb'))
PS, the operator SET is obsolete.
|
|
lofberg
Platinum Boarder
Posts: 2280
|
|
Last Edit: 2011/03/04 11:12 By lofberg.
|
|
|
Re: plotting Constraint Set 2 Years, 2 Months ago
|
Karma: 32
|
Some more plotting fun!
Plot the feasible set for the SDP relaxation of the union. It's tight as you can see
| Code: |
v = monolist([x y],2);
M = v*v';
plot([p1*p2<0,M>0],[],[],100,sdpsettings('relax',1,'verbose',0));
hold on
% Plot first ball
plot(p1>0,[],'g',100);
hold on
% Plot second ball
plot(p2>0,[],'b',100);
|
The convex hull of conic-representable sets can be created directly by using the hull operator
| Code: |
plot(hull(p1>0,p2>0))
|
|
|
lofberg
Platinum Boarder
Posts: 2280
|
|
|
|
|