%We assume here we are in 2D

%define the number of spheres the model has to place
n=7;

% Define a symmetric matrix P
P = sdpvar(n,n) ;
%objective function
alpha=sdpvar(1,1);

%variable that codes the perimeter used by the placements of the spheres
UsedPerimeter=0;

%SDP matrix
Constraints =[P>=0,diag(P)==eye];
for i = 1:n-1
	%calculate the perimeter used by the placement (underestimated)
	%we make here a linear approximation of the distance on the circle, knowing that the angle is greater than pi/3
	UsedPerimeter=UsedPerimeter +(2 -2*P(i,i+1))*pi/3 ;
end
UsedPerimeter=UsedPerimeter+(2 -2*P(n,1))*pi/3 ;
 
Constraints= Constraints +[UsedPerimeter<=2*pi];

%Schur complement
%X=sdpvar(2,n);
%Constraints = Constraints + [X(i,j)>=-1, X(i,j)<=1];
%M = [ eye(2) X; X' P ];
%Constraints = Constraints+[ M >= 0 ];

%non-overlapping interior
for i = 1:n
	for j = 1 : n
		if (i != j)
			Constraints= Constraints+[P(i,j)<=1/2, 2-2*P(i,j)>=alpha(1,1), P(i,j)>=-1, P(i,j)<=1 ];
		end
	end
end

  
Objective= [-alpha];
optimize(Constraints,Objective);

Pfeasible = value(P);
display('Solution:');
display(Pfeasible);
display('Objective');
display(Objective);