I’m trying to model a problem with school transport routes, however, according to the code below, whenever the bus capacity is exceeded by the number of students, the code presents an error. I don’t know which constraint the problem is. Can anybody help me?
function sbrp(C, V, S, c, s, i, time_limit)
# Extract the number of stops
n = length(V)
# Create a JuMP model with CPLEX optimizer
model_sbrp = Model(optimizer_with_attributes(CPLEX.Optimizer,
"CPX_PARAM_TILIM" => time_limit,
"CPX_PARAM_THREADS" => 1))
# Decision Variables
@variable(model_sbrp, x[i in V, j in V, k = 1:n; i != j], Bin) # 1 if bus k travels from i to j, 0 otherwise
@variable(model_sbrp, y[i in V, k = 1:n], Bin) # 1 if bus k visits stop i, 0 otherwise
@variable(model_sbrp, z[i in V, l in S, k = 1:n], Bin) # 1 if student l is picked up by bus k at stop i, 0 otherwise
@variable(model_sbrp, u[i in V], Int) # order of visit to stop i
# Objective Function
@objective(model_sbrp, Min, sum(c[i, j] * x[i, j, k] for i in V, j in V, k in 1:n if i != j))
# Constraints
for i in V
for k in 1:n
@constraint(model_sbrp, sum(x[i, j, k] for j in V if i != j) == sum(x[j, i, k] for j in V if i != j))
@constraint(model_sbrp, sum(x[i, j, k] for j in V if i != j) == y[i, k])
end
end
@constraint(model_sbrp, [i in V, i != 0], sum(y[i, k] for k = 1:n) <= 1)
@constraint(model_sbrp, [l in S, i in V], sum(z[i, l, k] for k = 1:n) <= s[i, l])
@constraint(model_sbrp, [k in 1:n], sum(z[i, l, k] for i in V, l in S) <= C)
@constraint(model_sbrp, [i in V, l in S, k in 1:n], z[i, l, k] <= y[i, k])
@constraint(model_sbrp, [i in 2:n, j in 2:n, k = 1:n; i != j], (u[i] + 1) <= (u[j] + n * (1 - x[i, j, k])))
# Optimization
status = optimize!(model_sbrp)
# Retrieve results
X_values = value.(x)
zIP = objective_value(model_sbrp)
tzIP = MOI.get(model_sbrp, MOI.SolveTimeSec())
LRG = MOI.get(model_sbrp, MOI.RelativeGap())
return (zIP, tzIP, LRG, X_values)
end