Constraints not being satisfied while using vector elements as rhs

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.

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

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:

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

Thanks

Try

!=

instead of

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

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

Well, I have this output from the solver

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?

Define the constraint and objective like this

@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.

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

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.

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

1 Like