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