Skip to content

Commit 2c79007

Browse files
committed
suggestions
1 parent 7b0c0a2 commit 2c79007

File tree

4 files changed

+42
-36
lines changed

4 files changed

+42
-36
lines changed

src/ModelAnalyzer.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ abstract type AbstractData end
1414
abstract type AbstractAnalyzer end
1515

1616
"""
17-
analyze(analyzer::AbstractAnalyzer, model::JuMP.Model; kwargs...)
17+
analyze(analyzer::AbstractAnalyzer, model::JuMP.GenericModel; kwargs...)
1818
1919
Analyze a JuMP model using the specified analyzer.
2020
Depending on the analyzer, this keyword arguments might vary.
@@ -122,6 +122,7 @@ some numerical issues, it can be the coefficient value.
122122
function value(issue::AbstractIssue, ::Nothing)
123123
return value(issue)
124124
end
125+
125126
function value(issue::AbstractIssue, ::MOI.ModelLike)
126127
return value(issue)
127128
end
@@ -134,6 +135,7 @@ Return the variable associated to a particular issue.
134135
function variable(issue::AbstractIssue, ::Nothing)
135136
return variable(issue)
136137
end
138+
137139
function variable(issue::AbstractIssue, ::MOI.ModelLike)
138140
return variable(issue)
139141
end
@@ -146,6 +148,7 @@ Return the variables associated to a particular issue.
146148
function variables(issue::AbstractIssue, ::Nothing)
147149
return variables(issue)
148150
end
151+
149152
function variables(issue::AbstractIssue, ::MOI.ModelLike)
150153
return variables(issue)
151154
end
@@ -158,11 +161,13 @@ Return the constraint associated to a particular issue.
158161
function constraint(issue::AbstractIssue, ::Nothing)
159162
return constraint(issue)
160163
end
164+
161165
function constraint(issue::AbstractIssue, ::MOI.ModelLike)
162166
return constraint(issue)
163167
end
164168

165169
function _verbose_summarize end
170+
166171
function _summarize end
167172

168173
function _name(ref::MOI.VariableIndex, model::MOI.ModelLike)

src/feasibility.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ julia> ModelAnalyzer.summarize(ModelAnalyzer.Feasibility.DualViolation)
8585
```
8686
"""
8787
struct DualViolation <: AbstractFeasibilityIssue
88-
ref::Union{JuMP.ConstraintRef,JuMP.VariableRef}
88+
ref::Union{JuMP.ConstraintRef,JuMP.GenericVariableRef}
8989
violation::Float64
9090
end
9191

@@ -651,7 +651,7 @@ function _name(ref::JuMP.ConstraintRef)
651651
return JuMP.name(ref)
652652
end
653653

654-
function _name(ref::JuMP.VariableRef)
654+
function _name(ref::JuMP.GenericVariableRef)
655655
return JuMP.name(ref)
656656
end
657657

@@ -1062,12 +1062,12 @@ function _dual_point_to_dual_model_ref(
10621062
if haskey(primal_con_dual_var, moi_con)
10631063
vec_vars = primal_con_dual_var[moi_con]
10641064
for (i, moi_var) in enumerate(vec_vars)
1065-
jump_var = JuMP.VariableRef(dual_model, moi_var)
1065+
jump_var = JuMP.GenericVariableRef{T}(dual_model, moi_var)
10661066
dual_point[jump_var] = val[i]
10671067
end
10681068
elseif haskey(primal_con_dual_convar, moi_con)
10691069
moi_convar = primal_con_dual_convar[moi_con]
1070-
jump_var = JuMP.VariableRef(
1070+
jump_var = JuMP.GenericVariableRef{T}(
10711071
dual_model,
10721072
MOI.VariableIndex(moi_convar.value),
10731073
)
@@ -1105,7 +1105,10 @@ function _fix_ret(
11051105
primal_model::JuMP.GenericModel{T},
11061106
dual_con_primal_all,
11071107
) where {T}
1108-
ret = Dict{Union{JuMP.ConstraintRef,JuMP.VariableRef},Union{T,Vector{T}}}()
1108+
ret = Dict{
1109+
Union{JuMP.ConstraintRef,JuMP.GenericVariableRef{T}},
1110+
Union{T,Vector{T}},
1111+
}()
11091112
for (jump_dual_con, val) in pre_ret
11101113
# v is a variable in the dual jump model
11111114
# we need the associated cosntraint in the primal jump model
@@ -1115,7 +1118,7 @@ function _fix_ret(
11151118
# variable in the dual model
11161119
# constraint in the primal model
11171120
jump_primal_var =
1118-
JuMP.VariableRef(primal_model, moi_primal_something)
1121+
JuMP.GenericVariableRef{T}(primal_model, moi_primal_something)
11191122
# ret[jump_primal_var] = T[val]
11201123
ret[jump_primal_var] = val
11211124
else
@@ -1144,7 +1147,7 @@ function _dualize2(
11441147
if mode == JuMP.MANUAL
11451148
error("Dualization does not support solvers in $(mode) mode")
11461149
end
1147-
dual_model = JuMP.Model()
1150+
dual_model = JuMP.GenericModel()
11481151
dual_problem = Dualization.DualProblem(JuMP.backend(dual_model))
11491152
Dualization.dualize(JuMP.backend(model), dual_problem; kwargs...)
11501153
Dualization._fill_obj_dict_with_variables!(dual_model)

src/infeasibility.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ julia> ModelAnalyzer.summarize(ModelAnalyzer.Infeasibility.InfeasibleBounds)
5050
````
5151
"""
5252
struct InfeasibleBounds{T} <: AbstractInfeasibilitylIssue
53-
variable::JuMP.VariableRef
53+
variable::JuMP.GenericVariableRef{T}
5454
lb::T
5555
ub::T
5656
end
@@ -71,7 +71,7 @@ julia> ModelAnalyzer.summarize(
7171
```
7272
"""
7373
struct InfeasibleIntegrality{T} <: AbstractInfeasibilitylIssue
74-
variable::JuMP.VariableRef
74+
variable::JuMP.GenericVariableRef{T}
7575
lb::T
7676
ub::T
7777
set::Union{MOI.Integer,MOI.ZeroOne}#, MOI.Semicontinuous{T}, MOI.Semiinteger{T}}
@@ -147,7 +147,7 @@ function ModelAnalyzer.analyze(
147147
) where {T}
148148
out = Data()
149149

150-
variables = Dict{JuMP.VariableRef,Interval{T}}()
150+
variables = Dict{JuMP.GenericVariableRef{T},Interval{T}}()
151151

152152
# first layer of infeasibility analysis is bounds consistency
153153
bounds_consistent = true
@@ -196,7 +196,7 @@ function ModelAnalyzer.analyze(
196196
# second layer of infeasibility analysis is constraint range analysis
197197
range_consistent = true
198198
for (F, S) in JuMP.list_of_constraint_types(model)
199-
F != JuMP.GenericAffExpr{T,JuMP.VariableRef} && continue
199+
F != JuMP.GenericAffExpr{T,JuMP.GenericVariableRef{T}} && continue
200200
# TODO: handle quadratics
201201
!(S in (MOI.EqualTo{T}, MOI.LessThan{T}, MOI.GreaterThan{T})) &&
202202
continue

src/jump.jl

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
import JuMP
2-
3-
# struct JuMPData{T<:AbstractData} <: ModelAnalyzer.AbstractData
4-
# data::T
5-
# model::JuMP.Model
6-
# end
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.
75

8-
# struct JuMPIssue{T<:AbstractIssue} <: ModelAnalyzer.AbstractIssue
9-
# issue::T
10-
# model::JuMP.Model
11-
# end
6+
import JuMP
127

138
function ModelAnalyzer.analyze(
149
analyzer::T,
15-
model::JuMP.Model;
10+
model::JuMP.GenericModel;
1611
kwargs...,
1712
) where {T<:ModelAnalyzer.AbstractAnalyzer}
1813
moi_model = JuMP.backend(model)
@@ -21,16 +16,19 @@ function ModelAnalyzer.analyze(
2116
return result
2217
end
2318

24-
function ModelAnalyzer._name(ref::MOI.VariableIndex, model::JuMP.Model)
25-
jump_ref = JuMP.VariableRef(model, ref)
19+
function ModelAnalyzer._name(
20+
ref::MOI.VariableIndex,
21+
model::JuMP.GenericModel{T},
22+
) where {T}
23+
jump_ref = JuMP.GenericVariableRef{T}(model, ref)
2624
name = JuMP.name(jump_ref)
2725
if !isempty(name)
2826
return name
2927
end
3028
return "$jump_ref"
3129
end
3230

33-
function ModelAnalyzer._name(ref::MOI.ConstraintIndex, model::JuMP.Model)
31+
function ModelAnalyzer._name(ref::MOI.ConstraintIndex, model::JuMP.GenericModel)
3432
jump_ref = JuMP.constraint_ref_with_index(model, ref)
3533
name = JuMP.name(jump_ref)
3634
if !isempty(name)
@@ -40,39 +38,39 @@ function ModelAnalyzer._name(ref::MOI.ConstraintIndex, model::JuMP.Model)
4038
end
4139

4240
"""
43-
variable(issue::ModelAnalyzer.AbstractIssue, model::JuMP.Model)
41+
variable(issue::ModelAnalyzer.AbstractIssue, model::JuMP.GenericModel)
4442
4543
Return the **JuMP** variable reference associated to a particular issue.
4644
"""
4745
function ModelAnalyzer.variable(
4846
issue::ModelAnalyzer.AbstractIssue,
49-
model::JuMP.Model,
50-
)
47+
model::JuMP.GenericModel{T},
48+
) where {T}
5149
ref = ModelAnalyzer.variable(issue)
52-
return JuMP.VariableRef(model, ref)
50+
return JuMP.GenericVariableRef{T}(model, ref)
5351
end
5452

5553
"""
56-
variables(issue::ModelAnalyzer.AbstractIssue, model::JuMP.Model)
54+
variables(issue::ModelAnalyzer.AbstractIssue, model::JuMP.GenericModel)
5755
5856
Return the **JuMP** variable references associated to a particular issue.
5957
"""
6058
function ModelAnalyzer.variables(
6159
issue::ModelAnalyzer.AbstractIssue,
62-
model::JuMP.Model,
63-
)
60+
model::JuMP.GenericModel{T},
61+
) where {T}
6462
refs = ModelAnalyzer.variables(issue)
65-
return JuMP.VariableRef.(model, refs)
63+
return JuMP.GenericVariableRef{T}.(model, refs)
6664
end
6765

6866
"""
69-
constraint(issue::ModelAnalyzer.AbstractIssue, model::JuMP.Model)
67+
constraint(issue::ModelAnalyzer.AbstractIssue, model::JuMP.GenericModel)
7068
7169
Return the **JuMP** constraint reference associated to a particular issue.
7270
"""
7371
function ModelAnalyzer.constraint(
7472
issue::ModelAnalyzer.AbstractIssue,
75-
model::JuMP.Model,
73+
model::JuMP.GenericModel,
7674
)
7775
ref = ModelAnalyzer.constraint(issue)
7876
return JuMP.constraint_ref_with_index(model, ref)

0 commit comments

Comments
 (0)