Skip to content

Commit f0d70fa

Browse files
committed
Add query tools
1 parent fc09db0 commit f0d70fa

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

src/feasibility.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ struct PrimalViolation <: AbstractFeasibilityIssue
6666
violation::Float64
6767
end
6868

69+
ModelAnalyzer.constraint(issue::PrimalViolation) = issue.ref
70+
71+
ModelAnalyzer.value(issue::PrimalViolation) = issue.violation
72+
6973
"""
7074
DualConstraintViolation <: AbstractFeasibilityIssue
7175
@@ -83,6 +87,10 @@ struct DualConstraintViolation <: AbstractFeasibilityIssue
8387
violation::Float64
8488
end
8589

90+
ModelAnalyzer.variable(issue::DualConstraintViolation) = issue.ref
91+
92+
ModelAnalyzer.value(issue::DualConstraintViolation) = issue.violation
93+
8694
"""
8795
DualConstrainedVariableViolation <: AbstractFeasibilityIssue
8896
@@ -101,6 +109,10 @@ struct DualConstrainedVariableViolation <: AbstractFeasibilityIssue
101109
violation::Float64
102110
end
103111

112+
ModelAnalyzer.constraint(issue::DualConstrainedVariableViolation) = issue.ref
113+
114+
ModelAnalyzer.value(issue::DualConstrainedVariableViolation) = issue.violation
115+
104116
"""
105117
ComplemetarityViolation <: AbstractFeasibilityIssue
106118
@@ -119,6 +131,10 @@ struct ComplemetarityViolation <: AbstractFeasibilityIssue
119131
violation::Float64
120132
end
121133

134+
ModelAnalyzer.constraint(issue::ComplemetarityViolation) = issue.ref
135+
136+
ModelAnalyzer.value(issue::ComplemetarityViolation) = issue.violation
137+
122138
"""
123139
DualObjectiveMismatch <: AbstractFeasibilityIssue
124140
@@ -136,6 +152,8 @@ struct DualObjectiveMismatch <: AbstractFeasibilityIssue
136152
obj_solver::Float64
137153
end
138154

155+
# ModelAnalyzer.values(issue::DualObjectiveMismatch) = [issue.obj, issue.obj_solver]
156+
139157
"""
140158
PrimalObjectiveMismatch <: AbstractFeasibilityIssue
141159
@@ -153,6 +171,8 @@ struct PrimalObjectiveMismatch <: AbstractFeasibilityIssue
153171
obj_solver::Float64
154172
end
155173

174+
# ModelAnalyzer.values(issue::PrimalObjectiveMismatch) = [issue.obj, issue.obj_solver]
175+
156176
"""
157177
PrimalDualMismatch <: AbstractFeasibilityIssue
158178
@@ -170,6 +190,8 @@ struct PrimalDualMismatch <: AbstractFeasibilityIssue
170190
dual::Float64
171191
end
172192

193+
ModelAnalyzer.values(issue::PrimalDualMismatch) = [issue.primal, issue.dual]
194+
173195
"""
174196
PrimalDualSolverMismatch <: AbstractFeasibilityIssue
175197
@@ -187,6 +209,8 @@ struct PrimalDualSolverMismatch <: AbstractFeasibilityIssue
187209
dual::Float64
188210
end
189211

212+
# ModelAnalyzer.values(issue::PrimalDualSolverMismatch) = [issue.primal, issue.dual]
213+
190214
"""
191215
Data
192216

test/feasibility.jl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ function test_only_bounds()
9292
JuMP.index(LowerBoundRef(x)),
9393
1.0,
9494
)
95+
@test ModelAnalyzer.constraint(ret[], model) == LowerBoundRef(x)
96+
@test ModelAnalyzer.value(ret[]) == 1.0
9597
ret = ModelAnalyzer.list_of_issues(
9698
data,
9799
ModelAnalyzer.Feasibility.ComplemetarityViolation,
@@ -100,11 +102,14 @@ function test_only_bounds()
100102
JuMP.index(LowerBoundRef(x)),
101103
-1.0,
102104
)
105+
@test ModelAnalyzer.constraint(ret[], model) == LowerBoundRef(x)
106+
@test ModelAnalyzer.value(ret[]) == -1.0
103107
ret = ModelAnalyzer.list_of_issues(
104108
data,
105109
ModelAnalyzer.Feasibility.PrimalDualMismatch,
106110
)
107111
@test ret[] == ModelAnalyzer.Feasibility.PrimalDualMismatch(-1.0, 0.0)
112+
# @test ModelAnalyzer.values(ret[]) == [-1.0, 0.0]
108113

109114
data = ModelAnalyzer.analyze(
110115
ModelAnalyzer.Feasibility.Analyzer(),
@@ -125,6 +130,8 @@ function test_only_bounds()
125130
JuMP.index(LowerBoundRef(x)),
126131
1.0,
127132
)
133+
@test ModelAnalyzer.constraint(ret[], model) == LowerBoundRef(x)
134+
@test ModelAnalyzer.value(ret[]) == 1.0
128135
ret = ModelAnalyzer.list_of_issues(
129136
data,
130137
ModelAnalyzer.Feasibility.PrimalDualMismatch,
@@ -150,6 +157,8 @@ function test_only_bounds()
150157
)
151158
@test ret[] ==
152159
ModelAnalyzer.Feasibility.DualConstraintViolation(JuMP.index(x), 2.0)
160+
@test ModelAnalyzer.variable(ret[], model) == x
161+
@test ModelAnalyzer.value(ret[]) == 2.0
153162
ret = ModelAnalyzer.list_of_issues(
154163
data,
155164
ModelAnalyzer.Feasibility.DualConstrainedVariableViolation,
@@ -158,6 +167,8 @@ function test_only_bounds()
158167
JuMP.index(LowerBoundRef(x)),
159168
1.0,
160169
)
170+
@test ModelAnalyzer.constraint(ret[], model) == LowerBoundRef(x)
171+
@test ModelAnalyzer.value(ret[]) == 1.0
161172
ret = ModelAnalyzer.list_of_issues(
162173
data,
163174
ModelAnalyzer.Feasibility.ComplemetarityViolation,
@@ -166,6 +177,8 @@ function test_only_bounds()
166177
JuMP.index(LowerBoundRef(x)),
167178
-1.0,
168179
)
180+
@test ModelAnalyzer.constraint(ret[], model) == LowerBoundRef(x)
181+
@test ModelAnalyzer.value(ret[]) == -1.0
169182
ret = ModelAnalyzer.list_of_issues(
170183
data,
171184
ModelAnalyzer.Feasibility.PrimalDualMismatch,
@@ -213,12 +226,16 @@ function test_no_lb()
213226
ModelAnalyzer.Feasibility.PrimalViolation,
214227
)
215228
@test ret[] == ModelAnalyzer.Feasibility.PrimalViolation(JuMP.index(c), 1.0)
229+
@test ModelAnalyzer.constraint(ret[], model) == c
230+
@test ModelAnalyzer.value(ret[]) == 1.0
216231
ret = ModelAnalyzer.list_of_issues(
217232
data,
218233
ModelAnalyzer.Feasibility.ComplemetarityViolation,
219234
)
220235
@test ret[] ==
221236
ModelAnalyzer.Feasibility.ComplemetarityViolation(JuMP.index(c), -1.0)
237+
@test ModelAnalyzer.constraint(ret[], model) == c
238+
@test ModelAnalyzer.value(ret[]) == -1.0
222239
ret = ModelAnalyzer.list_of_issues(
223240
data,
224241
ModelAnalyzer.Feasibility.PrimalDualMismatch,
@@ -242,6 +259,8 @@ function test_no_lb()
242259
)
243260
@test ret[] ==
244261
ModelAnalyzer.Feasibility.ComplemetarityViolation(JuMP.index(c), 1.0)
262+
@test ModelAnalyzer.constraint(ret[], model) == c
263+
@test ModelAnalyzer.value(ret[]) == 1.0
245264
ret = ModelAnalyzer.list_of_issues(
246265
data,
247266
ModelAnalyzer.Feasibility.PrimalDualMismatch,
@@ -267,6 +286,8 @@ function test_no_lb()
267286
)
268287
@test ret[] ==
269288
ModelAnalyzer.Feasibility.DualConstraintViolation(JuMP.index(x), 2.0)
289+
@test ModelAnalyzer.variable(ret[], model) == x
290+
@test ModelAnalyzer.value(ret[]) == 2.0
270291
ret = ModelAnalyzer.list_of_issues(
271292
data,
272293
ModelAnalyzer.Feasibility.DualConstrainedVariableViolation,
@@ -275,12 +296,16 @@ function test_no_lb()
275296
JuMP.index(c),
276297
1.0,
277298
)
299+
@test ModelAnalyzer.constraint(ret[], model) == c
300+
@test ModelAnalyzer.value(ret[]) == 1.0
278301
ret = ModelAnalyzer.list_of_issues(
279302
data,
280303
ModelAnalyzer.Feasibility.ComplemetarityViolation,
281304
)
282305
@test ret[] ==
283306
ModelAnalyzer.Feasibility.ComplemetarityViolation(JuMP.index(c), -1.0)
307+
@test ModelAnalyzer.constraint(ret[], model) == c
308+
@test ModelAnalyzer.value(ret[]) == -1.0
284309
ret = ModelAnalyzer.list_of_issues(
285310
data,
286311
ModelAnalyzer.Feasibility.PrimalDualMismatch,
@@ -329,6 +354,8 @@ function test_lb0()
329354
)
330355
@test ret[] ==
331356
ModelAnalyzer.Feasibility.DualConstraintViolation(JuMP.index(x), 2.3)
357+
@test ModelAnalyzer.variable(ret[], model) == x
358+
@test ModelAnalyzer.value(ret[]) == 2.3
332359

333360
data = ModelAnalyzer.analyze(
334361
ModelAnalyzer.Feasibility.Analyzer(),
@@ -351,6 +378,8 @@ function test_lb0()
351378
)
352379
@test ret[] ==
353380
ModelAnalyzer.Feasibility.DualConstraintViolation(JuMP.index(x), 4.3)
381+
@test ModelAnalyzer.variable(ret[], model) == x
382+
@test ModelAnalyzer.value(ret[]) == 4.3
354383
ret = ModelAnalyzer.list_of_issues(
355384
data,
356385
ModelAnalyzer.Feasibility.DualConstrainedVariableViolation,
@@ -359,6 +388,9 @@ function test_lb0()
359388
JuMP.index(c),
360389
3.3,
361390
)
391+
@test ModelAnalyzer.constraint(ret[], model) == c
392+
@test ModelAnalyzer.value(ret[]) == 3.3
393+
return
362394
end
363395

364396
function test_lb2()
@@ -398,6 +430,8 @@ function test_lb2()
398430
)
399431
@test ret[] ==
400432
ModelAnalyzer.Feasibility.DualConstraintViolation(JuMP.index(x), 2.3)
433+
@test ModelAnalyzer.variable(ret[], model) == x
434+
@test ModelAnalyzer.value(ret[]) == 2.3
401435

402436
data = ModelAnalyzer.analyze(
403437
ModelAnalyzer.Feasibility.Analyzer(),
@@ -422,6 +456,8 @@ function test_lb2()
422456
JuMP.index(c),
423457
3.3,
424458
)
459+
@test ModelAnalyzer.constraint(ret[], model) == c
460+
@test ModelAnalyzer.value(ret[]) == 3.3
425461

426462
data = ModelAnalyzer.analyze(
427463
ModelAnalyzer.Feasibility.Analyzer(),
@@ -446,10 +482,14 @@ function test_lb2()
446482
JuMP.index(c),
447483
3.3,
448484
)
485+
@test ModelAnalyzer.constraint(ret[1], model) == c
486+
@test ModelAnalyzer.value(ret[1]) == 3.3
449487
@test ret[2] == ModelAnalyzer.Feasibility.DualConstrainedVariableViolation(
450488
JuMP.index(LowerBoundRef(x)),
451489
1.0,
452490
)
491+
@test ModelAnalyzer.constraint(ret[2], model) == LowerBoundRef(x)
492+
@test ModelAnalyzer.value(ret[2]) == 1.0
453493

454494
data = ModelAnalyzer.analyze(
455495
ModelAnalyzer.Feasibility.Analyzer(),
@@ -470,6 +510,8 @@ function test_lb2()
470510
JuMP.index(c),
471511
3.3,
472512
)
513+
@test ModelAnalyzer.constraint(ret[], model) == c
514+
@test ModelAnalyzer.value(ret[]) == 3.3
473515
return
474516
end
475517

@@ -613,6 +655,8 @@ function test_analyse_no_opt()
613655
@test length(list) == 1
614656
ret = ModelAnalyzer.list_of_issues(data, list[1])
615657
@test ret[] == ModelAnalyzer.Feasibility.PrimalViolation(JuMP.index(c), 1.0)
658+
@test ModelAnalyzer.constraint(ret[], model) == c
659+
@test ModelAnalyzer.value(ret[]) == 1.0
616660

617661
data = ModelAnalyzer.analyze(
618662
ModelAnalyzer.Feasibility.Analyzer(),
@@ -625,6 +669,8 @@ function test_analyse_no_opt()
625669
ret = ModelAnalyzer.list_of_issues(data, list[1])
626670
@test ret[1] ==
627671
ModelAnalyzer.Feasibility.ComplemetarityViolation(JuMP.index(c), 1.0)
672+
@test ModelAnalyzer.constraint(ret[1], model) == c
673+
@test ModelAnalyzer.value(ret[1]) == 1.0
628674
ret = ModelAnalyzer.list_of_issues(data, list[2])
629675
@test ret[1] == ModelAnalyzer.Feasibility.PrimalDualMismatch(1.0, 0.0)
630676

@@ -648,12 +694,18 @@ function test_analyse_no_opt()
648694
ret = ModelAnalyzer.list_of_issues(data, list[1])
649695
@test ret[1] ==
650696
ModelAnalyzer.Feasibility.PrimalViolation(JuMP.index(c), 1.0)
697+
@test ModelAnalyzer.constraint(ret[1], model) == c
698+
@test ModelAnalyzer.value(ret[1]) == 1.0
651699
ret = ModelAnalyzer.list_of_issues(data, list[2])
652700
@test ret[1] ==
653701
ModelAnalyzer.Feasibility.DualConstraintViolation(JuMP.index(x), 1.0)
702+
@test ModelAnalyzer.variable(ret[1], model) == x
703+
@test ModelAnalyzer.value(ret[1]) == 1.0
654704
ret = ModelAnalyzer.list_of_issues(data, list[3])
655705
@test ret[1] ==
656706
ModelAnalyzer.Feasibility.ComplemetarityViolation(JuMP.index(c), -2.0)
707+
@test ModelAnalyzer.constraint(ret[1], model) == c
708+
@test ModelAnalyzer.value(ret[1]) == -2.0
657709
ret = ModelAnalyzer.list_of_issues(data, list[4])
658710
@test ret[1] == ModelAnalyzer.Feasibility.PrimalDualMismatch(-1.0, 0.0)
659711

0 commit comments

Comments
 (0)