Skip to content

Commit f88f78b

Browse files
authored
[Test] add tests for DualObjectiveValue (#2588)
1 parent 5098bd7 commit f88f78b

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed

src/Test/test_solve.jl

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,3 +1879,145 @@ function setup_test(
18791879
)
18801880
return
18811881
end
1882+
1883+
function test_DualObjectiveValue_Min_VariableIndex_GreaterThan(
1884+
model::MOI.ModelLike,
1885+
config::Config{T},
1886+
) where {T}
1887+
@requires _supports(config, MOI.optimize!)
1888+
@requires _supports(config, MOI.DualObjectiveValue)
1889+
x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(T(2)))
1890+
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
1891+
f = T(3) * x
1892+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
1893+
MOI.optimize!(model)
1894+
MOI.get(model, MOI.TerminationStatus()) == config.optimal_status
1895+
MOI.get(model, MOI.DualStatus()) == MOI.FEASIBLE_POINT
1896+
@test (MOI.get(model, MOI.DualObjectiveValue()), T(6), config)
1897+
return
1898+
end
1899+
1900+
function setup_test(
1901+
::typeof(test_DualObjectiveValue_Min_VariableIndex_GreaterThan),
1902+
model::MOIU.MockOptimizer,
1903+
::Config{T},
1904+
) where {T}
1905+
MOIU.set_mock_optimize!(
1906+
model,
1907+
mock -> MOIU.mock_optimize!(
1908+
mock,
1909+
MOI.OPTIMAL,
1910+
(MOI.FEASIBLE_POINT, T[2]),
1911+
MOI.FEASIBLE_POINT,
1912+
(MOI.VariableIndex, MOI.GreaterThan{T}) => T[3],
1913+
),
1914+
)
1915+
return
1916+
end
1917+
1918+
function test_DualObjectiveValue_Max_VariableIndex_LessThan(
1919+
model::MOI.ModelLike,
1920+
config::Config{T},
1921+
) where {T}
1922+
@requires _supports(config, MOI.optimize!)
1923+
@requires _supports(config, MOI.DualObjectiveValue)
1924+
x, _ = MOI.add_constrained_variable(model, MOI.LessThan(T(2)))
1925+
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
1926+
f = T(3) * x
1927+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
1928+
MOI.optimize!(model)
1929+
MOI.get(model, MOI.TerminationStatus()) == config.optimal_status
1930+
MOI.get(model, MOI.DualStatus()) == MOI.FEASIBLE_POINT
1931+
@test (MOI.get(model, MOI.DualObjectiveValue()), T(6), config)
1932+
return
1933+
end
1934+
1935+
function setup_test(
1936+
::typeof(test_DualObjectiveValue_Max_VariableIndex_LessThan),
1937+
model::MOIU.MockOptimizer,
1938+
::Config{T},
1939+
) where {T}
1940+
MOIU.set_mock_optimize!(
1941+
model,
1942+
mock -> MOIU.mock_optimize!(
1943+
mock,
1944+
MOI.OPTIMAL,
1945+
(MOI.FEASIBLE_POINT, T[2]),
1946+
MOI.FEASIBLE_POINT,
1947+
(MOI.VariableIndex, MOI.LessThan{T}) => T[-3],
1948+
),
1949+
)
1950+
return
1951+
end
1952+
1953+
function test_DualObjectiveValue_Min_ScalarAffine_GreaterThan(
1954+
model::MOI.ModelLike,
1955+
config::Config{T},
1956+
) where {T}
1957+
@requires _supports(config, MOI.optimize!)
1958+
@requires _supports(config, MOI.DualObjectiveValue)
1959+
x = MOI.add_variable(model)
1960+
MOI.add_constraint(model, one(T) * x, MOI.GreaterThan(T(2)))
1961+
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
1962+
f = T(3) * x
1963+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
1964+
MOI.optimize!(model)
1965+
MOI.get(model, MOI.TerminationStatus()) == config.optimal_status
1966+
MOI.get(model, MOI.DualStatus()) == MOI.FEASIBLE_POINT
1967+
@test (MOI.get(model, MOI.DualObjectiveValue()), T(6), config)
1968+
return
1969+
end
1970+
1971+
function setup_test(
1972+
::typeof(test_DualObjectiveValue_Min_ScalarAffine_GreaterThan),
1973+
model::MOIU.MockOptimizer,
1974+
::Config{T},
1975+
) where {T}
1976+
MOIU.set_mock_optimize!(
1977+
model,
1978+
mock -> MOIU.mock_optimize!(
1979+
mock,
1980+
MOI.OPTIMAL,
1981+
(MOI.FEASIBLE_POINT, T[2]),
1982+
MOI.FEASIBLE_POINT,
1983+
(MOI.ScalarAffineFunction{T}, MOI.GreaterThan{T}) => T[3],
1984+
),
1985+
)
1986+
return
1987+
end
1988+
1989+
function test_DualObjectiveValue_Max_ScalarAffine_LessThan(
1990+
model::MOI.ModelLike,
1991+
config::Config{T},
1992+
) where {T}
1993+
@requires _supports(config, MOI.optimize!)
1994+
@requires _supports(config, MOI.DualObjectiveValue)
1995+
x = MOI.add_variable(model)
1996+
MOI.add_constraint(model, one(T) * x, MOI.LessThan(T(2)))
1997+
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
1998+
f = T(3) * x
1999+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
2000+
MOI.optimize!(model)
2001+
MOI.get(model, MOI.TerminationStatus()) == config.optimal_status
2002+
MOI.get(model, MOI.DualStatus()) == MOI.FEASIBLE_POINT
2003+
@test (MOI.get(model, MOI.DualObjectiveValue()), T(6), config)
2004+
return
2005+
end
2006+
2007+
function setup_test(
2008+
::typeof(test_DualObjectiveValue_Max_ScalarAffine_LessThan),
2009+
model::MOIU.MockOptimizer,
2010+
::Config{T},
2011+
) where {T}
2012+
MOIU.set_mock_optimize!(
2013+
model,
2014+
mock -> MOIU.mock_optimize!(
2015+
mock,
2016+
MOI.OPTIMAL,
2017+
(MOI.FEASIBLE_POINT, T[2]),
2018+
MOI.FEASIBLE_POINT,
2019+
(MOI.ScalarAffineFunction{T}, MOI.LessThan{T}) => T[-3],
2020+
),
2021+
)
2022+
return
2023+
end

0 commit comments

Comments
 (0)