source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/dev/spjot.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 4.4 KB
Line 
1sdpvar x1 x2 x3 x4 x5 x6 t1 t2
2
3lhs = [-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
6rhs = [0 0 0 0 t1+t2 t2 -t1-t2 -t2 t1+2*t2 t2 -t1-2*t2 -t2 1 1 1 1]';
7
8
9F = set(lhs < rhs);
10x = [x1 x2 x3 x4 x5];
11sol = solvemp(F+set(-4< [t1 t2]<4),x1+x2+x3+x4,[],[t1;t2])
12
13sdpvar x1 x2 y1 y2 t1 t2
14
15F = set(x1+3*x2-y1 < 9-2*t1+t2);
16F = F + set(2*x1+x2 < 8 + t1-2*t2);
17F = F + set(x1<4+t1+t2);
18F = F + set(-x1 < 0);
19F = F + set(-x2 < 0);
20F = 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
29sdpvar x1 x2 x3 x4 x5 x6 t1 t2
30
31lhs = [-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
34rhs = [0 0 0 0 t1+t2 t2 -t1-t2 -t2 t1+2*t2 t2 -t1-2*t2 -t2 1 1 1 1]';
35
36
37F = set(lhs < rhs);
38x = [x1 x2 x3 x4 x5];
39
40
41
42sol = solvemp(F+set(-4< [t1 t2]<4),x1+x2+x3+x4,[],[t1;t2])
43
44F+set(-4< [t1 t2]<4);
45obj = x1+x2+x3+x4;
46parametric = [t1;t2];
47t = [t1;t2];
48[sol,dgn,Z,J] = mimpmilp(F,obj,sdpsettings('debug',1),parametric)
49
50
51sdpvar x1 x2 t1 t2
52binvar y1 y2
53
54F = set(x1+3*x2-y1 < 9-2*t1+t2);
55F = F + set(2*x1+x2 < 8 + t1-2*t2);
56F = F + set(x1<4+t1+t2);
57F = F + set(-x1 < 0);
58F = F + set(-x2 < 0);
59F = F + set(-10 <[t1 t2] < 10);
60
61y = [y1;y2];
62t = [t1;t2];
63obj = -2*x1-x2+y1+y2;
64sol = solvemp(F,obj,[],t);
65sol = mpt_removeOverlaps(sol);
66
67sold = dua_test(F,obj,[],t,y)
68sold = mpt_removeOverlaps(sold);
69
70
71
72sol = rmovlps(sol);
73plot(sol.Pn)
74
75sol = mimpmilp(F,obj,[],t)
76
77sol = mimpmilp(F,-2*x1-x2+y1+y2,t,y);
78
79
80
81
82
83
84sol = mimpmilp(F,obj,x{k},dd);
85
86
87
88% Dua example 1
89sdpvar x1 x2  t1 t2
90binvar y1 y2
91
92obj = -3*x1-8*x2+4*y1+2*y2
93
94F = 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]);
95F = F + set([x1 x2]>0) + set(0<[t1 t2]<10)
96sol = solvemp(F,obj,[],[t1;t2]);
97sol = mpt_removeOverlaps(sol);
98
99sold = dua_test(F,obj,[],[t1;t2],[y1;y2]);
100sold = mpt_removeOverlaps(sold);
101
102
103% Dua example 2
104sdpvar x1 x2  t1 t2 t3
105binvar y1 y2
106
107obj = -3*x1-2*x2+10*y1+5*y2;
108
109F=set([x1 < 10+t1+2*t2;
110x2 < 10-t1 +t2;
111x1+x2<20-t2;
112x1+2*x2 < 12+t1-t3;
113x1-20*y1<0;
114x2-20*y2<0;
115-x1+x2>4-t3;
116y1+y2>1]);
117
118F = F + set([x1 x2]>0) + set(0<[t1 t2 t3]<5)
119
120sol = solvemp(F,obj,[],[t1;t2;t3]);
121sol = mpt_removeOverlaps(sol)
122
123sold = dua_test(F,obj,[],[t1;t2;t3],[y1;y2]);
124sold = mpt_removeOverlaps(sold);
125
126
127% Dua 3
128sdpvar x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23
129sdpvar t1 t2 t3 t4
130binvar y1 y2 y3 y4 y5 y6 y7 y8
131
132x = [x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23]
133
134F = set([x19 == 90000*y1+9600*x1;
135x20 == 40000*y2+8500*x2;
136x21 == 45000*(y3+y4) + 25*x17;
137x22 == 25000*(y5+y6) + 14.5*x18;
138x23 == 20000*(y7+y8);
139x1  == x3+x4+x5+x6+x7;
140x12 == x2+x3+x4+x5-x8-x9-x10;
141x11 == x6+x7+x8+x9+x10;
142x17 == x13 + x14;
143x18 == x15+x16;
144x13 == 42.6*x3+121*x6;
145x14 == 42.6*x4+121*x7;
146x15 == 78.4*x8;
147x16 == 78.4*x9;
148x12 > 20+10*t1;
149x13+x15 > 7000+1000*t2;
150x14+x16 > 4000+1000*t3;
151x11 > 80+10*t4;
152x6 - 200*y7 < 0;
153x7 - 200*y8 < 0;
154x3+x6-200*y3 < 0;
155x4+x7-200*y4 < 0;
156x8-200*y5 < 0;
157x9-200*y6 < 0;
158y3-y1<0;
159y4-y1<0;
160y7-y3<0;
161y8-y4<0;
162y3+y5 == 1;
163y4+y6 == 1;
164x > 0;
165[t1 t2 t3 t4] <1;
166[t1 t2 t3 t4] > 0])
167obj = x19+x20+x21+x22+x23;
168sol = solvemp(F,obj,[],[t1;t2;t3;t4]);
169tic
170sol = mpt_removeOverlaps(sol);
171toc
172
173sola = solvemp(F,obj,sdpsettings('mp.al',2),[t1;t2;t3;t4]);
174tic
175sola = mpt_removeOverlaps(sola);
176toc
177
178
179sold = dua_test(F,obj,[],[t1;t2;t3;t4])
180tic
181sold = mpt_removeOverlaps(sold);
182toc
183
184mpt_ispWAbigger(sold,sol)
185
186mpt_ispWAbigger(sola,sol)
187
188
189
190
191
192sol = solvesdp(F,obj)
193
194y=[y1 y2 y3 y4 y5 y6 y7 y8]
195for i = 1:23
196solvesdp(F+set(x<1e7)+set(y==[1 0 0 1 1 0 0 0]),x(i),sdpsettings('relax',1));xl(i) = double(x(i));
197solvesdp(F+set(x<1e7)+set(y==[1 0 0 1 1 0 0 0]),-x(i),sdpsettings('relax',1));xu(i) = double(x(i));
198end
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
242sol = rmovlps(sol);
243
244binary = [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
250not_integer = find((sum(abs([sol{1}.Fi{:}]),2) ~= 0) | sum(abs([sol{1}.Gi{:}]-round([sol{1}.Gi{:}])),2)~=0);
251
252if ~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}})
257end
258
259
Note: See TracBrowser for help on using the repository browser.