From 0e08b506c4a12b07df2bfc91172e8e46a9f7e147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Tue, 16 Jun 2026 23:52:39 +0200 Subject: [PATCH] Add support for more attributes --- src/attributes.jl | 4 ++++ test/Tests/test_attributes.jl | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/attributes.jl b/src/attributes.jl index 59b3833..2392648 100644 --- a/src/attributes.jl +++ b/src/attributes.jl @@ -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() diff --git a/test/Tests/test_attributes.jl b/test/Tests/test_attributes.jl index 4b2dc26..3a93f4c 100644 --- a/test/Tests/test_attributes.jl +++ b/test/Tests/test_attributes.jl @@ -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()