# SBRP problem with capacity os bus

**URL:** https://discourse.julialang.org/t/sbrp-problem-with-capacity-os-bus/106719
**Category:** Optimization (Mathematical)
**Tags:** question, jump, constraint
**Created:** [November 25, 2023, 7:53pm UTC](https://discourse.julialang.org/t/sbrp-problem-with-capacity-os-bus/106719 "2023-11-25T19:53:17Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Victor\_Neto](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/victor_neto/32/204390_2.png) [@Victor\_Neto](https://discourse.julialang.org/u/Victor_Neto)
#### Post date: [November 25, 2023, 7:53pm UTC](https://discourse.julialang.org/t/sbrp-problem-with-capacity-os-bus/106719/1 "2023-11-25T19:53:17Z")

</div>

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?

```Julia
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

```

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [November 25, 2023, 10:47pm UTC](https://discourse.julialang.org/t/sbrp-problem-with-capacity-os-bus/106719/2 "2023-11-25T22:47:18Z")

</div>

Hi @Victor_Neto, welcome to the forum.

Can you provide a reproducible example of running the code with data and the error that happens?

If by error you mean infeasibility, then the JuMP documentation has some suggestions for how to debug: [Debugging · JuMP](https://jump.dev/JuMP.jl/stable/tutorials/getting_started/debugging/#Debugging-an-infeasible-model)

---

<div class="post-metadata">

### Author: ![Victor\_Neto](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/victor_neto/32/204390_2.png) [@Victor\_Neto](https://discourse.julialang.org/u/Victor_Neto)
#### Post date: [November 29, 2023, 2:30pm UTC](https://discourse.julialang.org/t/sbrp-problem-with-capacity-os-bus/106719/3 "2023-11-29T14:30:05Z")

</div>

Dear Oscar  
thank you very much for your support.  
I created a new topic: [https://discourse.julialang.org/t/subtour-elimination-constraints/106902](https://discourse.julialang.org/t/subtour-elimination-constraints/106902)  
Best  
Victor

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [November 29, 2023, 7:03pm UTC](https://discourse.julialang.org/t/sbrp-problem-with-capacity-os-bus/106719/4 "2023-11-29T19:03:32Z")

</div>

No need to start a new topic if it’s the same question. We’re not StackOverflow, so you’re free to have a conversation 😄

---

<div class="post-metadata">

### Author: ![Victor\_Neto](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/victor_neto/32/204390_2.png) [@Victor\_Neto](https://discourse.julialang.org/u/Victor_Neto)
#### Post date: [November 29, 2023, 7:18pm UTC](https://discourse.julialang.org/t/sbrp-problem-with-capacity-os-bus/106719/5 "2023-11-29T19:18:17Z")

</div>

this time i formulated the question better kkkk

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [November 29, 2023, 7:23pm UTC](https://discourse.julialang.org/t/sbrp-problem-with-capacity-os-bus/106719/6 "2023-11-29T19:23:11Z")

</div>

Haha it’s not a problem. But you can always edit your original post, or reply with the new formulation. We tend to try and go for a more conversational tone, rather than a question-and-answer where you immediately have to post a coherent and useful question. Anyway, let’s carry on in the other thread.
