source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/modules/parametric/solvemp.m @ 37

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

Added original make3d

File size: 5.5 KB
Line 
1function varargout = solvemp(F,h,ops,x,y)
2%SOLVEMP Computes solution to multi-parametric optimization problem
3%
4% min_z(x)   h(x,z)
5% subject to
6%            F(x,z) > 0
7%
8%
9% [SOL, DIAGNOSTIC,Z,HPWF,ZPWF] = SOLVEMP(F,h,options,x,y)
10%
11% SOL        : Multi-parametric solution (see MPT toolbox)
12%
13% DIAGNOSTIC : struct with diagnostic information
14%
15% Z          : SDPVAR object with the detected decision variable z
16%
17% HPWF       : The value function as a pwf function
18%
19% ZPWF       : The optimal decision variable as a pfw function
20%
21% Input
22%    F        : SET object describing the constraints.
23%    h        : SDPVAR object describing the objective function h(x,z).
24%    options  : solver options. See SDPSETTINGS. Can be [].
25%    x        : Parametric variables
26%    y        : Requested decision variables (subset of z)
27%
28% NOTE : If you are solving a problem leading to an mpMILP, the
29% output SOL will be a set-valued map. To obtain the minimal
30% solution (without so called overlaps), run removeOverlaps(SOL). If you
31% have requested the 5th output ZPWF, overlaps are automatically removed.
32% If your problem leads to an mpMIQP,  the output SOL will also be a
33% set-valued map, but there is currently no way in MPT to obtain a
34% non-overlapping solution. To use the solution in MPT, the command
35% mpt_mergeCS(SOL) can be useful. Notice that the fifth output argument
36% not will be available for mpMIQP problems.
37%
38% See also PARAMETRIC, SET, SDPSETTINGS, YALMIPERROR
39
40% Author Johan Löfberg
41% $Id: solvemp.m,v 1.9 2006/09/13 09:28:52 joloef Exp $
42
43if nargin <= 3
44    ops = sdpsettings;
45end
46
47if nargin <=3
48    x = [];
49    y = [];
50end
51
52par_declarations = is(F,'parametric');
53if any(par_declarations)
54    x = [x;recover(getvariables(sdpvar(F(find(par_declarations)))))];
55    F = F(find(~par_declarations));
56end
57
58if length(x) == 0
59    error('solvemp must always have 4 input arguments or a parametric declaration');
60end
61
62if ~isempty(ops)
63    if isequal(ops.solver,'')
64        ops.solver = 'mpt';
65    end
66else
67    ops = sdpsettings('solver','mpt');
68end
69
70if nargin == 4
71    y = [];
72    ny = 0;
73    my = 0;
74else
75    % YALMIP wants a vector as desired decsision variable
76    [ny,my] = size(y);
77    y = reshape(y,ny*my,1);
78end
79
80% Robustify first?
81if length(F) > 0
82    unc_declarations = is(F,'uncertain');
83    if any(unc_declarations)
84        w = recover(getvariables(sdpvar(F(find(unc_declarations)))));
85        F = F(find(~unc_declarations));
86        [F,h,failure] = robustify(F,h,ops,w);
87        if failure
88            error('Derivation of robust counter-part failed')
89        end
90    end
91end
92
93sol = solvesdp(F,h,ops,x,y);
94
95if isfield(sol,'mpsol')
96    if ~isfield(sol.mpsol,'model')
97        varargout{1} = [];
98        varargout{2} = sol;
99        varargout{3} = [];
100        varargout{4} = [];
101        varargout{5} = [];
102    elseif isempty(sol.mpsol.model{1})
103        varargout{1} = sol.mpsol.model;       
104        varargout{2} = sol;
105        varargout{3} = [];
106        varargout{4} = [];
107        varargout{5} = [];
108    else
109
110        mpsolution = sol.mpsol.model;
111        varargout{1} = sol.mpsol.model;
112
113        if nargout > 2
114            z = recover(sol.solveroutput.U);
115            x = recover(sol.solveroutput.x);
116            varargout{3}= z;
117        end
118
119        if nargout > 3
120            % User wants the value function               
121            if length(mpsolution) == 1
122                if isequal(mpsolution{1}.convex,1)
123                    % Simple mpLP value function
124                    if ops.mp.simplify
125                        s = mpsolution{1};
126                        s.Fi = s.Bi;
127                        s.Gi = s.Ci;
128                        s = mpt_simplify(s);
129                        s.Bi = s.Fi;
130                        s.Ci = s.Gi;
131                        varargout{4} = pwf(s,x,'convex');
132                    else
133                        varargout{4} = pwf(mpsolution{1},x,'convex');
134                    end
135                else
136                    % Probably generated from removing overlaps
137                    varargout{4} = pwf(mpsolution,x,'general');
138                end
139            else
140                % No overlap removal done
141                varargout{4} = pwf(mpsolution,x,'convexoverlapping');
142            end
143        end
144
145        if nargout > 4
146            % User wants optimizer in YALMIP format
147            % Any overlaps?
148            anyQP = 0;
149            if length(varargout{1}) > 1
150                for i = 1:length(sol.mpsol.model)
151                    if nnz([sol.mpsol.model{i}.Ai{:}])>0
152                        anyQP = 1;
153                        break
154                    end
155                end
156                if ~anyQP
157                    minimalmodel{1} = mpt_removeOverlaps(sol.mpsol.model);
158                    varargout{1} = minimalmodel;
159                end
160            else
161                minimalmodel = varargout{1};
162            end
163            % PWA assumes we want Bi and Ci
164            if ~anyQP
165                minimalmodel{1}.Ai = cell(1,length(minimalmodel{1}.Fi));
166                minimalmodel{1}.Bi = minimalmodel{1}.Fi;
167                minimalmodel{1}.Ci = minimalmodel{1}.Gi;
168                varargout{5} = pwf(minimalmodel,x,'general');
169                if min([ny my])>0
170                    varargout{5} = reshape(varargout{5},ny,my);
171                end
172            else
173                disp('Optimizer (5th output) not available for overlapping quadratic problems.');
174                varargout{5} = [];
175            end
176        end
177    end
178else
179    varargout{1} = [];
180    varargout{2} = sol;
181    varargout{3} = [];
182    varargout{4} = [];
183    varargout{5} = [];
184end
185varargout{2} = sol;
186
Note: See TracBrowser for help on using the repository browser.