|
4 | 4 | # in the LICENSE.md file or at https://opensource.org/licenses/MIT. |
5 | 5 |
|
6 | 6 | function _bound_infeasibility!(optimizer::Optimizer, ::Type{T}) where {T} |
7 | | - variables = Dict{MOI.VariableIndex,Interval{T}}() |
8 | | - |
9 | | - variable_indices = |
10 | | - MOI.get(optimizer.original_model, MOI.ListOfVariableIndices()) |
| 7 | + return _bound_infeasibility!(optimizer.original_model, optimizer.results, T) |
| 8 | +end |
11 | 9 |
|
| 10 | +function _bound_infeasibility!( |
| 11 | + original_model::MOI.ModelLike, |
| 12 | + results::Vector{InfeasibilityData}, |
| 13 | + ::Type{T}, |
| 14 | +) where {T} |
| 15 | + variables = Dict{MOI.VariableIndex,Interval{T}}() |
| 16 | + variable_indices = MOI.get(original_model, MOI.ListOfVariableIndices()) |
12 | 17 | lb = Dict{MOI.VariableIndex,T}() |
13 | 18 | lb_con = Dict{MOI.VariableIndex,MOI.ConstraintIndex}() |
14 | 19 | ub = Dict{MOI.VariableIndex,T}() |
15 | 20 | ub_con = Dict{MOI.VariableIndex,MOI.ConstraintIndex}() |
16 | | - |
17 | 21 | for con in MOI.get( |
18 | | - optimizer.original_model, |
| 22 | + original_model, |
19 | 23 | MOI.ListOfConstraintIndices{MOI.VariableIndex,MOI.EqualTo{T}}(), |
20 | 24 | ) |
21 | | - set = MOI.get(optimizer.original_model, MOI.ConstraintSet(), con) |
22 | | - func = MOI.get(optimizer.original_model, MOI.ConstraintFunction(), con) |
| 25 | + set = MOI.get(original_model, MOI.ConstraintSet(), con) |
| 26 | + func = MOI.get(original_model, MOI.ConstraintFunction(), con) |
23 | 27 | lb[func] = set.value |
24 | 28 | lb_con[func] = con |
25 | 29 | ub[func] = set.value |
26 | 30 | ub_con[func] = con |
27 | 31 | end |
28 | | - |
29 | 32 | for con in MOI.get( |
30 | | - optimizer.original_model, |
| 33 | + original_model, |
31 | 34 | MOI.ListOfConstraintIndices{MOI.VariableIndex,MOI.LessThan{T}}(), |
32 | 35 | ) |
33 | | - set = MOI.get(optimizer.original_model, MOI.ConstraintSet(), con) |
34 | | - func = MOI.get(optimizer.original_model, MOI.ConstraintFunction(), con) |
35 | | - # lb[func] = -Inf |
| 36 | + set = MOI.get(original_model, MOI.ConstraintSet(), con) |
| 37 | + func = MOI.get(original_model, MOI.ConstraintFunction(), con) |
| 38 | + # lb[func] = typemin(T) |
36 | 39 | ub[func] = set.upper |
37 | 40 | ub_con[func] = con |
38 | 41 | end |
39 | | - |
40 | 42 | for con in MOI.get( |
41 | | - optimizer.original_model, |
| 43 | + original_model, |
42 | 44 | MOI.ListOfConstraintIndices{MOI.VariableIndex,MOI.GreaterThan{T}}(), |
43 | 45 | ) |
44 | | - set = MOI.get(optimizer.original_model, MOI.ConstraintSet(), con) |
45 | | - func = MOI.get(optimizer.original_model, MOI.ConstraintFunction(), con) |
| 46 | + set = MOI.get(original_model, MOI.ConstraintSet(), con) |
| 47 | + func = MOI.get(original_model, MOI.ConstraintFunction(), con) |
46 | 48 | lb[func] = set.lower |
47 | 49 | lb_con[func] = con |
48 | | - # ub[func] = Inf |
| 50 | + # ub[func] = typemax(T) |
49 | 51 | end |
50 | | - |
51 | 52 | for con in MOI.get( |
52 | | - optimizer.original_model, |
| 53 | + original_model, |
53 | 54 | MOI.ListOfConstraintIndices{MOI.VariableIndex,MOI.Interval{T}}(), |
54 | 55 | ) |
55 | | - set = MOI.get(optimizer.original_model, MOI.ConstraintSet(), con) |
56 | | - func = MOI.get(optimizer.original_model, MOI.ConstraintFunction(), con) |
| 56 | + set = MOI.get(original_model, MOI.ConstraintSet(), con) |
| 57 | + func = MOI.get(original_model, MOI.ConstraintFunction(), con) |
57 | 58 | lb[func] = set.lower |
58 | 59 | lb_con[func] = con |
59 | 60 | ub[func] = set.upper |
60 | 61 | ub_con[func] = con |
61 | 62 | end |
62 | | - |
63 | | - # for con in MOI.get(optimizer.original_model, MOI.ListOfConstraintIndices{MOI.VariableIndex,MOI.SemiContinuous{T}}()) |
64 | | - # set = MOI.get(optimizer.original_model, MOI.ConstraintSet(), con) |
65 | | - # func = MOI.get(optimizer.original_model, MOI.ConstraintFunction(), con) |
| 63 | + # for con in MOI.get(original_model, MOI.ListOfConstraintIndices{MOI.VariableIndex,MOI.SemiContinuous{T}}()) |
| 64 | + # set = MOI.get(original_model, MOI.ConstraintSet(), con) |
| 65 | + # func = MOI.get(original_model, MOI.ConstraintFunction(), con) |
66 | 66 | # lb[func] = 0 # set.lower |
67 | 67 | # ub[func] = set.upper |
68 | 68 | # end |
69 | | - |
70 | | - # for con in MOI.get(optimizer.original_model, MOI.ListOfConstraintIndices{MOI.VariableIndex,MOI.SemiInteger{T}}()) |
71 | | - # set = MOI.get(optimizer.original_model, MOI.ConstraintSet(), con) |
72 | | - # func = MOI.get(optimizer.original_model, MOI.ConstraintFunction(), con) |
| 69 | + # for con in MOI.get(original_model, MOI.ListOfConstraintIndices{MOI.VariableIndex,MOI.SemiInteger{T}}()) |
| 70 | + # set = MOI.get(original_model, MOI.ConstraintSet(), con) |
| 71 | + # func = MOI.get(original_model, MOI.ConstraintFunction(), con) |
73 | 72 | # lb[func] = 0 #set.lower |
74 | 73 | # ub[func] = set.upper |
75 | 74 | # end |
76 | | - |
77 | 75 | bounds_consistent = true |
78 | | - |
79 | 76 | for con in MOI.get( |
80 | | - optimizer.original_model, |
| 77 | + original_model, |
81 | 78 | MOI.ListOfConstraintIndices{MOI.VariableIndex,MOI.Integer}(), |
82 | 79 | ) |
83 | | - func = MOI.get(optimizer.original_model, MOI.ConstraintFunction(), con) |
84 | | - _lb = get(lb, func, -Inf) |
85 | | - _ub = get(ub, func, Inf) |
| 80 | + func = MOI.get(original_model, MOI.ConstraintFunction(), con) |
| 81 | + _lb, _ub = get(lb, func, typemin(T)), get(ub, func, typemax(T)) |
86 | 82 | if abs(_ub - _lb) < 1 && ceil(_ub) == ceil(_lb) |
87 | 83 | push!( |
88 | | - optimizer.results, |
| 84 | + results, |
89 | 85 | InfeasibilityData( |
90 | | - [con, lb_con[func], ub_con[func]], |
| 86 | + MOI.ConstraintIndex[con, lb_con[func], ub_con[func]], |
91 | 87 | true, |
92 | 88 | IntegralityData(_lb, _ub, MOI.Integer()), |
93 | 89 | ), |
94 | 90 | ) |
95 | 91 | bounds_consistent = false |
96 | 92 | end |
97 | 93 | end |
98 | | - |
99 | 94 | for con in MOI.get( |
100 | | - optimizer.original_model, |
| 95 | + original_model, |
101 | 96 | MOI.ListOfConstraintIndices{MOI.VariableIndex,MOI.ZeroOne}(), |
102 | 97 | ) |
103 | | - func = MOI.get(optimizer.original_model, MOI.ConstraintFunction(), con) |
104 | | - _lb = get(lb, func, -Inf) |
105 | | - _ub = get(ub, func, Inf) |
106 | | - if _lb > 0 && _ub < 1 |
| 98 | + func = MOI.get(original_model, MOI.ConstraintFunction(), con) |
| 99 | + _lb, _ub = get(lb, func, typemin(T)), get(ub, func, typemax(T)) |
| 100 | + if 0 < _lb && _ub < 1 |
107 | 101 | push!( |
108 | | - optimizer.results, |
| 102 | + results, |
109 | 103 | InfeasibilityData( |
110 | | - [con, lb_con[func], ub_con[func]], |
| 104 | + MOI.ConstraintIndex[con, lb_con[func], ub_con[func]], |
111 | 105 | true, |
112 | 106 | IntegralityData(_lb, _ub, MOI.ZeroOne()), |
113 | 107 | ), |
114 | 108 | ) |
115 | 109 | bounds_consistent = false |
116 | 110 | elseif _lb > 1 |
117 | 111 | push!( |
118 | | - optimizer.results, |
| 112 | + results, |
119 | 113 | InfeasibilityData( |
120 | | - [con, lb_con[func]], |
| 114 | + MOI.ConstraintIndex[con, lb_con[func]], |
121 | 115 | true, |
122 | | - IntegralityData(_lb, Inf, MOI.ZeroOne()), |
| 116 | + IntegralityData(_lb, typemax(T), MOI.ZeroOne()), |
123 | 117 | ), |
124 | 118 | ) |
125 | 119 | bounds_consistent = false |
126 | 120 | elseif _ub < 0 |
127 | 121 | push!( |
128 | | - optimizer.results, |
| 122 | + results, |
129 | 123 | InfeasibilityData( |
130 | | - [con, ub_con[func]], |
| 124 | + MOI.ConstraintIndex[con, ub_con[func]], |
131 | 125 | true, |
132 | | - IntegralityData(-Inf, _ub, MOI.ZeroOne()), |
| 126 | + IntegralityData(typemin(T), _ub, MOI.ZeroOne()), |
133 | 127 | ), |
134 | 128 | ) |
135 | 129 | bounds_consistent = false |
136 | 130 | end |
137 | 131 | end |
138 | | - |
139 | 132 | for var in variable_indices |
140 | | - _lb = get(lb, var, -Inf) |
141 | | - _ub = get(ub, var, Inf) |
| 133 | + _lb, _ub = get(lb, var, typemin(T)), get(ub, var, typemax(T)) |
142 | 134 | if _lb > _ub |
143 | 135 | push!( |
144 | | - optimizer.results, |
| 136 | + results, |
145 | 137 | InfeasibilityData( |
146 | | - [lb_con[var], ub_con[var]], |
| 138 | + MOI.ConstraintIndex[lb_con[var], ub_con[var]], |
147 | 139 | true, |
148 | 140 | BoundsData(_lb, _ub), |
149 | 141 | ), |
|
0 commit comments