# (binary) solution not satisfying constraint

**URL:** https://discourse.julialang.org/t/binary-solution-not-satisfying-constraint/30998
**Category:** Optimization (Mathematical)
**Created:** [November 12, 2019, 9:58am UTC](https://discourse.julialang.org/t/binary-solution-not-satisfying-constraint/30998 "2019-11-12T09:58:15Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mposs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mposs/32/21087_2.png) [@mposs](https://discourse.julialang.org/u/mposs)
#### Post date: [November 12, 2019, 9:58am UTC](https://discourse.julialang.org/t/binary-solution-not-satisfying-constraint/30998/1 "2019-11-12T09:58:15Z")

</div>

Hello

I’m solving a small problem with Gurobi, which is given by `println(cover)`=

```julia
Min slack[1] + slack[2] + slack[7] + slack[9]
Subject to
 y[135] + y[136] + y[152] + y[158] + y[159] + y[200] + y[474] + y[550] + y[551] = 2.0
 y[135] + y[136] + y[152] + y[158] + y[159] + y[200] + y[474] + y[550] + y[551] + slack[1] ≥ 1.0
 y[135] + y[136] + y[158] + y[474] + y[550] + y[551] + slack[2] ≥ 1.0
 y[135] + y[136] + y[152] + y[158] + y[159] + y[200] + slack[7] ≥ 1.0
 y[135] + y[136] + y[152] + y[200] + y[474] + slack[9] ≥ 1.0
 slack[1] ≥ 0.0
 slack[2] ≥ 0.0
 slack[7] ≥ 0.0
 slack[9] ≥ 0.0
 y[135] binary
 y[136] binary
 y[152] binary
 y[158] binary
 y[159] binary
 y[200] binary
 y[474] binary
 y[550] binary
 y[551] binary

```

The returned solution is `println(value.(y))`=

```julia
1-dimensional DenseAxisArray{Float64,1,...} with index sets:
    Dimension 1, Any[134, 146, 158, 550, 551]
And data, a 5-element Array{Float64,1}:
 0.0
 0.0
 0.0
 0.0
 1.0

```

which does not satisfy the first constraint. How is that possible? (I can unfortunately not easily share the code).

Best,

Michael.

---

<div class="post-metadata">

### Author: ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)
#### Post date: [November 12, 2019, 12:00pm UTC](https://discourse.julialang.org/t/binary-solution-not-satisfying-constraint/30998/2 "2019-11-12T12:00:56Z")

</div>

What are the values of `raw_status(model)`, `termination_status(model)` and `primal_status(model)`?

---

<div class="post-metadata">

### Author: ![mposs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mposs/32/21087_2.png) [@mposs](https://discourse.julialang.org/u/mposs)
#### Post date: [November 12, 2019, 3:30pm UTC](https://discourse.julialang.org/t/binary-solution-not-satisfying-constraint/30998/3 "2019-11-12T15:30:42Z")

</div>

```julia
raw_status(model): Model was solved to optimality (subject to tolerances), and an optimal solution is available.
termination_status(model): OPTIMAL
primal_status(model): FEASIBLE_POINT

```

By the way, the solution has been found heuristically, as can be seen in the output:

```julia
Optimize a model with 5 rows, 9 columns and 20 nonzeros
Variable types: 4 continuous, 5 integer (5 binary)
Coefficient statistics:
  Matrix range [1e+00, 1e+00]
  Objective range [1e+00, 1e+00]
  Bounds range [0e+00, 0e+00]
  RHS range [1e+00, 2e+00]
Found heuristic solution: objective 0.0000000

Explored 0 nodes (0 simplex iterations) in 0.00 seconds
Thread count was 1 (of 8 available processors)

Solution count 1: 0 

Optimal solution found (tolerance 1.00e-04)
Best objective 0.000000000000e+00, best bound 0.000000000000e+00, gap 0.0000%

```

---

<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 12, 2019, 3:35pm UTC](https://discourse.julialang.org/t/binary-solution-not-satisfying-constraint/30998/4 "2019-11-12T15:35:47Z")

</div>

Without code, it’s hard to offer advice.

It looks like there is a bug in your code because the printed values have 5 elements, but it looks like your model has many more. Moreover, y[134] appears in the solution, but not in the model.

---

<div class="post-metadata">

### Author: ![mposs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mposs/32/21087_2.png) [@mposs](https://discourse.julialang.org/u/mposs)
#### Post date: [November 12, 2019, 3:45pm UTC](https://discourse.julialang.org/t/binary-solution-not-satisfying-constraint/30998/5 "2019-11-12T15:45:58Z")

</div>

Oops, indeed, I pasted the wrong model. Here comes the correct one:

```julia
Min slack[1] + slack[2] + slack[7] + slack[9]
Subject to
 y[134] + y[146] + y[158] + y[550] + y[551] = 2.0
 y[134] + y[146] + y[158] + y[551] + slack[1] ≥ 1.0
 y[134] + y[551] + slack[2] ≥ 1.0
 y[134] + y[146] + y[158] + slack[7] ≥ 1.0
 y[134] + y[146] + slack[9] ≥ 1.0
 slack[1] ≥ 0.0
 slack[2] ≥ 0.0
 slack[7] ≥ 0.0
 slack[9] ≥ 0.0
 y[134] binary
 y[146] binary
 y[158] binary
 y[550] binary
 y[551] binary

```

I’ll see if I can create a small instance of the bug.
