Skip to content

Commit 85e00fb

Browse files
committed
MOI infeasibility analysis
1 parent e378889 commit 85e00fb

File tree

6 files changed

+298
-139
lines changed

6 files changed

+298
-139
lines changed

src/ModelAnalyzer.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,6 @@ end
216216

217217
include("numerical.jl")
218218
include("feasibility.jl")
219-
# include("infeasibility.jl")
219+
include("infeasibility.jl")
220220

221221
end # module ModelAnalyzer

src/_eval_variables.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) 2025: Joaquim Garcia, Oscar Dowson and contributors
2+
#
3+
# Use of this source code is governed by an MIT-style license that can be found
4+
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
5+
6+
function _eval_variables end
7+
8+
function _eval_variables(value_fn::Function, t::MOI.ScalarAffineTerm)
9+
return t.coefficient * value_fn(t.variable)
10+
end
11+
12+
function _eval_variables(value_fn::Function, t::MOI.ScalarQuadraticTerm)
13+
out = t.coefficient * value_fn(t.variable_1) * value_fn(t.variable_2)
14+
return t.variable_1 == t.variable_2 ? out / 2 : out
15+
end
16+
17+
_eval_variables(value_fn::Function, f::MOI.VariableIndex) = value_fn(f)
18+
19+
function _eval_variables(
20+
value_fn::Function,
21+
f::MOI.ScalarAffineFunction{T},
22+
) where {T}
23+
# TODO: this conversion exists in JuMP, but not in MOI
24+
S = Base.promote_op(value_fn, MOI.VariableIndex)
25+
U = Base.promote_op(*, T, S)
26+
out = convert(U, f.constant)
27+
for t in f.terms
28+
out += _eval_variables(value_fn, t)
29+
end
30+
return out
31+
end

0 commit comments

Comments
 (0)