|
667 | 667 | % required to avoid mismatch warning message if mixed |
668 | 668 | % integer price computation stage is not skipped |
669 | 669 | % - ``relax_integer`` (0) - relax integer constraints, if true |
| 670 | + % - ``fix_integer`` (0) - fix integer variables at value in |
| 671 | + % ``x0``, if true |
670 | 672 | % - ``skip_prices`` (0) - flag that specifies whether or not |
671 | 673 | % to skip the price computation stage for mixed integer |
672 | 674 | % problems, in which the problem is re-solved for only the |
|
773 | 775 | [x, f, eflag, output, lambda] = pnes_master(fcn, x0, opt); |
774 | 776 | end |
775 | 777 | case {'MINLP', 'NLP'} |
776 | | - mixed_integer = strcmp(pt(1:2), 'MI') && ... |
777 | | - (~isfield(opt, 'relax_integer') || ~opt.relax_integer); |
| 778 | + [mixed_integer, x0, xmin, xmax, vtype] = ... |
| 779 | + mm.mixed_integer_helper(opt); |
778 | 780 | if mixed_integer %% MINLP - mixed integer non-linear program |
779 | 781 | error('mp.opt_model.solve: not yet implemented for ''MINLP'' problems.') |
780 | 782 | else %% NLP - nonlinear program |
781 | | - %% optimization vars, bounds, types |
782 | | - [x0, xmin, xmax] = mm.var.params(); |
783 | | - if isfield(opt, 'x0') |
784 | | - x0 = opt.x0; |
785 | | - end |
786 | | - |
787 | 783 | %% run solver |
788 | 784 | [A, l, u] = mm.lin.params(mm.var); |
789 | 785 | f_fcn = @(x)nlp_costfcn(mm, x); |
|
797 | 793 | [HH, CC, C0] = mm.qdc.params(mm.var); |
798 | 794 | [Q, B, ll, uu] = mm.qcn.params(mm.var); |
799 | 795 | [A, l, u] = mm.lin.params(mm.var); |
800 | | - mixed_integer = strcmp(pt(1:2), 'MI') && ... |
801 | | - (~isfield(opt, 'relax_integer') || ~opt.relax_integer); |
802 | | - |
| 796 | + [mixed_integer, x0, xmin, xmax, vtype] = ... |
| 797 | + mm.mixed_integer_helper(opt); |
803 | 798 | if mixed_integer |
804 | | - %% optimization vars, bounds, types |
805 | | - [x0, xmin, xmax, vtype] = mm.var.params(); |
806 | | - if isfield(opt, 'x0') |
807 | | - x0 = opt.x0; |
808 | | - end |
809 | | - |
810 | 799 | %% run solver |
811 | 800 | if isempty(Q) %% MILP, MIQP - mixed integer linear/quadratic program |
812 | 801 | [x, f, eflag, output, lambda] = ... |
|
817 | 806 | % miqcqps_master(HH, CC, Q, B, k, ll, uu, A, l, u, xmin, xmax, x0, vtype, opt); |
818 | 807 | end |
819 | 808 | else %% LP, QP - linear/quadratic program |
820 | | - %% optimization vars, bounds, types |
821 | | - [x0, xmin, xmax] = mm.var.params(); |
822 | | - if isfield(opt, 'x0') |
823 | | - x0 = opt.x0; |
824 | | - end |
825 | | - |
826 | 809 | %% run solver |
827 | 810 | if isempty(Q) %% LP, QP - linear/quadratic program |
828 | 811 | [x, f, eflag, output, lambda] = ... |
@@ -1129,6 +1112,37 @@ function display(mm, varargin) |
1129 | 1112 | end |
1130 | 1113 | end |
1131 | 1114 | end %% methods |
| 1115 | + |
| 1116 | + methods (Access=protected) |
| 1117 | + function [mixed_integer, x0, xmin, xmax, vtype] = mixed_integer_helper(mm, opt) |
| 1118 | + % |
| 1119 | + pt = mm.problem_type(); |
| 1120 | + mixed_integer = strcmp(pt(1:2), 'MI') && ... |
| 1121 | + (~isfield(opt, 'relax_integer') || ~opt.relax_integer); |
| 1122 | + if mixed_integer |
| 1123 | + %% optimization vars, bounds, types |
| 1124 | + [x0, xmin, xmax, vtype] = mm.var.params(); |
| 1125 | + if isfield(opt, 'x0') |
| 1126 | + x0 = opt.x0; |
| 1127 | + end |
| 1128 | + |
| 1129 | + if isfield(opt, 'fix_integer') && opt.fix_integer |
| 1130 | + %% fix integer variables |
| 1131 | + j = find(vtype == 'B' | vtype == 'I')'; |
| 1132 | + xmin(j) = x0(j); |
| 1133 | + xmax(j) = x0(j); |
| 1134 | + mixed_integer = false; |
| 1135 | + end |
| 1136 | + else |
| 1137 | + %% optimization vars, bounds, types |
| 1138 | + [x0, xmin, xmax] = mm.var.params(); |
| 1139 | + if isfield(opt, 'x0') |
| 1140 | + x0 = opt.x0; |
| 1141 | + end |
| 1142 | + vtype = []; |
| 1143 | + end |
| 1144 | + end |
| 1145 | + end |
1132 | 1146 | end %% classdef |
1133 | 1147 |
|
1134 | 1148 | function d = copy_prop(s, d, prop) |
|
0 commit comments