1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
---|
2 | <html> |
---|
3 | |
---|
4 | <head> |
---|
5 | <meta http-equiv="Content-Language" content="en-us"> |
---|
6 | <title>YALMIP Example : Efficient solution of KYP problems</title> |
---|
7 | <meta http-equiv="Content-Type" content="text/html; charset=windows-1251"> |
---|
8 | <meta content="Microsoft FrontPage 6.0" name="GENERATOR"> |
---|
9 | <meta name="ProgId" content="FrontPage.Editor.Document"> |
---|
10 | <link href="yalmip.css" type="text/css" rel="stylesheet"> |
---|
11 | <base target="_self"> |
---|
12 | </head> |
---|
13 | |
---|
14 | <body leftMargin="0" topMargin="0"> |
---|
15 | |
---|
16 | <div align="left"> |
---|
17 | <table border="0" cellpadding="4" cellspacing="3" style="border-collapse: collapse" bordercolor="#000000" width="100%" align="left" height="100%"> |
---|
18 | <tr> |
---|
19 | <td width="100%" align="left" height="100%" valign="top"> |
---|
20 | <h2>Saving & and loading</h2> |
---|
21 | <hr noShade SIZE="1"> |
---|
22 | <p>The most efficient and safe way to save and communicate YALMIP models |
---|
23 | is to work with the MATLAB script, i.e. the YALMIP code. In some cases |
---|
24 | however, it might be necessary to use binary or other formats. |
---|
25 | Additionally, there might be cases where a YALMIP model needs to be |
---|
26 | converted to a solver specific numerical model.</p> |
---|
27 | <h3>Loading & saving in binary MATLAB format</h3> |
---|
28 | <p>The objects in YALMIP all support loading and saving, hence it is |
---|
29 | possible to save a model in a binary MATLAB format.</p> |
---|
30 | <table cellPadding="10" width="100%"> |
---|
31 | <tr> |
---|
32 | <td class="xmpcode"> |
---|
33 | <pre>A = randn(3); |
---|
34 | P = sdpvar(3,3); |
---|
35 | F = set(A'*P+P*A < -eye(3)); |
---|
36 | obj = trace(P);</pre> |
---|
37 | <pre>save mymodel</pre> |
---|
38 | <pre>clear all; |
---|
39 | load mymodel |
---|
40 | |
---|
41 | F |
---|
42 | <font color="#000000">+++++++++++++++++++++++++++++++++++++++++++++++++ |
---|
43 | | ID| Constraint| Type| |
---|
44 | +++++++++++++++++++++++++++++++++++++++++++++++++ |
---|
45 | | #1| Numeric value| Matrix inequality 3x3| |
---|
46 | +++++++++++++++++++++++++++++++++++++++++++++++++</font> |
---|
47 | obj |
---|
48 | <font color="#000000">Linear scalar (real, 3 variables)</font></pre> |
---|
49 | </td> |
---|
50 | </tr> |
---|
51 | </table> |
---|
52 | <p>Note that loading a YALMIP model will destroy any |
---|
53 | <a href="reference.htm#sdpvar">sdpvar</a> and |
---|
54 | <a href="reference.htm#set">set</a> object in the current |
---|
55 | workspace. The binary data format is not recommended, and the reason is three-fold. The first reason is |
---|
56 | incompatibility between different MATLAB version, the second reason is |
---|
57 | possible incompatibility between different YALMIP versions, and finally |
---|
58 | that the binary format in YALMIP currently is inefficient for |
---|
59 | large-scale problems.</p> |
---|
60 | <h3>Loading & saving in SDPA sparse ASCII format</h3> |
---|
61 | <p>The leading format to communicate standard linear SDP problems in a |
---|
62 | platform and application independent way is the |
---|
63 | <a target="_blank" href="http://infohost.nmt.edu/~sdplib/FORMAT">sparse |
---|
64 | SDPA format</a>. YALMIP can both save and load models in this format.</p> |
---|
65 | <table cellPadding="10" width="100%" id="table1"> |
---|
66 | <tr> |
---|
67 | <td class="xmpcode"> |
---|
68 | <pre>A = randn(3); |
---|
69 | P = sdpvar(3,3); |
---|
70 | F = set(A'*P+P*A < -eye(3)); |
---|
71 | obj = trace(P);</pre> |
---|
72 | <pre>savesdpafile(F,obj,'mymodel.dat-s');</pre> |
---|
73 | <pre>clear all; |
---|
74 | [F,obj] = loadsdpafile('mymodel.dat-s'); |
---|
75 | |
---|
76 | F |
---|
77 | <font color="#000000">+++++++++++++++++++++++++++++++++++++++++++++++++ |
---|
78 | | ID| Constraint| Type| |
---|
79 | +++++++++++++++++++++++++++++++++++++++++++++++++ |
---|
80 | | #1| Numeric value| Matrix inequality 3x3| |
---|
81 | +++++++++++++++++++++++++++++++++++++++++++++++++</font> |
---|
82 | obj |
---|
83 | <font color="#000000">Linear scalar (real, 3 variables)</font></pre> |
---|
84 | </td> |
---|
85 | </tr> |
---|
86 | </table> |
---|
87 | <p>The SDPA format is limited to standard linear SDP problems (without |
---|
88 | equality constraints), hence many YALMIP models cannot be saved in this |
---|
89 | format. </p> |
---|
90 | <h3>Exporting solver specific models</h3> |
---|
91 | <p>YALMIP can be used to extract the numerical model in various solver |
---|
92 | specific formats. This can be done along during a call to the solver, |
---|
93 | but also without explicitly invoking the solver. To export the solver |
---|
94 | while solving the problem, we use the <code>savesolverinput</code> option.<table cellPadding="10" width="100%" id="table2"> |
---|
95 | <tr> |
---|
96 | <td class="xmpcode"> |
---|
97 | <pre>A = randn(3); |
---|
98 | P = sdpvar(3,3); |
---|
99 | F = set(A'*P+P*A < -eye(3)); |
---|
100 | obj = trace(P); |
---|
101 | sol = solvesdp(F,obj,sdpsettings('solver','sedumi','savesolverinput',1)); |
---|
102 | sol.solverinput |
---|
103 | <font color="#000000">ans = </font></pre> |
---|
104 | <pre><font color="#000000"> A: [9x6 double] |
---|
105 | c: [9x1 double] |
---|
106 | b: [6x1 double] |
---|
107 | K: [1x1 struct] |
---|
108 | pars: [1x1 struct]</font></pre> |
---|
109 | </td> |
---|
110 | </tr> |
---|
111 | </table> |
---|
112 | <p>To export the model with actually calling the solver, use |
---|
113 | <a href="reference.htm#export">export</a>.</p> |
---|
114 | <table cellPadding="10" width="100%" id="table3"> |
---|
115 | <tr> |
---|
116 | <td class="xmpcode"> |
---|
117 | <pre>A = randn(3); |
---|
118 | P = sdpvar(3,3); |
---|
119 | F = set(A'*P+P*A < -eye(3)); |
---|
120 | obj = trace(P); |
---|
121 | mdl = export(F,obj,sdpsettings('solver','sedumi')); |
---|
122 | mdl</pre> |
---|
123 | </td> |
---|
124 | </tr> |
---|
125 | </table> |
---|
126 | <p>All solvers are currently not supported in |
---|
127 | <a href="reference.htm#export">export</a>. If you miss |
---|
128 | support for some solver, please make a feature request.<h3>Saving AMPL |
---|
129 | models<br> |
---|
130 | </h3>A |
---|
131 | rudimentary support for exporting models in |
---|
132 | <a target="_blank" href="http://www.ampl.com/">AMPL</a> format is |
---|
133 | available. This functionality is mainly intended for small nonlinear or |
---|
134 | mixed integer programs, and was only implemented in order to save one |
---|
135 | particular problem. If you are interested in a better support, make a |
---|
136 | feature request.<table cellPadding="10" width="100%" id="table4"> |
---|
137 | <tr> |
---|
138 | <td class="xmpcode"> |
---|
139 | <pre>sdpvar a b c |
---|
140 | F = set(a+b^2 < c*pi) + set(integer(b)) + set(a+b==3); |
---|
141 | obj = a*b*c; |
---|
142 | saveampl(F,obj,'mymodel.mod') |
---|
143 | type mymodel</pre> |
---|
144 | <pre><font color="#000000">var x {1..2}; |
---|
145 | var z {1..1} integer ; |
---|
146 | minimize obj: x[1]*z[1]*x[2]; |
---|
147 | subject to constr1: 0 <= -x[1]+x[2]-z[1]^2; |
---|
148 | subject to constr2: 0 == 3-x[1]-z[1]; |
---|
149 | solve; |
---|
150 | display x; |
---|
151 | display z; |
---|
152 | display obj;</font></pre> |
---|
153 | </td> |
---|
154 | </tr> |
---|
155 | </table> |
---|
156 | </td> |
---|
157 | </tr> |
---|
158 | </table> |
---|
159 | </div> |
---|
160 | |
---|
161 | </body> |
---|
162 | |
---|
163 | </html> |
---|