# Constraints not being satisfied while using vector elements as rhs

**URL:** <https://discourse.julialang.org/t/constraints-not-being-satisfied-while-using-vector-elements-as-rhs/88294>\
**Category:** Optimization (Mathematical)\
**Created:** [October 5, 2022, 1:43pm UTC](https://discourse.julialang.org/t/constraints-not-being-satisfied-while-using-vector-elements-as-rhs/88294 "2022-10-05T13:43:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gokhan\_Kof](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gokhan_kof/32/43267_2.png) [@Gokhan\_Kof](https://discourse.julialang.org/u/Gokhan_Kof)\
**Post date:** [October 5, 2022, 1:43pm UTC](https://discourse.julialang.org/t/constraints-not-being-satisfied-while-using-vector-elements-as-rhs/88294/1 "2022-10-05T13:43:35Z")

</div>

Hi,

I am trying to solve the model below but the constraints are not being satisfied if I input a vector on the rhs (u[j] - 1). But, when I type it with hand (34, 28). It is being satisfied.

```julia
ap.p
3
ap.n
5
ap.c
3×5×5 Array{Int64, 3}:
[:, :, 1] =
 6 6 10 15 11
 2 7 4 10 10
 1 17 19 2 1

[:, :, 2] =
 1 8 13 3 20
 6 10 11 7 15
 6 20 13 15 9

[:, :, 3] =
 20 6 1 5 16
  9 10 1 1 20
 20 8 7 12 20

[:, :, 4] =
  2 9 10 1 12
 10 6 13 19 11
  5 8 18 10 7

[:, :, 5] =
  3 6 15 11 9
 18 2 1 12 7
  9 20 17 3 6

```

```julia
begin
	k = 1
	u = [0, 35, 29]
	model = Model(optimizer_with_attributes(HiGHS.Optimizer, "output_flag" => false))
	@variable(model, x[1:ap.n, 1:ap.n], Bin)
	@constraint(model, [r = 1:ap.n], sum(x[r, l] for l in 1:ap.n) == 1)
	@constraint(model, [l = 1:ap.n], sum(x[r, l] for r in 1:ap.n) == 1)
	@constraint(model, [j = 1:ap.p; j ≠ k], sum(ap.c[j,:,:] .* x) <= u[j] - 1)
	@objective(model, Min, sum(ap.c[k,:,:] .* x))
	# print(model)
	optimize!(model)
	status = termination_status(model)
	println([sum(ap.c[j,:,:] .* value.(x)) for j in 1:ap.p])
end

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/f/6ffca56e5b094b48c872a129000be9ac9d6b99df.png)

Sounds like something I am missing something obvious but I appreciate any help?!

EDIT:

I just realized even if I type it like the following it still does not work:

```julia
@constraint(model, sum(ap.c[2,:,:] .* x) <= 34)
@constraint(model, sum(ap.c[3,:,:] .* x) <= 28)

```

Thanks

---

<div class="post-metadata">

**Author:** ![Mahbubar06](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@Mahbubar06](https://discourse.julialang.org/u/Mahbubar06)\
**Post date:** [October 5, 2022, 3:06pm UTC](https://discourse.julialang.org/t/constraints-not-being-satisfied-while-using-vector-elements-as-rhs/88294/2 "2022-10-05T15:06:20Z")

</div>

Try

```julia
!=

```

instead of

```julia
≠

```

in your constraint definition. It works. It turns out your model is infeasible!

---

<div class="post-metadata">

**Author:** ![Gokhan\_Kof](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gokhan_kof/32/43267_2.png) [@Gokhan\_Kof](https://discourse.julialang.org/u/Gokhan_Kof)\
**Post date:** [October 5, 2022, 3:20pm UTC](https://discourse.julialang.org/t/constraints-not-being-satisfied-while-using-vector-elements-as-rhs/88294/3 "2022-10-05T15:20:06Z")

</div>

I do not think that is the issue. Am I still missing something?

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/d/dd52d6105244f88b1a9528325a96e0121e9ce1c6.jpeg)

---

<div class="post-metadata">

**Author:** ![Gokhan\_Kof](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gokhan_kof/32/43267_2.png) [@Gokhan\_Kof](https://discourse.julialang.org/u/Gokhan_Kof)\
**Post date:** [October 5, 2022, 3:28pm UTC](https://discourse.julialang.org/t/constraints-not-being-satisfied-while-using-vector-elements-as-rhs/88294/4 "2022-10-05T15:28:25Z")

</div>

Well, I have this output from the solver

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/c/6cbbb70db1bdf902af778afb1eb5a87f7a6baf59.jpeg)

Anyone knows what the error part means? If the model is infeasible, why does the terminations\_status shows optimal? And how can I access the true solver status?

---

<div class="post-metadata">

**Author:** ![Mahbubar06](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@Mahbubar06](https://discourse.julialang.org/u/Mahbubar06)\
**Post date:** [October 5, 2022, 3:29pm UTC](https://discourse.julialang.org/t/constraints-not-being-satisfied-while-using-vector-elements-as-rhs/88294/5 "2022-10-05T15:29:17Z")

</div>

Define the constraint and objective like this

```julia
@constraint(model, [j = 1:p; j!=k], sum(sum(c[j,l,m]*x[l,m] for l in 1:n) for m in 1:n) <= u[j] - 1)
@objective(model, Min, sum(sum(c[k,l,m]*x[l,m] for l in 1:n) for m in 1:n))

```

This solves your problem optimally.

---

<div class="post-metadata">

**Author:** ![Gokhan\_Kof](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gokhan_kof/32/43267_2.png) [@Gokhan\_Kof](https://discourse.julialang.org/u/Gokhan_Kof)\
**Post date:** [October 5, 2022, 3:37pm UTC](https://discourse.julialang.org/t/constraints-not-being-satisfied-while-using-vector-elements-as-rhs/88294/6 "2022-10-05T15:37:31Z")

</div>

> [@Mahbubar06](#):
>
> ```julia
> @objective(model, Min, sum(sum(c[k,l,m]*x[l,m] for l in 1:n) for m in 1:n))
> 
> ```

Shouldn’t 2nd element in the vector output be less than 35?

 ![image](https://global.discourse-cdn.com/julialang/original/3X/f/d/fd40065d3303c9f6367be2ff670fcac6201e061c.jpeg)

---

<div class="post-metadata">

**Author:** ![Mahbubar06](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@Mahbubar06](https://discourse.julialang.org/u/Mahbubar06)\
**Post date:** [October 5, 2022, 3:45pm UTC](https://discourse.julialang.org/t/constraints-not-being-satisfied-while-using-vector-elements-as-rhs/88294/7 "2022-10-05T15:45:16Z")

</div>

Yes, your point is right, then I have no idea what is happening! This is may be the issue with HiGHS solver. Because other solver like Gurobi gives infeasible status.

---

<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 8, 2022, 4:42am UTC](https://discourse.julialang.org/t/constraints-not-being-satisfied-while-using-vector-elements-as-rhs/88294/8 "2022-10-08T04:42:47Z")

</div>

Upstream HiGHS has a few fixes for these sorts of problems that haven’t been released yet: [Incorrect Termination Status · Issue #966 · ERGO-Code/HiGHS · GitHub](https://github.com/ERGO-Code/HiGHS/issues/966)
