55
66module ModelAnalyzer
77
8+ import MathOptInterface as MOI
9+
810abstract type AbstractIssue end
911
1012abstract type AbstractData end
1113
1214abstract type AbstractAnalyzer end
1315
1416"""
15- analyze(analyzer::AbstractAnalyzer, model::JuMP.Model ; kwargs...)
17+ analyze(analyzer::AbstractAnalyzer, model::JuMP.GenericModel ; kwargs...)
1618
1719Analyze a JuMP model using the specified analyzer.
1820Depending on the analyzer, this keyword arguments might vary.
@@ -25,10 +27,12 @@ See [`summarize`](@ref), [`list_of_issues`](@ref), and
2527function analyze end
2628
2729"""
28- summarize([io::IO,] AbstractData; verbose = true, max_issues = 10, kwargs...)
30+ summarize([io::IO,] AbstractData; model = nothing, verbose = true, max_issues = 10, kwargs...)
2931
3032Print a summary of the analysis results contained in `AbstractData` to the
3133specified IO stream. If no IO stream is provided, it defaults to `stdout`.
34+ The model that led to the issue can be provided to `model`, it will be
35+ used to generate the name of variables and constraints in the issue summary.
3236The `verbose` flag controls whether to print detailed information about each
3337issue (if `true`) or a concise summary (if `false`). The `max_issues` argument
3438controls the maximum number of issues to display in the summary. If there are
@@ -41,9 +45,11 @@ be a subtype of `AbstractIssue`). In the verbose case it will provide a text
4145explaning the issue. In the non-verbose case it will provide just the issue
4246name.
4347
44- summarize([io::IO,] issue::AbstractIssue; verbose = true)
48+ summarize([io::IO,] issue::AbstractIssue; model = nothing, verbose = true)
4549
4650This variant allows summarizing a single issue instance of type `AbstractIssue`.
51+ The model that led to the issue can be provided to `model`, it will be
52+ used to generate the name of variables and constraints in the issue summary.
4753"""
4854function summarize end
4955
@@ -76,11 +82,16 @@ function summarize(::Type{T}; kwargs...) where {T<:AbstractIssue}
7682 return summarize (stdout , T; kwargs... )
7783end
7884
79- function summarize (io:: IO , issue:: AbstractIssue ; verbose = true )
85+ function summarize (
86+ io:: IO ,
87+ issue:: AbstractIssue ;
88+ model = nothing ,
89+ verbose = true ,
90+ )
8091 if verbose
81- return _verbose_summarize (io, issue)
92+ return _verbose_summarize (io, issue, model )
8293 else
83- return _summarize (io, issue)
94+ return _summarize (io, issue, model )
8495 end
8596end
8697
@@ -93,6 +104,7 @@ const DEFAULT_MAX_ISSUES = 10
93104function summarize (
94105 io:: IO ,
95106 issues:: Vector{T} ;
107+ model = nothing ,
96108 verbose = true ,
97109 max_issues = DEFAULT_MAX_ISSUES,
98110) where {T<: AbstractIssue }
@@ -110,7 +122,7 @@ function summarize(
110122 end
111123 for issue in first (issues, max_issues)
112124 print (io, " * " )
113- summarize (io, issue, verbose = verbose)
125+ summarize (io, issue, verbose = verbose, model = model )
114126 print (io, " \n " )
115127 end
116128 return
@@ -124,11 +136,91 @@ function summarize(data::AbstractData; kwargs...)
124136 return summarize (stdout , data; kwargs... )
125137end
126138
139+ """
140+ value(issue::AbstractIssue)
141+
142+ Return the value associated to a particular issue. The value is a number
143+ with a different meaning depending on the type of issue. For example, for
144+ some numerical issues, it can be the coefficient value.
145+ """
146+ function value end
147+
148+ """
149+ values(issue::AbstractIssue)
150+
151+ Return the values associated to a particular issue.
152+ """
153+ function values end
154+
155+ """
156+ variable(issue::AbstractIssue)
157+
158+ Return the variable associated to a particular issue.
159+ """
160+ function variable (issue:: AbstractIssue , :: MOI.ModelLike )
161+ return variable (issue)
162+ end
163+
164+ """
165+ variables(issue::AbstractIssue)
166+
167+ Return the variables associated to a particular issue.
168+ """
169+ function variables (issue:: AbstractIssue , :: MOI.ModelLike )
170+ return variables (issue)
171+ end
172+
173+ """
174+ constraint(issue::AbstractIssue)
175+
176+ Return the constraint associated to a particular issue.
177+ """
178+ function constraint (issue:: AbstractIssue , :: MOI.ModelLike )
179+ return constraint (issue)
180+ end
181+
182+ """
183+ constraints(issue::AbstractIssue)
184+
185+ Return the constraints associated to a particular issue.
186+ """
187+ function constraints (issue:: AbstractIssue , :: MOI.ModelLike )
188+ return constraints (issue)
189+ end
190+
191+ """
192+ set(issue::AbstractIssue)
193+
194+ Return the set associated to a particular issue.
195+ """
196+ function set end
197+
127198function _verbose_summarize end
199+
128200function _summarize end
129201
202+ function _name (ref:: MOI.VariableIndex , model:: MOI.ModelLike )
203+ name = MOI. get (model, MOI. VariableName (), ref)
204+ if ! isempty (name)
205+ return name
206+ end
207+ return " $ref "
208+ end
209+
210+ function _name (ref:: MOI.ConstraintIndex , model:: MOI.ModelLike )
211+ name = MOI. get (model, MOI. ConstraintName (), ref)
212+ if ! isempty (name)
213+ return name
214+ end
215+ return " $ref "
216+ end
217+
218+ function _name (ref, :: Nothing )
219+ return " $ref "
220+ end
221+
130222include (" numerical.jl" )
131223include (" feasibility.jl" )
132224include (" infeasibility.jl" )
133225
134- end
226+ end # module ModelAnalyzer
0 commit comments