[37] | 1 | function p = preprocess_bilinear_bounds(p) |
---|
| 2 | |
---|
| 3 | % if ~isempty(p.bilinears) |
---|
| 4 | % quadratics = find(p.bilinears(:,2) == p.bilinears(:,3)); |
---|
| 5 | % for i = quadratics(:)' |
---|
| 6 | % if ismember(p.bilinears(i,2),p.binary_variables) |
---|
| 7 | % p.binary_variables = [p.binary_variables p.bilinears(i,1)]; |
---|
| 8 | % elseif ismember(p.bilinears(i,2),p.integer_variables) |
---|
| 9 | % p.integer_variables = [p.integer_variables p.bilinears(i,1)]; |
---|
| 10 | % end |
---|
| 11 | % end |
---|
| 12 | % end |
---|
| 13 | |
---|
| 14 | if ~isempty(p.integer_variables) |
---|
| 15 | for i = 1:size(p.bilinears,1) |
---|
| 16 | if ismember(p.bilinears(i,2),p.integer_variables) |
---|
| 17 | if ismember(p.bilinears(i,3),p.integer_variables) |
---|
| 18 | p.integer_variables = [p.integer_variables p.bilinears(i,1)]; |
---|
| 19 | end |
---|
| 20 | end |
---|
| 21 | end |
---|
| 22 | if p.K.f > 0 |
---|
| 23 | for i = 1:p.K.f |
---|
| 24 | if all(p.F_struc(i,:) == fix(p.F_struc(i,:))) |
---|
| 25 | involved = find(p.F_struc(i,2:end)); |
---|
| 26 | if nnz(ismember(involved,p.integer_variables)) == length(involved)-1 |
---|
| 27 | p.integer_variables = [p.integer_variables involved]; |
---|
| 28 | end |
---|
| 29 | end |
---|
| 30 | end |
---|
| 31 | p.integer_variables = unique(p.integer_variables ); |
---|
| 32 | end |
---|
| 33 | end |
---|
| 34 | |
---|
| 35 | if ~isempty(p.binary_variables) |
---|
| 36 | for i = 1:size(p.bilinears,1) |
---|
| 37 | if ismember(p.bilinears(i,2),p.binary_variables) |
---|
| 38 | if ismember(p.bilinears(i,3),p.binary_variables) |
---|
| 39 | p.binary_variables = [p.binary_variables p.bilinears(i,1)]; |
---|
| 40 | end |
---|
| 41 | end |
---|
| 42 | end |
---|
| 43 | for i = 1:p.K.f |
---|
| 44 | if all(p.F_struc(i,:) == fix(p.F_struc(i,:))) |
---|
| 45 | involved = find(p.F_struc(i,2:end)); |
---|
| 46 | if nnz(ismember(involved,p.binary_variables)) == length(involved)-1 |
---|
| 47 | p.binary_variables = [p.binary_variables involved]; |
---|
| 48 | end |
---|
| 49 | end |
---|
| 50 | end |
---|
| 51 | p.binary_variables = unique(p.binary_variables ); |
---|
| 52 | |
---|
| 53 | end |
---|
| 54 | |
---|
| 55 | if isempty(p.ub) |
---|
| 56 | p.ub = repmat(inf,length(p.c),1); |
---|
| 57 | end |
---|
| 58 | if isempty(p.lb) |
---|
| 59 | p.lb = repmat(-inf,length(p.c),1); |
---|
| 60 | end |
---|
| 61 | if ~isempty(p.F_struc) |
---|
| 62 | [lb,ub,used_rows] = findulb(p.F_struc,p.K); |
---|
| 63 | if ~isempty(used_rows) |
---|
| 64 | lower_defined = find(~isinf(lb)); |
---|
| 65 | if ~isempty(lower_defined) |
---|
| 66 | p.lb(lower_defined) = max(p.lb(lower_defined),lb(lower_defined)); |
---|
| 67 | end |
---|
| 68 | upper_defined = find(~isinf(ub)); |
---|
| 69 | if ~isempty(upper_defined) |
---|
| 70 | p.ub(upper_defined) = min(p.ub(upper_defined),ub(upper_defined)); |
---|
| 71 | end |
---|
| 72 | % Remove linear bounds |
---|
| 73 | used_rows = used_rows(find(~any(p.F_struc(p.K.f+used_rows,1+p.nonlinears),2))); |
---|
| 74 | not_used_rows = setdiff(1:p.K.l,used_rows); |
---|
| 75 | for i = 1:length(p.KCut.l) |
---|
| 76 | p.KCut.l(i) = find(not_used_rows==p.KCut.l(i) ); |
---|
| 77 | p.originalModel.KCut.l(i) = find(not_used_rows==p.originalModel.KCut.l(i) ); |
---|
| 78 | end |
---|
| 79 | if ~isempty(used_rows) |
---|
| 80 | p.F_struc(p.K.f+used_rows,:)=[]; |
---|
| 81 | p.K.l = p.K.l - length(used_rows); |
---|
| 82 | used_rows = used_rows(used_rows <= p.originalModel.K.l); |
---|
| 83 | p.originalModel.F_struc(p.originalModel.K.f+used_rows,:)=[]; |
---|
| 84 | p.originalModel.K.l = p.originalModel.K.l - length(used_rows); |
---|
| 85 | end |
---|
| 86 | end |
---|
| 87 | end |
---|
| 88 | p.lb(p.binary_variables) = max(0,p.lb(p.binary_variables)); |
---|
| 89 | p.ub(p.binary_variables) = min(1,p.ub(p.binary_variables)); |
---|
| 90 | p.lb(p.integer_variables) = ceil(p.lb(p.integer_variables)); |
---|
| 91 | p.ub(p.integer_variables) = floor(p.ub(p.integer_variables)); |
---|
| 92 | |
---|
| 93 | p = clean_bounds(p); |
---|
| 94 | if ~isempty(p.bilinears) |
---|
| 95 | p = updatenonlinearbounds(p); |
---|
| 96 | end |
---|