# Indicator constraints with quadratic terms may have bugs?

**URL:** https://discourse.julialang.org/t/indicator-constraints-with-quadratic-terms-may-have-bugs/80516
**Category:** Optimization (Mathematical)
**Created:** [May 5, 2022, 12:53am UTC](https://discourse.julialang.org/t/indicator-constraints-with-quadratic-terms-may-have-bugs/80516 "2022-05-05T00:53:37Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![iiitr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iiitr/32/24586_2.png) [@iiitr](https://discourse.julialang.org/u/iiitr)
#### Post date: [May 5, 2022, 12:53am UTC](https://discourse.julialang.org/t/indicator-constraints-with-quadratic-terms-may-have-bugs/80516/1 "2022-05-05T00:53:38Z")

</div>

When I use the indicator constraint, I find that it sometimes causes the model to be infeasible, but I can solve the model when I set a feasible solution as a constraint.

I know that the indicator can only contain linear constraints, so I create a variable to represent the quadratic terms in it. juMP doesn’t report errors, but sometimes it doesn’t work and I’m confused.

My code is as follow:

```julia
indt = @variable(model, [1:pipeNum, 1:Horizon], binary=true)

for ij in setdiff(1:pipeNum, ijGC), t in 1:Horizon
    x_M_t_avg = (x_M_t[ij, 1, t] + x_M_t[ij, 2, t]) / 2
    i, j = idx2ft(GS_fnode, GS_tnode, ij)
    term1 = @variable(model)
    term2 = @variable(model)
    term3 = @variable(model)
    @constraints(model, begin
        term1 == x_M_t_avg^2
        term2 == x_p_t[i, t]^2
        term3 == x_p_t[j, t]^2
    end)
    @constraints(model, begin
        indt[ij, t] => {x_p_t[i, t] - x_p_t[j, t] >= 0}
        indt[ij, t] => {x_M_t_avg >= 0}
        indt[ij, t] => {term1 == GS_K2[ij] .* (term2 - term3)}

        !indt[ij, t] => {x_p_t[i, t] - x_p_t[j, t] <= 0}
        !indt[ij, t] => {x_M_t_avg <= 0}
        !indt[ij, t] => {-term1 == GS_K2[ij] .* (term2 - term3)}
    end)
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: [May 5, 2022, 4:41am UTC](https://discourse.julialang.org/t/indicator-constraints-with-quadratic-terms-may-have-bugs/80516/2 "2022-05-05T04:41:06Z")

</div>

Can you provide the solver and data to make this reproducible?

What do you mean by doesn’t work?

---

<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: [May 5, 2022, 8:28pm UTC](https://discourse.julialang.org/t/indicator-constraints-with-quadratic-terms-may-have-bugs/80516/4 "2022-05-05T20:28:12Z")

</div>

> [@iiitr](#):
>
> `@constraint(model, x_M_t .== feasible_solution_x_M_t)`

What happens if you use `set_start_value.(x_M_t, feasible_solution_x_M_t)` instead?

But if your claim is that Gurobi reports infeasible without the constraint, and feasible with the constraint, then this seems like a problem in Gurobi, not JuMP or Gurobi.jl. You should contact Gurobi support.

You can create an MPS file to send them by going

```Julia
optimize!(model)
GRBwrite(unsafe_backend(model), "model.mps")

```

---

<div class="post-metadata">

### Author: ![iiitr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iiitr/32/24586_2.png) [@iiitr](https://discourse.julialang.org/u/iiitr)
#### Post date: [May 6, 2022, 1:42am UTC](https://discourse.julialang.org/t/indicator-constraints-with-quadratic-terms-may-have-bugs/80516/5 "2022-05-06T01:42:46Z")

</div>

Thank you very much! I contacted Gurobi and they reported it as a bug.

---

<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: [May 6, 2022, 1:53am UTC](https://discourse.julialang.org/t/indicator-constraints-with-quadratic-terms-may-have-bugs/80516/6 "2022-05-06T01:53:47Z")

</div>

> I contacted Gurobi and they reported it as a bug

Nice work!
