Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ function dual_attribute end
dual_attribute(attr::MOI.ResultCount) = attr
dual_attribute(attr::MOI.RawStatusString) = attr
dual_attribute(attr::MOI.SolveTimeSec) = attr
dual_attribute(attr::MOI.SimplexIterations) = attr
dual_attribute(attr::MOI.BarrierIterations) = attr
dual_attribute(attr::MOI.NodeCount) = attr
dual_attribute(attr::MOI.RawSolver) = attr

dual_attribute(::MOI.VariableName) = MOI.ConstraintName()

Expand Down
41 changes: 41 additions & 0 deletions test/Tests/test_attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,47 @@ function test_solve_time_sec()
return
end

function test_simplex_iterations()
_test_passthrough_model_attribute(MOI.SimplexIterations(), Int64(7))
return
end

function test_barrier_iterations()
_test_passthrough_model_attribute(MOI.BarrierIterations(), Int64(11))
return
end

function test_node_count()
_test_passthrough_model_attribute(MOI.NodeCount(), Int64(13))
return
end

function test_raw_solver()
# `MockOptimizer.RawSolver` returns the mock itself, so check identity
# rather than going through the generic helper's `set`/`get` round-trip.
@test Dualization.dual_attribute(MOI.RawSolver()) == MOI.RawSolver()
T = Float64
mock = MOI.Utilities.MockOptimizer(
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{T}());
eval_variable_constraint_dual = false,
)
cached = MOI.Utilities.CachingOptimizer(
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{T}()),
MOI.Utilities.MANUAL,
)
dual = Dualization.DualOptimizer(mock)
MOI.Utilities.reset_optimizer(cached, dual)
x = MOI.add_variable(cached)
c = MOI.add_constraint(cached, T(1) * x, MOI.GreaterThan(T(0)))
MOI.set(cached, MOI.ObjectiveSense(), MOI.MIN_SENSE)
MOI.set(cached, MOI.ObjectiveFunction{typeof(T(1) * x)}(), T(1) * x)
MOI.Utilities.attach_optimizer(cached)
MOI.optimize!(cached)
inner_mock = dual.dual_problem.dual_model.model.optimizer
@test MOI.get(cached, MOI.RawSolver()) === inner_mock
return
end

end # module

TestAttributes.runtests()
Loading