1 | function Matrices = yalmip2mpt(interfacedata) |
---|
2 | |
---|
3 | F_struc = interfacedata.F_struc; |
---|
4 | c = interfacedata.c; |
---|
5 | f = interfacedata.f; |
---|
6 | K = interfacedata.K; |
---|
7 | x0 = interfacedata.x0; |
---|
8 | Q = interfacedata.Q; |
---|
9 | lb = interfacedata.lb; |
---|
10 | ub = interfacedata.ub; |
---|
11 | |
---|
12 | % We have three groups of variables. |
---|
13 | % parametric, free, and binary free |
---|
14 | param_var = interfacedata.parametric_variables; |
---|
15 | free_var = setdiff(1:length(c),param_var); |
---|
16 | binary_var = interfacedata.binary_variables; |
---|
17 | |
---|
18 | % These rows of the solution should be returned |
---|
19 | if isempty(interfacedata.requested_variables) |
---|
20 | Matrices.requested_variables = 1:length(free_var); |
---|
21 | else |
---|
22 | Matrices.requested_variables = []; |
---|
23 | for i = 1:length(interfacedata.requested_variables) |
---|
24 | Matrices.requested_variables = [Matrices.requested_variables find(ismember(free_var,interfacedata.requested_variables(i)))]; |
---|
25 | end |
---|
26 | end |
---|
27 | |
---|
28 | % Extract data for free and parametric variables |
---|
29 | Matrices.F = (2*Q(param_var,free_var)); |
---|
30 | Matrices.Y = (Q(param_var,param_var)); |
---|
31 | Matrices.H = (2*Q(free_var,free_var)); |
---|
32 | Matrices.G = (-F_struc(1+K.f:end,1+free_var)); |
---|
33 | Matrices.E = (F_struc(1+K.f:end,1+param_var)); |
---|
34 | Matrices.W = (F_struc(1+K.f:end,1)); |
---|
35 | Matrices.Cf = (c(free_var)'); |
---|
36 | Matrices.Cx = (c(param_var)'); |
---|
37 | Matrices.Cc = (f); |
---|
38 | |
---|
39 | % Equality constraints (YALMIP specific) |
---|
40 | Matrices.Aeq = -F_struc(1:K.f,1+free_var); |
---|
41 | Matrices.Beq = -F_struc(1:K.f,1+param_var); |
---|
42 | Matrices.beq = F_struc(1:K.f,1); |
---|
43 | |
---|
44 | % This is not dealth with in YALMIP |
---|
45 | Matrices.bndA=[]; |
---|
46 | Matrices.bndb=[]; |
---|
47 | |
---|
48 | % Save this silly info also |
---|
49 | Matrices.nu = length(free_var); |
---|
50 | Matrices.nx = length(param_var); |
---|
51 | |
---|
52 | if nnz(Matrices.H)==0 & nnz(Matrices.Y)==0%nnz(Q)==0 |
---|
53 | % Whoops, it's an LP and MPT uses the name H for linear cost also... |
---|
54 | Matrices.H = c(free_var)'; |
---|
55 | if nnz(Matrices.F) > 0 |
---|
56 | % Latest MPT does not fullify D |
---|
57 | Matrices.D = full(Matrices.F'); |
---|
58 | end |
---|
59 | Matrices.F = Matrices.Cx; |
---|
60 | Matrices.qp = 0; |
---|
61 | else |
---|
62 | Matrices.qp = 1; |
---|
63 | end |
---|
64 | |
---|
65 | if ~isempty(lb) |
---|
66 | Matrices.lb = [lb(free_var);lb(param_var)]; |
---|
67 | else |
---|
68 | Matrices.lb = repmat(-inf,nx+nu,1); |
---|
69 | end |
---|
70 | if ~isempty(ub) |
---|
71 | Matrices.ub = [ub(free_var);ub(param_var)]; |
---|
72 | else |
---|
73 | Matrices.ub = repmat(inf,nx+nu,1); |
---|
74 | end |
---|
75 | |
---|
76 | Matrices.param_var = interfacedata.parametric_variables; |
---|
77 | Matrices.free_var = setdiff(1:length(c),param_var); |
---|
78 | Matrices.binary_var_index = find(ismember(free_var,binary_var)); |
---|
79 | |
---|
80 | % A transformation to go to original variables when |
---|
81 | % equality constraints have been removed |
---|
82 | Matrices.getback = []; |
---|