Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test empty model solution and improve error msg #447

Merged
merged 3 commits into from
Feb 24, 2021
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
5 changes: 2 additions & 3 deletions src/Algorithm/basic/solveipform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,9 @@ function optimize_with_moi!(optimizer::MoiOptimizer, form::Formulation, result::
sync_solver!(optimizer, form)
nbvars = MOI.get(form.optimizer.inner, MOI.NumberOfVariables())
if nbvars <= 0
@warn "No variable in the formulation. Coluna does not call the solver."
else
MOI.optimize!(getinner(optimizer))
@warn "No variable in the formulation."
end
MOI.optimize!(getinner(optimizer))
termination_status!(result, optimizer)
return
end
Expand Down
2 changes: 1 addition & 1 deletion src/Algorithm/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ get_storages_usage(algo::AbstractAlgorithm, model::AbstractModel) = Tuple{Abstra
Returns algorithm's output.
"""
function run!(algo::AbstractAlgorithm, env::Env, data::AbstractData, input::AbstractInput)::AbstractOutput
error("run! not defined for algorithm $(typeof(algo)), data $(typeof(data)), and input $(typeof(input)).")
error("Cannot apply run! for arguments $(typeof(algo)), $(typeof(data)), $(typeof(input)).")
end

"""
Expand Down
40 changes: 40 additions & 0 deletions test/issues_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,42 @@ function decomposition_with_constant_in_objective()
@test objective_value(model) 307.5 + 2
end

# Issue #424
# - If you try to solve an empty model with Coluna using a SolveIpForm or SolveLpForm
# as top solver, the objective value will be 0.
# - If you try to solve an empty model using TreeSearchAlgorithm, then Coluna will
# throw an error because since there is no decomposition, there is no reformulation
# and TreeSearchAlgorithm must be run on a reformulation.
function solve_empty_model()
coluna = JuMP.optimizer_with_attributes(
Coluna.Optimizer,
"params" => CL.Params(solver = ClA.SolveIpForm()),
"default_optimizer" => GLPK.Optimizer
)
model = BlockModel(coluna)
optimize!(model)
@test JuMP.objective_value(model) == 0

coluna = JuMP.optimizer_with_attributes(
Coluna.Optimizer,
"params" => CL.Params(solver = ClA.SolveLpForm(update_ip_primal_solution = true)),
"default_optimizer" => GLPK.Optimizer
)
model = BlockModel(coluna)
optimize!(model)
@test JuMP.objective_value(model) == 0

coluna = optimizer_with_attributes(
Coluna.Optimizer,
"params" => Coluna.Params(
solver = Coluna.Algorithm.TreeSearchAlgorithm()
),
"default_optimizer" => GLPK.Optimizer
)
model = BlockModel(coluna)
@test_throws ErrorException optimize!(model)
end

function test_issues_fixed()
@testset "no_decomposition" begin
solve_with_no_decomposition()
Expand All @@ -85,6 +121,10 @@ function test_issues_fixed()
@testset "decomposition_with_constant_in_objective" begin
decomposition_with_constant_in_objective()
end

@testset "solve_empty_model" begin
solve_empty_model()
end
end

test_issues_fixed()
8 changes: 0 additions & 8 deletions test/unit/algorithms/algorithm.jl

This file was deleted.

23 changes: 0 additions & 23 deletions test/unit/algorithms/masteripheur.jl

This file was deleted.

6 changes: 0 additions & 6 deletions test/unit/unit_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ include("containers/solsandbounds.jl")
include("MathProg/types.jl")
include("MathProg/variables.jl")

include("algorithms/algorithm.jl")

include("counters.jl")
include("variable.jl")
include("constraint.jl")
Expand All @@ -24,10 +22,6 @@ function unit_tests()
end
end

@testset "algorithm.jl" begin
algorithm_unit_tests()
end

@testset "counters.jl" begin
counters_unit_tests()
end
Expand Down