-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraw_prim_curves.m
More file actions
164 lines (124 loc) · 6 KB
/
draw_prim_curves.m
File metadata and controls
164 lines (124 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
% IP
T = 800; % Since CPLEX exhibits unstable behavior as it approaches the time limit, we exclude the final portion from our plots (e.g., when the time limit is 1000s, we only plot results up to 800s)
nam = '(a) IP';
% nexttile;
default_file = ".\IP-r\exp-cplex-method-['fixTop']-perc-0.0-Mt3600\primals.mat";
ori_fix_file = ".\IP-r\exp-cplex-method-['fixTop']-perc-0.1-Mt1000\primals.mat";
ori_ps_file = ".\IP-r\exp-cplex-method-['PS']-perc-0.1-Mt1000\primals.mat";
opt_fix_file = ".\IP-rs\exp-cplex-method-['fixTop']-perc-0.1-Mt1000\primals.mat";
opt_ps_file = ".\IP-rs\exp-cplex-method-['PS']-perc-0.1-Mt1000\primals.mat";
draw_primal_curves(default_file,ori_fix_file,ori_ps_file,opt_fix_file,opt_ps_file,nam,T);
ylim([0.5,1]);
xlim([10,T]);
% SMSP
figure;
nam = '(b) SMSP';
default_file = ".\SMSP-r\exp-cplex-method-['fixTop']-perc-0.0-Mt3600\primals.mat";
ori_fix_file = ".\SMSP-r\exp-cplex-method-['fixTop']-perc-0.5-Mt1000\primals.mat";
ori_ps_file = ".\SMSP-r\exp-cplex-method-['PS']-perc-0.5-Mt1000\primals.mat";
opt_fix_file = ".\SMSP-rs\exp-cplex-method-['fixTop']-perc-0.5-Mt1000\primals.mat";
opt_ps_file = ".\SMSP-rs\exp-cplex-method-['PS']-perc-0.5-Mt1000\primals.mat";
draw_primal_curves(default_file,ori_fix_file,ori_ps_file,opt_fix_file,opt_ps_file,nam,T);
ylim([0.4,1.3]);
xlim([10,T]);
function draw_primal_curves(default_path,ori_fix_path,ori_ps_path,opt_fix_path,opt_ps_path,nam,T)
default_primals = load(default_path).primals;
ori_fix = load(ori_fix_path).primals;
ori_ps = load(ori_ps_path).primals;
opt_fix = load(opt_fix_path).primals;
opt_ps = load(opt_ps_path).primals;
default_BKV = default_primals(:,size(default_primals,2));
ori_fix_BKV = ori_fix(:,size(ori_fix,2));
ori_ps_BKV = ori_ps(:,size(ori_ps,2));
opt_fix_BKV = opt_fix(:,size(opt_fix,2));
opt_ps_BKV = opt_ps(:,size(opt_ps,2));
BKV= [default_BKV,ori_fix_BKV,ori_ps_BKV,opt_fix_BKV,opt_ps_BKV];
BKV = min(BKV,[],2);
pag_default = mean(abs(default_primals-BKV)./abs(BKV),1);
pag_ori_fix = mean(abs(ori_fix-BKV)./abs(BKV),1);
pag_ori_ps = mean(abs(ori_ps-BKV)./abs(BKV),1);
pag_opt_fix = mean(abs(opt_fix-BKV)./abs(BKV),1);
pag_opt_ps = mean(abs(opt_ps-BKV)./abs(BKV),1);
% align
% Since the optimal value of each SMSP instance are greater than 1772
% resulting in extremely small-valued primal gaps, thus re-scaled values (between 0 and 1) of
% primal gaps are ploted.
if strcmp(nam ,'(b) SMSP')
scale = 100;
pag_default = pag_default*scale;
pag_ori_fix = pag_ori_fix*scale;
pag_ori_ps = pag_ori_ps*scale;
pag_opt_fix = pag_opt_fix*scale;
pag_opt_ps = pag_opt_ps*scale;
end
% limited length
pag_default = pag_default(1:T);
pag_ori_fix = pag_ori_fix(1:T);
pag_ori_ps = pag_ori_ps(1:T);
pag_opt_fix = pag_opt_fix(1:T);
pag_opt_ps = pag_opt_ps(1:T);
% statistic
pag_default_std = std(default_primals./BKV,1);
pag_ori_fix_std = std(ori_fix./BKV,1);
pag_ori_ps_std = std(ori_ps./BKV,1);
pag_opt_fix_std = std(opt_fix./BKV,1);
pag_opt_ps_std = std(opt_ps./BKV,1);
pag_default_mean = pag_default(T);
pag_ori_fix_mean = pag_ori_fix(T);
pag_ori_ps_mean = pag_ori_ps(T);
pag_opt_fix_mean = pag_opt_fix(T);
pag_opt_ps_mean = pag_opt_ps(T);
pag_default_std = pag_default_std(T);
pag_ori_fix_std = pag_ori_fix_std(T);
pag_ori_ps_std = pag_ori_ps_std(T);
pag_opt_fix_std = pag_opt_fix_std(T);
pag_opt_ps_std = pag_opt_ps_std(T);
fprintf('Relative primal gap of %s\n', nam);
fprintf('CPLEX: %f\n', pag_default_mean);
fprintf('ND: %f\n', pag_ori_fix_mean);
fprintf('ND+SymILO: %f\n', pag_opt_fix_mean);
fprintf('PS: %f\n', pag_ori_ps_mean);
fprintf('PS+SymILO: %f\n', pag_opt_ps_mean);
w = 10;
pag_default = smooth_v(pag_default,w);
pag_ori_fix = smooth_v(pag_ori_fix,w);
pag_ori_ps = smooth_v(pag_ori_ps,w);
pag_opt_fix = smooth_v(pag_opt_fix,w);
pag_opt_ps = smooth_v(pag_opt_ps,w);
red = [0.850980392156863 0.325490196078431 0.0980392156862745];
green = [0.466666666666667 0.674509803921569 0.188235294117647];
purple = [0.494117647058824 0.184313725490196 0.556862745098039];
linwidth = 2;
plot(1:size(pag_ori_fix,2),pag_ori_fix,'LineWidth',linwidth,'Marker','o','MarkerIndices',[1,200,400,600,800],'MarkerSize',8,'LineStyle','-','Color',red);hold on;
plot(1:size(pag_ori_ps,2),pag_ori_ps,'LineWidth',linwidth,'Marker','o','MarkerIndices',[1,200,400,600,800],'MarkerSize',8,'LineStyle','-','Color',green);hold on;
plot(1:size(pag_default,2),pag_default,'LineWidth',linwidth,'Marker','none','MarkerIndices',[1,200,400,600,800],'MarkerSize',8,'LineStyle','--','Color','b');hold on;
plot(1:size(pag_opt_fix,2),pag_opt_fix,'LineWidth',linwidth,'Marker','diamond','MarkerIndices',[1,200,400,600,800],'MarkerSize',8,'LineStyle','-','Color',red);hold on;
plot(1:size(pag_opt_ps,2),pag_opt_ps,'LineWidth',linwidth,'Marker','diamond','MarkerIndices',[1,200,400,600,800],'MarkerSize',8,'LineStyle','-','Color',green);hold on;
set(gca,'FontSize',12,'XTick',[ 10 200 400 600 800]);
grid on;
xlabel({'Solving time (s)',nam},'Interpreter','tex','FontSize',20);
ylabel('Primal gap','Interpreter','tex','FontSize',20);
legend('ND','PS','Tuned CPLEX','SymILO+Fix\&optimize','SymILO+Local Branching','Color',[0.99,0.995,1],'Interpreter','latex');
% st = subtitle(nam,'Interpreter','tex','FontSize',20);
end
function sv = smooth_v(v,w)
v_len = size(v);
v_len = v_len(2);
sv = 1:v_len;
tv = 1:v_len+w-1;
for i=1:v_len
sv(i) = v(i);
tv(i) = v(i);
end
for i=1:w-1
tv(v_len+i) = v(v_len);
end
for i=1:v_len
ss = 0;
for j=1:w
ss = ss + tv(i+j-1);
end
ss = ss/w;
sv(i) = ss;
end
end