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
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, whileConstraintSolver
claims the problem is infeasible. They can't both be right.Updated code:
Package status: