Section 8.2.2: Separating polyhedra in 2D
randn('seed',0);
n = 2;
m = 2*n;
A1 = [1 1; 1 -1; -1 1; -1 -1];
A2 = [1 0; -1 0; 0 1; 0 -1];
b1 = 2*ones(m,1);
b2 = [5; -3; 4; -2];
fprintf(1,'Finding a separating hyperplane between the 2 polyhedra...');
cvx_begin
variables lam(m) muu(m) z(n)
maximize ( -b1'*lam - b2'*muu)
A1'*lam + z == 0;
A2'*muu - z == 0;
norm(z) <= 1;
-lam <=0;
-muu <=0;
cvx_end
fprintf(1,'Done! \n');
disp('------------------------------------------------------------------');
disp('The distance between the 2 polyhedra C and D is: ' );
disp(['dist(C,D) = ' num2str(cvx_optval)]);
t = linspace(-3,6,100);
p = -z(1)*t/z(2) + (muu'*b2 - lam'*b1)/(2*z(2));
figure;
fill([-2; 0; 2; 0],[0;2;0;-2],'b', [3;5;5;3],[2;2;4;4],'r')
axis([-3 6 -3 6])
axis square
hold on;
plot(t,p)
title('Separating 2 polyhedra by a hyperplane');
Finding a separating hyperplane between the 2 polyhedra...
Calling sedumi: 11 variables, 5 equality constraints
------------------------------------------------------------
SeDuMi 1.21 by AdvOL, 2005-2008 and Jos F. Sturm, 1998-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
eqs m = 5, order n = 11, dim = 12, blocks = 2
nnz(A) = 17 + 0, nnz(ADA) = 25, nnz(L) = 15
it : b*y gap delta rate t/tP* t/tD* feas cg cg prec
0 : 1.53E+01 0.000
1 : -2.21E+00 4.16E+00 0.000 0.2727 0.9000 0.9000 1.77 1 1 2.4E+00
2 : -2.32E+00 8.44E-01 0.000 0.2028 0.9000 0.9000 1.45 1 1 3.6E-01
3 : -2.12E+00 4.88E-02 0.000 0.0578 0.9900 0.9900 1.07 1 1 2.1E-02
4 : -2.12E+00 1.71E-04 0.000 0.0035 0.9990 0.9990 1.01 1 1 7.8E-05
5 : -2.12E+00 6.83E-07 0.000 0.0040 0.9990 0.9990 1.00 1 1 3.1E-07
6 : -2.12E+00 9.97E-09 0.000 0.0146 0.9901 0.9900 1.00 2 2 5.0E-09
iter seconds digits c*x b*y
6 0.0 8.3 -2.1213203358e+00 -2.1213203460e+00
|Ax-b| = 4.9e-10, [Ay-c]_+ = 2.6E-09, |x|= 1.9e+00, |y|= 2.6e+00
Detailed timing (sec)
Pre IPM Post
1.000E-02 3.000E-02 0.000E+00
Max-norms: ||b||=1, ||c|| = 3,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 944.813.
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +2.12132
Done!
------------------------------------------------------------------
The distance between the 2 polyhedra C and D is:
dist(C,D) = 2.1213