Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengy09 committed Jun 25, 2021
1 parent 6b0dca4 commit 4e76a29
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 46 deletions.
Binary file added examples/data/ex5_2_dense_graph2_degree.mat
Binary file not shown.
Binary file added examples/data/ex5_2_sparse_graph2_degree.mat
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/example3_5.m → examples/example5_1.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% =================================================================
% Code for Example 3.5 in the paper:
% Code for Example 5.1 in the paper:
% Y. Zheng, G. Fantuzzi, Sum-of-squares chordal decomposition of polynomial
% matrix inequalities
%
Expand Down
12 changes: 7 additions & 5 deletions examples/example3_5b.m → examples/example5_1b.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
% =================================================================
% Code for Example 3.5 in the paper:
% Code for Example 5.1 in the paper:
% Y. Zheng, G. Fantuzzi, Sum-of-squares chordal decomposition of polynomial
% matrix inequalities
%
% NOTE: Assume the option sos.csp in Yalmip has been modified
% NOTE: Assume the option sos.csp in Yalmip has been modified or
% install the following fork of YALMIP:
% https://github.com/aeroimperial-optimization/aeroimperial-yalmip
% =================================================================
clc
clear
Expand All @@ -15,9 +17,9 @@
opts.verbose = 0;

% Parameters
Dim = 2:2:6; % Dimension of the polynomial matrix
Dim = 5:5:40; % Dimension of the polynomial matrix
% the range of 5:5:40 was used in the paper
nu = 1; % degree of SOS multipler
nu = 0:1:3; % degree of SOS multipler
% the range of 1:4 was used in the paper

% Initalize containers
Expand Down Expand Up @@ -83,6 +85,6 @@
end
end

fprintf('m = %d, time %5.3f %5.3f \n ',m, TimeSolver{dind}(index,1),TimeSolver{dind}(index,2));
fprintf('m = %d, time %5.3f %5.3f \n',m, TimeSolver{dind}(index,1),TimeSolver{dind}(index,2));
end
end
14 changes: 7 additions & 7 deletions examples/example5_2_dense.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
objStandard = zeros(length(Deg),length(Gsize));
timeStandard = zeros(length(Deg),length(Gsize));

for indm = 1%:length(Gsize)
for indm = 1:length(Gsize)
m = Gsize(indm);
fprintf('Graph size: %d \n\n',m);
memFlag = 0; % out of memory for Standard SOS?
Expand Down Expand Up @@ -66,12 +66,12 @@

% Solve without sparsity exploitation
opts = sdpsettings('sos.csp',0);
if m >= 30 && Deg(indx) == 4 % these choices --> out of memory on our computer
memFlag = 1;
end
if m >= 35 && Deg(indx) >= 3 % these choices --> out of memory on our computer
memFlag = 1;
end
% if m >= 30 && Deg(indx) == 4 % these choices --> out of memory on our computer
% memFlag = 1;
% end
% if m >= 35 && Deg(indx) >= 3 % these choices --> out of memory on our computer
% memFlag = 1;
% end
if memFlag == 0
try
sol = solvesos(F,-cost,opts,[s1c; gc]);
Expand Down
4 changes: 2 additions & 2 deletions examples/example5_2_graphs.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
%
% =================================================================

Gsize = 10:5:40;
Gsize = 5:2:10; % 10:5:40 was used in the paper
maxClique = 5; % bound on the largest maximal cliques
G = [];
A = [];
Expand All @@ -23,4 +23,4 @@
B{indm} = (spones(G{indm}) - eye(m)).*tmp; % zeros on its diagonal
end

%save('example5_2_graphs.mat','G','A','B','Gsize');
%save('data/example5_2_graphs_new.mat','G','A','B','Gsize');
30 changes: 15 additions & 15 deletions examples/example5_2_integral.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
%
% =================================================================

function example5_2_integral
load('data/example5_2_graphs.mat','A','B','Gsize')
%function example5_2_integral
load('data/example5_2_graphs.mat','A','B','Gsize')

cost_integral = zeros(length(Gsize),1);
for indm = 2%:length(Gsize) % Different matris sizes
m = Gsize(indm);
Am = A{indm};
Bm = B{indm};
p = @(r,theta) mineigP(m,Am,Bm,r,theta) .* r;
tstart = tic;
cost_integral(indm) = integral2(p,0,1,0,2*pi,'AbsTol',1e-7,'RelTol',1e-8);
tend = toc(tstart);
fprintf('%d %4.2f %4.5f\n',m,tend,cost_integral(indm));
end

%save('example5_2_graphs.mat','G','A','B','Gsize','cost_integral')
cost_integral = zeros(length(Gsize),1);
for indm = 2:length(Gsize) % Different matris sizes
m = Gsize(indm);
Am = A{indm};
Bm = B{indm};
p = @(r,theta) mineigP(m,Am,Bm,r,theta) .* r;
tstart = tic;
cost_integral(indm) = integral2(p,0,1,0,2*pi,'AbsTol',1e-7,'RelTol',1e-8);
tend = toc(tstart);
fprintf('%d %4.2f %4.5f\n',m,tend,cost_integral(indm));
end

%save('example5_2_graphs.mat','G','A','B','Gsize','cost_integral')
%end
20 changes: 9 additions & 11 deletions examples/example5_2_plot_patterns.m
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
% =================================================================
% Plot chordal patterns, Example 5-2 in the paper:
% Plot chordal patterns (Figure 5), Example 5-2 in the paper:
% Y. Zheng, G. Fantuzzi, Sum-of-squares chordal decomposition of polynomial
% matrix inequalities
%
% =================================================================

function example5_2_plot_patterns
close all
load('data/example5_2_results.mat','G','Gsize'); % Pre-generated chordal graphs
for indg = 2:7
figure;
spym(G{indg},'ks',5);
set(gcf,'Position',[100 100 300 300])
fname = ['chordal',num2str(Gsize(indg))];
print(gcf,fname,'-painters','-depsc','-r600')
end
close all
load('data/example5_2_graphs.mat','G','Gsize'); % Pre-generated chordal graphs
for indg = 2:7
figure;
spym(G{indg},'ks',5);
set(gcf,'Position',[100 100 300 300])
fname = ['chordal',num2str(Gsize(indg))];
%print(gcf,fname,'-painters','-depsc','-r600')
end

4 changes: 2 additions & 2 deletions examples/example5_2_plots.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% =================================================================
% Plot inner approximation, Example 5-2 in the paper:
% Plot inner approximation (Figure 6), Example 5-2 in the paper:
%
% Y. Zheng, G. Fantuzzi, Sum-of-squares chordal decomposition of polynomial
% matrix inequalities
Expand Down Expand Up @@ -123,6 +123,6 @@
ff.PaperSize = FigSize;
ff.PaperPosition = [0 0 FigSize];
fname = ['gio_inner_approx'];
print(gcf,fname,'-painters','-depsc','-r300')
%print(gcf,fname,'-painters','-depsc','-r300')


8 changes: 5 additions & 3 deletions examples/example5_2_sparse.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% =================================================================% Code for Example 5-2 in the paper:
% =================================================================
% Code for Example 5-2 in the paper:
% Y. Zheng, G. Fantuzzi, Sum-of-squares chordal decomposition of polynomial
% matrix inequalities
%
Expand All @@ -16,15 +17,16 @@
load('data/example5_2_graphs.mat','G','A','B','Gsize')

% Parameters: half-degree of SOS multipliers
% Deg = 2:4;
Deg = 14;

% Initalize containers for the results
gSparse = cell(length(Deg),length(Gsize));
exponents = cell(length(Deg),length(Gsize));
exponents = cell(length(Deg),length(Gsize));
objSparse = zeros(length(Deg),length(Gsize));
timeSparse = zeros(length(Deg),length(Gsize));

for indm = 2%length(Gsize)
for indm = 2%:length(Gsize)
m = Gsize(indm);
clique = cliquesFromSpMatD(G{indm}); % cliques of graph
fprintf(' Graph size: %d \n',m)
Expand Down

0 comments on commit 4e76a29

Please sign in to comment.