# Help with a JuMP.jl problem

**URL:** <https://discourse.julialang.org/t/help-with-a-jump-jl-problem/104778>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [October 10, 2023, 12:59am UTC](https://discourse.julialang.org/t/help-with-a-jump-jl-problem/104778 "2023-10-10T00:59:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [October 10, 2023, 12:59am UTC](https://discourse.julialang.org/t/help-with-a-jump-jl-problem/104778/1 "2023-10-10T00:59:24Z")

</div>

The task is fairly straightforward. I need to group the numbers in `A` into pairs, such that the sum of each pair corresponds to one of the numbers in `S`.

```julia
using HiGHS
using JuMP

m = Model(HiGHS.Optimizer)
A = [
	119 225 511 259 173 28
	486 374 375 227 164 314
	389 136 72 241 81 326
]

S = reshape(100:100:900, 3, 3)'

@variable(m, x[i=1:3, j=1:6, z=1:9], binary=true)

# you can only have 2 numbers from A in a group
for i ∈ 1:9
	@constraint(m, sum(x[:, :, i] .== true) == 2)
end

# the sums of the products of each group and A must equal S
@constraint(m, reshape([sum(x[:, :, i] .* A) for i ∈ 1:9], 3, 3)' .== S)

optimize!(m)

```

With HiGHS, it just tells me that it’s infeasible…

---

<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:** [October 10, 2023, 5:48am UTC](https://discourse.julialang.org/t/help-with-a-jump-jl-problem/104778/2 "2023-10-10T05:48:52Z")

</div>

The issue is

```julia
for i in 1:9
	@constraint(m, sum(x[:, :, i] .== true) == 2)
end

```

because you are comparing a `VariableRef == Bool`, which is always false:

```julia
julia> i = 1
1

julia> sum(x[:, :, i] .== true)
0

```

So the constraint says `0 == 2`.

Here’s how you can write it

```plaintext
using HiGHS
using JuMP
model = Model(HiGHS.Optimizer)
A = [
	119 225 511 259 173 28
	486 374 375 227 164 314
	389 136 72 241 81 326
]
S = reshape(100:100:900, 3, 3)'
@variable(model, x[1:3, 1:6, 1:9], Bin)
@constraint(model, [i in 1:9], sum(x[:, :, i]) == 2)
@constraint(model, reshape([sum(x[:, :, i] .* A) for i in 1:9], 3, 3)' .== S)
optimize!(model)

```
