Skip to content
This repository was archived by the owner on Jun 14, 2020. It is now read-only.

Commit 4e13722

Browse files
authored
Implement model printing (#80)
* Implement model printing * Simplify testing
1 parent 812d334 commit 4e13722

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/LinQuadOptInterface.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ end
199199
# Abstract + macro
200200
abstract type LinQuadOptimizer <: MOI.AbstractOptimizer end
201201

202+
function Base.show(io::IO, model::LinQuadOptimizer)
203+
println(io, "A LinQuadOptInterface model with backend:")
204+
Base.show(io, model.inner)
205+
return
206+
end
207+
202208
@enum(VariableType, Continuous, Binary, Integer, Semiinteger, Semicontinuous)
203209

204210
macro LinQuadOptimizerBase(inner_model_type=Any)

src/mockoptimizer.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ mutable struct MockLinQuadModel # <: LinQuadOptInterface.LinQuadOptimizer
8080
end
8181
end
8282

83+
function Base.show(io::IO, model::MockLinQuadModel)
84+
println(io, "MockLinQuadModel")
85+
println(io, " Sense $(model.sense)")
86+
println(io, " Variables $(length(model.lb))")
87+
println(io, " Constraints $(length(model.b))")
88+
return
89+
end
90+
8391
"""
8492
Solution builder to create solutions for the mock solver.
8593
Should be called inside `MOI.optimize!(model::LinQuadOptimizer)` right before changing signs. This means that these solutions replicate the low-level solver output.

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ end
2020
@testset "LinQuadOptInterface" begin
2121
solver = LQOI.MockLinQuadOptimizer()
2222

23+
@testset "Printing" begin
24+
@test sprint(show, solver) == "A LinQuadOptInterface model with " *
25+
"backend:\nMockLinQuadModel\n Sense minimize\n " *
26+
"Variables 0\n Constraints 0\n"
27+
end
28+
2329
config = MOIT.TestConfig(solve=false)
2430

2531
@testset "Unit Tests" begin

0 commit comments

Comments
 (0)