Hello everyone,
I have some doubts about how to create constraints using a constant value. For example, let’s take the code below.
using JuMP, Gurobi
function solve()
#Decision variables
@variable(model, x[m = 1:30, s = 1:5, w = 1:4, d = 1:7], Bin)
for s = 1:5; w = 1:4; d = 1:7
@constraint(model, sum(x[m,s,w,d] for m in 1:9) >= 3)
end
@objective(model, Min, sum(x[m,s,w,d] for m in 1:30, s = 1:5, w = 1:4, d = 1:7))
#-----------------------------------------------------
println("\n\nsolving mathematical model...")
optimize!(model)
status = termination_status(model)
end
The solver returned the following error:
ERROR: Operation sub_mul
between Matrix{AffExpr}
and Int64
is not allowed. This most often happens when you write a constraint like x >= y
where x
is an array and y
is a constant. Use the broadcast syntax x .- y >= 0
instead.
My doubt is how to use the broadcast syntax, more specifically how to get only a subset of x to build my constraint.
Thank you very much for the support.