[37] | 1 | function 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 | |
---|
| 5 | Matrices.lb = lower; |
---|
| 6 | Matrices.ub = upper; |
---|
| 7 | |
---|
| 8 | % Remove equality constraints and trivial stuff from big-M |
---|
| 9 | [equalities,redundant] = mpt_detect_fixed_rows(Matrices); |
---|
| 10 | Matrices = mpt_collect_equalities(Matrices,equalities); |
---|
| 11 | go_on_reducing = size(Matrices.Aeq,1)>0; |
---|
| 12 | Matrices = 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 |
---|
| 16 | parametric_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? |
---|
| 19 | if infeasible | parametric_empty |
---|
| 20 | return |
---|
| 21 | end |
---|
| 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. |
---|
| 27 | fixed = find(Matrices.lb == Matrices.ub); |
---|
| 28 | infeasible = 0; |
---|
| 29 | while 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); |
---|
| 35 | end |
---|
| 36 | |
---|
| 37 | % We are not interested in explicit solutions over numerically empty regions |
---|
| 38 | parametric_empty = any(abs(Matrices.lb(end-Matrices.nx+1:end)-Matrices.ub(end-Matrices.nx+1:end)) < 1e-6); |
---|
| 39 | |
---|
| 40 | if ~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 |
---|
| 87 | else |
---|
| 88 | |
---|
| 89 | end |
---|
| 90 | |
---|
| 91 | function [Pn,Fi,Gi,ac,Pfinal,details] = mpt_mpqp_mplcp(Matrices,options) |
---|
| 92 | |
---|
| 93 | if Matrices.qp |
---|
| 94 | lcpData = lcp_mpqp(Matrices); |
---|
| 95 | BB = mplcp(lcpData) |
---|
| 96 | [Pn,Fi,Gi] = soln_to_mpt(lcpData,BB); |
---|
| 97 | else |
---|
| 98 | lcpData = lcp_mplp(Matrices); |
---|
| 99 | BB = mplcp(lcpData) |
---|
| 100 | [Pn,Fi,Gi] = soln_to_mpt(lcpData,BB); |
---|
| 101 | end |
---|
| 102 | Pfinal = union(Pn); |
---|
| 103 | if 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 |
---|
| 109 | else |
---|
| 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 |
---|
| 115 | end |
---|
| 116 | ac = []; |
---|