Skip to content
This repository has been archived by the owner on Sep 10, 2019. It is now read-only.

Commit

Permalink
Make InstanceManager pass contlinear tests in every state/mode
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Feb 6, 2018
1 parent 0e0c8ae commit 9dadc91
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ function Base.setindex!(idxmap::IndexMap, ci1::MOI.ConstraintIndex{F, S}, ci2::M
Base.setindex!(idxmap.conmap, ci1, ci2)
end

Base.delete!(idxmap::IndexMap, vi::MOI.VariableIndex) = delete!(idxmap.varmap, vi)
Base.delete!(idxmap::IndexMap, ci::MOI.ConstraintIndex) = delete!(idxmap.conmap, ci)

Base.keys(idxmap::IndexMap) = Iterators.flatten((keys(idxmap.varmap), keys(idxmap.conmap)))

"""
Expand Down
6 changes: 3 additions & 3 deletions src/instancemanager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ function MOI.delete!(m::InstanceManager, index::MOI.Index)
end
@assert MOI.candelete(m, index)
if m.state == AttachedSolver
MOI.delete!(m.solver, m.instancetosolvermap[cindex])
delete!(m.solvertoinstancemap, m.instancetosolvermap[cindex])
delete!(m.instancetosolvermap, cindex)
MOI.delete!(m.solver, m.instancetosolvermap[index])
delete!(m.solvertoinstancemap, m.instancetosolvermap[index])
delete!(m.instancetosolvermap, index)
end
MOI.delete!(m.instance, index)
end
Expand Down
28 changes: 19 additions & 9 deletions test/instancemanager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,27 @@ end

end

@testset "InstanceManager constructor without solver in $mode mode" for mode in (MOIU.Manual, MOIU.Automatic)
m = MOIU.InstanceManager(InstanceForManager{Float64}(), mode)
@test MOIU.mode(m) == mode
config = MOIT.TestConfig(solve=false)
MOIT.contlineartest(m, config)
end

@testset "InstanceManager constructor with solver" begin
s = MOIU.MockSolverInstance(InstanceForMock{Float64}())
m = MOIU.InstanceManager(InstanceForManager{Float64}(), s)
@test MOI.isempty(m)
@test MOIU.state(m) == MOIU.EmptySolver
@test MOIU.mode(m) == MOIU.Automatic
config = MOIT.TestConfig(solve=false)
MOIT.contlineartest(m, config)
end

for state in (MOIU.NoSolver, MOIU.EmptySolver, MOIU.AttachedSolver)
@testset "Optimization tests in state $state and mode $mode" for mode in (MOIU.Manual, MOIU.Automatic)
m = MOIU.InstanceManager(InstanceForManager{Float64}(), mode)
if state != MOIU.NoSolver
s = MOIU.MockSolverInstance(InstanceForMock{Float64}())
MOIU.resetsolver!(m, s)
if state == MOIU.AttachedSolver
MOIU.attachsolver!(m)
end
end
@test MOIU.state(m) == state
@test MOIU.mode(m) == mode
config = MOIT.TestConfig(solve=false)
MOIT.contlineartest(m, config)
end
end

0 comments on commit 9dadc91

Please sign in to comment.