Wikunia / ConstraintSolver.jl

ConstraintSolver in Julia: Blog posts ->
https://opensourc.es/blog/constraint-solver-1
MIT License
136 stars 14 forks source link

Disagreement with Cbc.jl on feasibility #86

Closed metanoid closed 4 years ago

metanoid commented 4 years ago

Follow up to #83

I extended the example slightly - adding new constraints to make the search space smaller. Unfortunately it makes it too small - Cbc is able to find the optimal solution, while ConstraintSolver claims the problem is infeasible. They can't both be right.

Updated code:

using JuMP
using ConstraintSolver
using Cbc # for testing

model = Model()

# Variables
@variable(model, 0 <= inclusion[h = 1:3] <= 1, Int);
@variable(model, 0 <= allocations[h = 1:3, a = 1:3] <= 1, Int);
@variable(model, 0 <= days[h = 1:3, a = 1:3] <= 5, Int);

# Constraints
@constraint(model, must_include[h = 1:3],
    sum(allocations[h,a] for a in 1:3) <= inclusion[h]
);
# at least n
@constraint(model, min_hospitals,
    sum(inclusion[h] for h in 1:3) >= 3
);
# every h must be allocated at most one a
@constraint(model, must_visit[h = 1:3],
    sum(allocations[h,a] for a in 1:3) <= 1
);
# every allocated h must have fewer than 5 days of visits per week
@constraint(model, max_visits[h = 1:3],
    sum(days[h, a] for a in 1:3) <= 5 * inclusion[h]
);
@constraint(model, min_visits[h = 1:3],
    2 * inclusion[h] <= sum(days[h, a] for a in 1:3)
);
# for each a, only have days if allocated
@constraint(model, alloc_days[h = 1:3, a = 1:3],
    days[h,a] <= 5*allocations[h,a]
);
# every aa must be allocated to at most 2 h
@constraint(model, max_allocs[a = 1:3],
    sum(allocations[h,a] for h in 1:3) <= 2
);

benefit = @expression(model,
    sum(days[h,a] * 5
    for h in 1:3, a in 1:3));

@objective(model, Max, benefit);
set_optimizer(model, with_optimizer(Cbc.Optimizer))
optimize!(model) # working
termination_status(model) # OPTIMAL::TerminationStatusCode = 1
set_optimizer(model, with_optimizer(ConstraintSolver.Optimizer))
optimize!(model) # consumes all RAM without finishing
termination_status(model) # INFEASIBLE::TerminationStatusCode = 2

Package status:

pkg> status
    Status `C:\Users\colin37\Documents\Projects\IBS HBS Hospital Allocation\Project.toml`
  [336ed68f] CSV v0.5.23
  [9961bab8] Cbc v0.6.6
  [e0e52ebd] ConstraintSolver v0.1.0 #master (https://github.com/Wikunia/ConstraintSolver.jl)
  [a93c6f00] DataFrames v0.20.0
  [4076af6c] JuMP v0.20.1
  [fdbf4ff8] XLSX v0.5.8
Wikunia commented 4 years ago

Thanks for the issue. It's fixed now in master. Additionally since yesterday I use JuMP v0.21 which means with_optimizer is deprecated now.