1 | sdpvar x1 x2 x3 x4 x5 x6 t1 t2 |
---|
2 | |
---|
3 | lhs = [-x1+x5;-x1-x5;-x2+x6;-x2-x6;-x3;-x3-x5;-x3;-x3+x5;-x4-x5-x6;-x4+x5;-x4+x5;-x4+x5+x6;x5;-x5;x6;-x6] |
---|
4 | |
---|
5 | |
---|
6 | rhs = [0 0 0 0 t1+t2 t2 -t1-t2 -t2 t1+2*t2 t2 -t1-2*t2 -t2 1 1 1 1]'; |
---|
7 | |
---|
8 | |
---|
9 | F = set(lhs < rhs); |
---|
10 | x = [x1 x2 x3 x4 x5]; |
---|
11 | sol = solvemp(F+set(-4< [t1 t2]<4),x1+x2+x3+x4,[],[t1;t2]) |
---|
12 | |
---|
13 | sdpvar x1 x2 y1 y2 t1 t2 |
---|
14 | |
---|
15 | F = set(x1+3*x2-y1 < 9-2*t1+t2); |
---|
16 | F = F + set(2*x1+x2 < 8 + t1-2*t2); |
---|
17 | F = F + set(x1<4+t1+t2); |
---|
18 | F = F + set(-x1 < 0); |
---|
19 | F = F + set(-x2 < 0); |
---|
20 | F = F + set(binary([y1 y2])) + set(-10 <[t1 t2] < 10); |
---|
21 | |
---|
22 | |
---|
23 | [sol,dgn,Z,J] = solvemp(F,-2*x1-x2+y1+y2,sdpsettings('mp.al',3),[t1;t2]);sol = rmovlps(sol); |
---|
24 | |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | |
---|
29 | sdpvar x1 x2 x3 x4 x5 x6 t1 t2 |
---|
30 | |
---|
31 | lhs = [-x1+x5;-x1-x5;-x2+x6;-x2-x6;-x3;-x3-x5;-x3;-x3+x5;-x4-x5-x6;-x4+x5;-x4+x5;-x4+x5+x6;x5;-x5;x6;-x6] |
---|
32 | |
---|
33 | |
---|
34 | rhs = [0 0 0 0 t1+t2 t2 -t1-t2 -t2 t1+2*t2 t2 -t1-2*t2 -t2 1 1 1 1]'; |
---|
35 | |
---|
36 | |
---|
37 | F = set(lhs < rhs); |
---|
38 | x = [x1 x2 x3 x4 x5]; |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | sol = solvemp(F+set(-4< [t1 t2]<4),x1+x2+x3+x4,[],[t1;t2]) |
---|
43 | |
---|
44 | F+set(-4< [t1 t2]<4); |
---|
45 | obj = x1+x2+x3+x4; |
---|
46 | parametric = [t1;t2]; |
---|
47 | t = [t1;t2]; |
---|
48 | [sol,dgn,Z,J] = mimpmilp(F,obj,sdpsettings('debug',1),parametric) |
---|
49 | |
---|
50 | |
---|
51 | sdpvar x1 x2 t1 t2 |
---|
52 | binvar y1 y2 |
---|
53 | |
---|
54 | F = set(x1+3*x2-y1 < 9-2*t1+t2); |
---|
55 | F = F + set(2*x1+x2 < 8 + t1-2*t2); |
---|
56 | F = F + set(x1<4+t1+t2); |
---|
57 | F = F + set(-x1 < 0); |
---|
58 | F = F + set(-x2 < 0); |
---|
59 | F = F + set(-10 <[t1 t2] < 10); |
---|
60 | |
---|
61 | y = [y1;y2]; |
---|
62 | t = [t1;t2]; |
---|
63 | obj = -2*x1-x2+y1+y2; |
---|
64 | sol = solvemp(F,obj,[],t); |
---|
65 | sol = mpt_removeOverlaps(sol); |
---|
66 | |
---|
67 | sold = dua_test(F,obj,[],t,y) |
---|
68 | sold = mpt_removeOverlaps(sold); |
---|
69 | |
---|
70 | |
---|
71 | |
---|
72 | sol = rmovlps(sol); |
---|
73 | plot(sol.Pn) |
---|
74 | |
---|
75 | sol = mimpmilp(F,obj,[],t) |
---|
76 | |
---|
77 | sol = mimpmilp(F,-2*x1-x2+y1+y2,t,y); |
---|
78 | |
---|
79 | |
---|
80 | |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | sol = mimpmilp(F,obj,x{k},dd); |
---|
85 | |
---|
86 | |
---|
87 | |
---|
88 | % Dua example 1 |
---|
89 | sdpvar x1 x2 t1 t2 |
---|
90 | binvar y1 y2 |
---|
91 | |
---|
92 | obj = -3*x1-8*x2+4*y1+2*y2 |
---|
93 | |
---|
94 | F = set([x1+x2 < 13+t1;5*x1-4*x2 < 20;-8*x1+22*x2 < 121+t2;4*x1+x2>8;x1-10*y1<0;x2-15*y2 < 0]); |
---|
95 | F = F + set([x1 x2]>0) + set(0<[t1 t2]<10) |
---|
96 | sol = solvemp(F,obj,[],[t1;t2]); |
---|
97 | sol = mpt_removeOverlaps(sol); |
---|
98 | |
---|
99 | sold = dua_test(F,obj,[],[t1;t2],[y1;y2]); |
---|
100 | sold = mpt_removeOverlaps(sold); |
---|
101 | |
---|
102 | |
---|
103 | % Dua example 2 |
---|
104 | sdpvar x1 x2 t1 t2 t3 |
---|
105 | binvar y1 y2 |
---|
106 | |
---|
107 | obj = -3*x1-2*x2+10*y1+5*y2; |
---|
108 | |
---|
109 | F=set([x1 < 10+t1+2*t2; |
---|
110 | x2 < 10-t1 +t2; |
---|
111 | x1+x2<20-t2; |
---|
112 | x1+2*x2 < 12+t1-t3; |
---|
113 | x1-20*y1<0; |
---|
114 | x2-20*y2<0; |
---|
115 | -x1+x2>4-t3; |
---|
116 | y1+y2>1]); |
---|
117 | |
---|
118 | F = F + set([x1 x2]>0) + set(0<[t1 t2 t3]<5) |
---|
119 | |
---|
120 | sol = solvemp(F,obj,[],[t1;t2;t3]); |
---|
121 | sol = mpt_removeOverlaps(sol) |
---|
122 | |
---|
123 | sold = dua_test(F,obj,[],[t1;t2;t3],[y1;y2]); |
---|
124 | sold = mpt_removeOverlaps(sold); |
---|
125 | |
---|
126 | |
---|
127 | % Dua 3 |
---|
128 | sdpvar x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 |
---|
129 | sdpvar t1 t2 t3 t4 |
---|
130 | binvar y1 y2 y3 y4 y5 y6 y7 y8 |
---|
131 | |
---|
132 | x = [x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23] |
---|
133 | |
---|
134 | F = set([x19 == 90000*y1+9600*x1; |
---|
135 | x20 == 40000*y2+8500*x2; |
---|
136 | x21 == 45000*(y3+y4) + 25*x17; |
---|
137 | x22 == 25000*(y5+y6) + 14.5*x18; |
---|
138 | x23 == 20000*(y7+y8); |
---|
139 | x1 == x3+x4+x5+x6+x7; |
---|
140 | x12 == x2+x3+x4+x5-x8-x9-x10; |
---|
141 | x11 == x6+x7+x8+x9+x10; |
---|
142 | x17 == x13 + x14; |
---|
143 | x18 == x15+x16; |
---|
144 | x13 == 42.6*x3+121*x6; |
---|
145 | x14 == 42.6*x4+121*x7; |
---|
146 | x15 == 78.4*x8; |
---|
147 | x16 == 78.4*x9; |
---|
148 | x12 > 20+10*t1; |
---|
149 | x13+x15 > 7000+1000*t2; |
---|
150 | x14+x16 > 4000+1000*t3; |
---|
151 | x11 > 80+10*t4; |
---|
152 | x6 - 200*y7 < 0; |
---|
153 | x7 - 200*y8 < 0; |
---|
154 | x3+x6-200*y3 < 0; |
---|
155 | x4+x7-200*y4 < 0; |
---|
156 | x8-200*y5 < 0; |
---|
157 | x9-200*y6 < 0; |
---|
158 | y3-y1<0; |
---|
159 | y4-y1<0; |
---|
160 | y7-y3<0; |
---|
161 | y8-y4<0; |
---|
162 | y3+y5 == 1; |
---|
163 | y4+y6 == 1; |
---|
164 | x > 0; |
---|
165 | [t1 t2 t3 t4] <1; |
---|
166 | [t1 t2 t3 t4] > 0]) |
---|
167 | obj = x19+x20+x21+x22+x23; |
---|
168 | sol = solvemp(F,obj,[],[t1;t2;t3;t4]); |
---|
169 | tic |
---|
170 | sol = mpt_removeOverlaps(sol); |
---|
171 | toc |
---|
172 | |
---|
173 | sola = solvemp(F,obj,sdpsettings('mp.al',2),[t1;t2;t3;t4]); |
---|
174 | tic |
---|
175 | sola = mpt_removeOverlaps(sola); |
---|
176 | toc |
---|
177 | |
---|
178 | |
---|
179 | sold = dua_test(F,obj,[],[t1;t2;t3;t4]) |
---|
180 | tic |
---|
181 | sold = mpt_removeOverlaps(sold); |
---|
182 | toc |
---|
183 | |
---|
184 | mpt_ispWAbigger(sold,sol) |
---|
185 | |
---|
186 | mpt_ispWAbigger(sola,sol) |
---|
187 | |
---|
188 | |
---|
189 | |
---|
190 | |
---|
191 | |
---|
192 | sol = solvesdp(F,obj) |
---|
193 | |
---|
194 | y=[y1 y2 y3 y4 y5 y6 y7 y8] |
---|
195 | for i = 1:23 |
---|
196 | solvesdp(F+set(x<1e7)+set(y==[1 0 0 1 1 0 0 0]),x(i),sdpsettings('relax',1));xl(i) = double(x(i)); |
---|
197 | solvesdp(F+set(x<1e7)+set(y==[1 0 0 1 1 0 0 0]),-x(i),sdpsettings('relax',1));xu(i) = double(x(i)); |
---|
198 | end |
---|
199 | |
---|
200 | |
---|
201 | |
---|
202 | |
---|
203 | |
---|
204 | |
---|
205 | |
---|
206 | |
---|
207 | |
---|
208 | |
---|
209 | |
---|
210 | |
---|
211 | |
---|
212 | |
---|
213 | |
---|
214 | |
---|
215 | |
---|
216 | |
---|
217 | |
---|
218 | |
---|
219 | |
---|
220 | |
---|
221 | |
---|
222 | |
---|
223 | |
---|
224 | |
---|
225 | |
---|
226 | |
---|
227 | |
---|
228 | |
---|
229 | |
---|
230 | |
---|
231 | |
---|
232 | |
---|
233 | |
---|
234 | |
---|
235 | |
---|
236 | |
---|
237 | |
---|
238 | |
---|
239 | [sol,dgn,Z,J] = solvemp(F,-2*x1-x2+y1+y2,[],t,y); |
---|
240 | |
---|
241 | |
---|
242 | sol = rmovlps(sol); |
---|
243 | |
---|
244 | binary = [y1;y2]; |
---|
245 | |
---|
246 | % Solve relaxed problem |
---|
247 | [sol,dgn,Z,J] = solvemp(F,-2*x1-x2+y1+y2,sdpsettings('relax',1),[t1;t2],y); |
---|
248 | |
---|
249 | |
---|
250 | not_integer = find((sum(abs([sol{1}.Fi{:}]),2) ~= 0) | sum(abs([sol{1}.Gi{:}]-round([sol{1}.Gi{:}])),2)~=0); |
---|
251 | |
---|
252 | if ~isempty(not_integer) |
---|
253 | j = not_integer(1); |
---|
254 | [sol_down,dgn,Z,J] = solvemp(F+set(y(j)==0),-2*x1-x2+y1+y2,sdpsettings('relax',1),[t1;t2],y); |
---|
255 | [sol_up,dgn,Z,J] = solvemp(F+set(y(j)==1),-2*x1-x2+y1+y2,sdpsettings('relax',1),[t1;t2],y); |
---|
256 | sol = rmovlps({sol_down{1},sol_up{1}}) |
---|
257 | end |
---|
258 | |
---|
259 | |
---|