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

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

Added original make3d

File size: 4.5 KB
Line 
1function model = mpt_solvenode(Matrices,lower,upper,OriginalModel,model,options)
2% This is the core code. Lot of pre-processing to get rid of strange stuff
3% arising from odd problems, big-M etc etc
4
5Matrices.lb = lower;
6Matrices.ub = upper;
7
8% Remove equality constraints and trivial stuff from big-M
9[equalities,redundant] = mpt_detect_fixed_rows(Matrices);
10Matrices = mpt_collect_equalities(Matrices,equalities);
11go_on_reducing = size(Matrices.Aeq,1)>0;
12Matrices = mpt_remove_equalities(Matrices,redundant);
13[Matrices,infeasible] = mpt_project_on_equality(Matrices);
14
15% We are not interested in explicit solutions over numerically empty regions
16parametric_empty = any(abs(Matrices.lb(end-Matrices.nx+1:end)-Matrices.ub(end-Matrices.nx+1:end)) < 1e-6);
17
18% Were the equality constraints found to be infeasible?
19if infeasible | parametric_empty
20    return
21end
22
23% For some models with a lot of big-M stuff etc, the amount of implicit
24% equalities are typically large, making the LP solvers unstable if they
25% are not removed. To avoid problems, we iteratively detect fixed variables
26% and strenghten the bounds.
27fixed = find(Matrices.lb == Matrices.ub);
28infeasible = 0;
29while 0%~infeasible & options.mp.presolve
30    [Matrices,infeasible] = mpt_derive_bounds(Matrices,options);
31    if isequal(find(Matrices.lb == Matrices.ub),fixed)
32        break
33    end
34    fixed = find(Matrices.lb == Matrices.ub);
35end
36
37% We are not interested in explicit solutions over numerically empty regions
38parametric_empty = any(abs(Matrices.lb(end-Matrices.nx+1:end)-Matrices.ub(end-Matrices.nx+1:end)) < 1e-6);
39
40if ~infeasible & ~parametric_empty
41
42    while go_on_reducing & ~infeasible & options.mp.presolve
43        [equalities,redundant] = mpt_detect_fixed_rows(Matrices);
44        Matrices = mpt_collect_equalities(Matrices,equalities);
45        go_on_reducing = size(Matrices.Aeq,1)>0;
46        Matrices = mpt_remove_equalities(Matrices,redundant);
47        [Matrices,infeasible] = mpt_project_on_equality(Matrices);
48        M = Matrices;
49        if  go_on_reducing & ~infeasible
50            [Matrices,infeasible] = mpt_derive_bounds(Matrices,options);
51        end
52        if infeasible
53            % Numerical problems most likely because this infeasibility
54            % should have been caught above. We have only cleaned the model
55            Matrices = M;
56        end
57    end
58
59    if ~infeasible
60        if Matrices.qp
61            if isequal(options.solver,'mplcp')
62                [Pn,Fi,Gi,ac,Pfinal,details] = mpt_mpqp_mplcp(Matrices,options);
63            else
64                e = eig(full(Matrices.H));
65                if min(e) == 0
66                    disp('Lack of strict convexity may lead to troubles in the mpQP solver')
67                elseif min(e) < -1e-8
68                    disp('Problem is not positive semidefinite! Your mpQP solution may be completely wrong')
69                elseif min(e) < 1e-5
70                    disp('QP is close to being (negative) semidefinite, may lead to troubles in mpQP solver')
71                end
72                %Matrices.H = Matrices.H + eye(length(Matrices.H))*1e-4;
73                [Pn,Fi,Gi,ac,Pfinal,details] = mpt_mpqp(Matrices,options.mpt);
74            end
75        else
76            if isequal(options.solver,'mplcp')
77                [Pn,Fi,Gi,ac,Pfinal,details] = mpt_mpqp_mplcp(Matrices,options);
78            else               
79                [Pn,Fi,Gi,ac,Pfinal,details] = mpt_mplp(Matrices,options.mpt);
80            end
81        end
82        [Fi,Gi,details] = mpt_project_back_equality(Matrices,Fi,Gi,details,OriginalModel);
83        [Fi,Gi] = mpt_select_rows(Fi,Gi,Matrices.requested_variables);
84        [Fi,Gi] = mpt_clean_optmizer(Fi,Gi);
85        model = mpt_appendmodel(model,Pfinal,Pn,Fi,Gi,details);
86    end
87else
88
89end
90
91function [Pn,Fi,Gi,ac,Pfinal,details] = mpt_mpqp_mplcp(Matrices,options)
92
93if Matrices.qp
94    lcpData = lcp_mpqp(Matrices);
95    BB = mplcp(lcpData)
96    [Pn,Fi,Gi] = soln_to_mpt(lcpData,BB);
97else
98    lcpData = lcp_mplp(Matrices);
99    BB = mplcp(lcpData)
100    [Pn,Fi,Gi] = soln_to_mpt(lcpData,BB);
101end
102Pfinal = union(Pn);
103if Matrices.qp
104    for i=1:length(Fi)
105        details.Ai{i} = 0.5*Fi{i}'*Matrices.H*Fi{i} + 0.5*(Matrices.F*Fi{i}+Fi{i}'*Matrices.F') + Matrices.Y;
106        details.Bi{i} = Matrices.Cf*Fi{i}+Gi{i}'*Matrices.F' + Gi{i}'*Matrices.H*Fi{i} + Matrices.Cx;
107        details.Ci{i} = Matrices.Cf*Gi{i}+0.5*Gi{i}'*Matrices.H*Gi{i} + Matrices.Cc;
108    end
109else
110    for i=1:length(Fi)
111        details.Ai{i} = [];
112        details.Bi{i} = Matrices.H*Fi{i};
113        details.Ci{i} = Matrices.H*Gi{i};
114    end
115end
116ac  = [];
Note: See TracBrowser for help on using the repository browser.