ParOpt /

ParOpt

ParOpt.ParOpt History

Hide minor edits - Show changes to output

March 08, 2016, at 09:37 AM by 2001:67c:10ec:36c2::61 -
Changed line 50 from:
   solution.xopt.fplot('primal', 'index', i);
to:
   solution.xopt.fplot('primal', 'position', i);
Changed line 5 from:
\min \  (c + \theta d)^T x \\
to:
\min \  (c + D \theta)^T x \\
Changed line 17 from:
d = [1; 1];
to:
D = [1; 1];
Changed line 30 from:
J = (c + theta*d)'*x;
to:
J = (c + D*theta)'*x;
Added lines 2-71:

Say you want to find the optimal value of {$x$} as a function of the parameter {$\theta$} which solves the following parametric linear problem:
{$$
\min \  (c + \theta d)^T x \\
\text{s.t.} \ A x \le b,\\
\ x \ge 0,\\
\ 0 \le \theta \le u,
$$}
where {$A$}, {$b$}, {$c$}, {$d$}, {$u$} are fixed problem data, e.g.:
(:source lang=MATLAB -getcode:) [@
% problem data
A = [eye(2); -eye(2)];
b = [1; 1; -0.5; -0.5];
u = 2;
c = [1; 1];
d = [1; 1];
@]

We first formulate the problem in [[http://users.isy.liu.se/johanl/yalmip/|YALMIP]]:
(:source lang=MATLAB -getcode:) [@
% optimization variables
nx = size(A, 2);
x = sdpvar(nx, 1);

% parameter
theta = sdpvar(1, 1);

% objective function
J = (c + theta*d)'*x;

% constraints
C = [ A*x <= b, x >= 0, 0 <= theta <= u ];
@]

Then we convert the problem into the MPT format:
(:source lang=MATLAB -getcode:) [@
plp = Opt(C, J, theta, x);
@]

and tell MPT to constuct the parametric solution:
(:source lang=MATLAB -getcode:) [@
solution = plp.solve();
@]

The parametric solution maps the parameters onto optimization variables. For the case of a parametric linear problem, such a map takes a form of a piecewise affine function {$ x^{\star} = F_i \theta + g_i $} if {$ \theta \in \mathcal{R}_i $}, where {$ \mathcal{R}_i $}, {$i = 1, \ldots, N$} are so-called critical regions. The function can be plotted using the @@fplot()@@ method:
(:source lang=MATLAB -getcode:) [@
for i = 1:nx
    figure;
    solution.xopt.fplot('primal', 'index', i);
    xlabel('t');
    ylabel(sprintf('x_%d(t)', i));
end
@]

We can also plot the value function versus the parameter by
(:source lang=MATLAB -getcode:) [@
figure;
solution.xopt.fplot('obj');
xlabel('t');
ylabel('J(t)');
@]

To plot just the critical regions, use @@solution.xopt.plot()@@.

Finally, the parametric solution can be used to easily obtain the values of the optimization variables for a particular value of the parameter using the @@feval()@@ method:
(:source lang=MATLAB -getcode:) [@
t0 = 0.5;
x_t0 = solution.xopt.feval(t0, 'primal')
J_t0 = solution.xopt.feval(t0, 'obj')
@]
Added line 1:
! Parametric optimization