⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mp.htm

📁 optimization toolbox
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<title>YALMIP Example : Multiparametric programming</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<link href="yalmip.css" type="text/css" rel="stylesheet">
<base target="_self">
</head>

<body leftMargin="0" topMargin="0">

<div align="left">
  <table border="0" cellpadding="4" cellspacing="3" style="border-collapse: collapse" bordercolor="#000000" width="100%" align="left" height="100%">
    <tr>
      <td width="100%" align="left" height="100%" valign="top">
      <h2>Multiparametric programming</h2>
      <hr noShade SIZE="1">
    <p>
    <img border="0" src="exclamationmark.jpg" align="left" width="16" height="16">This 
    example requires the <a href="solvers.htm#mpt">Multi-Parametric 
      Toolbox (MPT)</a>. </p>
      <p>YALMIP can be used to calculate explicit solutions of linear and quadratic 
      programs by interfacing the <a href="solvers.htm#mpt">Multi-Parametric 
      Toolbox (MPT)</a>. This chapter assumes that the reader is familiar with 
		parametric programming and the basics of <a href="solvers.htm#mpt">MPT</a>.</p>
		<h3>Standard example.</h3>
		<p>Consider the following simple quadratic program in the<i> decision 
		variable</i> <b>z</b>, solved 
		for a particular value on a <i>parameter</i> <b>x</b>.</p>
      <table cellPadding="10" width="100%" id="table1">
        <tr>
          <td class="xmpcode">
          <pre>A = randn(15,3);
b = rand(15,1);
E = randn(15,2);

z = sdpvar(3,1);
x = [0.1;0.2];

F = set(A*z &lt;= b+E*x);
obj = (z-1)'*(z-1);

sol = solvesdp(F,obj);
double(z)
<font color="#000000">ans =</font></pre>
			<pre><font color="#000000">   -0.1454
   -0.1789
   -0.0388</font></pre>
          </td>
        </tr>
      </table>
      <p>To obtain the parametric solution with respect to <b>x</b>, we call the 
		function <code>solvemp.m</code>, and tell the solver that <b>x</b> is a 
		parametric variable. Moreover, we must add constraints to declare a 
		bound on the region where we want to compute the parametric solution, the so called exploration set.</p>
      <table cellPadding="10" width="100%">
        <tr>
          <td class="xmpcode">
          <pre>x = sdpvar(2,1);
F = set(A*z &lt;= b+E*x) + set(-1 &lt;= x &lt;= 1)
sol = solvemp(F,obj,[],x);</pre>
          </td>
        </tr>
      </table>
      <p>The first output is an <a href="solvers.htm#mpt">MPT</a> structure. 
		In accordance with <a href="solvers.htm#mpt">MPT</a> syntax, the optimizer for the parametric value&nbsp; 
		is given by the following code.</p>
      <table cellPadding="10" width="100%" id="table2">
        <tr>
          <td class="xmpcode">
          <pre>xx = [0.1;0.2];
[i,j] = isinside(sol{1}.Pn,xx)
sol{1}.Bi{j}*xx + sol{1}.Ci{j}
<font color="#000000">ans =</font></pre>
			<pre><font color="#000000">   -0.1454
   -0.1789
   -0.0388</font></pre>
          </td>
        </tr>
      </table>
      <p>By using more outputs from <code>solvemp</code>, it is possible to simplify 
		things considerably.</p>
      <table cellPadding="10" width="100%" id="table3">
        <tr>
          <td class="xmpcode">
          <pre>[sol,diagnostics,Z,Valuefunction,Optimizer] = solvemp(F,obj,[],x);</pre>
          </td>
        </tr>
      </table>
      <p>The function now returns solutions using YALMIPs
		<a href="extoperators.htm">nonlinear operator</a> framework. To retrieve the solution for a particular 
		parameter, simply use <code>assign</code> and <code>double</code> in standard fashion.</p>
      <table cellPadding="10" width="100%" id="table4">
        <tr>
          <td class="xmpcode">
          <pre>assign(x,[0.1;0.2]);
double(Optimizer)</pre>
          </td>
        </tr>
      </table>
      <p>Some of the plotting capabilities of <a href="solvers.htm#mpt">MPT</a> are overloaded for 
		the piecewise functions.</p>
      <table cellPadding="10" width="100%" id="table25">
        <tr>
          <td class="xmpcode">
          <pre>plot(Valuefunction)</pre>
          </td>
        </tr>
      </table>
      <p>More about the output later.</p>
      <h3>MPC example</h3>
		<p>Define numerical data for a linear system, prediction matrices, and 
		variables for current state <b>x</b> and the 
       
      	future control sequence<b> U</b>, for an MPC problem with horizon 5.</p>
      <table cellPadding="10" width="100%">
        <tr>
          <td class="xmpcode">
          <pre>N = 5;
A = [2 -1;1 0];
B = [1;0];
C = [0.5 0.5];
[H,S] = create_CHS(A,B,C,N);</pre>
          <pre>x = sdpvar(2,1);
U = sdpvar(N,1);</pre>
          </td>
        </tr>
      </table>
      <p>The future output predictions are linear in the current state&nbsp;and the 
      control sequence.</p>
      <table cellPadding="10" width="100%">
        <tr>
          <td class="xmpcode">
          <pre>Y = H*x+S*U;</pre>
          </td>
        </tr>
      </table>
      <p>We wish to minimize a  quadratic cost, compromising between small input 
		and outputs.</p>
      <table cellPadding="10" width="100%">
        <tr>
          <td class="xmpcode">
          <pre>objective = Y'*Y+U'*U;</pre>
          </td>
        </tr>
      </table>
      <p>The input variable has a hard constraint, and so does the output at the 
		terminal state.</p>
      <table cellPadding="10" width="100%">
        <tr>
          <td class="xmpcode">
          <pre>F = set(1 &gt; U &gt; -1);
F = F+set(1 &gt; Y(N) &gt; -1); </pre>
          </td>
        </tr>
      </table>
      <p>We seek the explicit solution <b><font face="Tahoma,Arial,sans-serif">U(x)</font></b> over the 
		exploration set <b>
      <font face="Tahoma,Arial,sans-serif">|x|&#8804;1</font></b>.</p>
      <table cellPadding="10" width="100%">
        <tr>
          <td class="xmpcode">
          <pre>F = F + set(5 &gt; x &gt; -5);</pre>
          </td>
        </tr>
      </table>
      <p>The explicit solution <b>U(x)</b> is obtained by calling
      <code>solvemp</code> with the parametric variable <b>x</b> as the fourth argument. 
		Additionally, since we only are interested in the first element of the 
		solution <b>U</b>, we use a fifth input to communicate this.</p>
      <table cellPadding="10" width="100%">
        <tr>
          <td class="xmpcode">
          <pre>[sol,diagnostics,Z,Valuefunction,Optimizer] = solvemp(F,objective,[],x,U(1));</pre>
          </td>
        </tr>
      </table>
      <p>The explicit solution can, e.g, be plotted (see the <a href="solvers.htm#mpt">MPT</a> 
      manual informationon the solution structure)</p>
      <table cellPadding="10" width="100%">
        <tr>
          <td class="xmpcode">
          <pre>sol{1}
<font color="#000000">
ans = 

 Pn: [1x13 polytope]
 Fi: {1x13 cell}
 Gi: {1x13 cell}
 activeConstraints: {1x13 cell}
 Phard: [1x1 polytope]</font></pre>
          <pre>figure
plot(sol{1}.Pn)
figure
plot(Valuefunction)
figure
plot(Optimizer)</pre>
          </td>
        </tr>
      </table>
      <p>The following piece of code calculates the explicit MPC controller with 
      an worst-case L<sub><font face="Arial">&#8734;</font></sub> cost instead 
		(i.e. worst case control/output peak along the predictions).</p>
      <table cellPadding="10" width="100%">
        <tr>
          <td class="xmpcode">
          <pre>A = [2 -1;1 0];
B = [1;0];
C = [0.5 0.5];
N = 5;
[H,S] = create_CHS(A,B,C,N);
t = sdpvar(1,1);
x = sdpvar(2,1);
U = sdpvar(N,1);
Y = H*x+S*U;
F = set(-1 &lt; U &lt; 1);
F = F+set(-1 &lt; Y(N) &lt; 1); 
F = F + set(-5 &lt; x &lt; 5);
[sol,diagnostics,Z,Valuefunction,Optimizer] = solvemp(F,norm([Y;U],inf),[],x);</pre>
          </td>
        </tr>
      </table>
      <p>This example enables us to introduce the overloading of the projection 
      functionality in <a href="solvers.htm#mpt">MPT</a>. In MPC, 
      only the first input, <b>U(1)</b>, is of interest. What we can do is to 
      project the whole problem to the parametric variable <b>x</b>, the 
      objective function <b>t</b>, and the variable of interest, <b>U(1)</b>. 
		The following piece of code projects the problem to the reduced set of 
		variables, and solves the multi-parametric LP in this reduced space (not 
		necessarily an efficient approach though, projection is very expensive, 
		and we can easily end up with a problem with many constraints in the 
		reduced variables.)</p>
      <table cellPadding="10" width="100%">
        <tr>
          <td class="xmpcode">
          <pre>A = [2 -1;1 0];
B = [1;0];
C = [0.5 0.5];
N = 5;
[H,S] = create_CHS(A,B,C,N);
t = sdpvar(1,1);
x = sdpvar(2,1);
U = sdpvar(N,1);
Y = H*x+S*U;
F = set(-1 &lt; U &lt; 1);
F = F+set(-1 &lt; Y(N) &lt; 1); 
F = F + set(-5 &lt; x &lt; 5);
F = F + set(-t &lt; [Y;U] &lt; t);

F = projection(F,[x;t;U(1)]);

[sol_p,diagnostics_p,Zsol_p,Valuefunction_p,Optimizer_p] = solvemp(F,t,[],x,[U(1);t]);</pre>
          </td>
        </tr>
      </table>
      <p>To check that the two solutions actually coincide, we compare the value 
		functions and conclude that they are essentially the same.</p>
      <table cellPadding="10" width="100%" id="table30">
        <tr>
          <td class="xmpcode">

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -