RHS and LHS inconsistency in indexing over constraints

Hi folks,

This is my first time using Julia for math optimization (was previously running Xpress FICO).
I am trying to run a relatively easy anti-covering model. But I am running into issue with indices (or something else). I was hoping you could help me figure it out.

The following command:

@constraint(aclp, con[j in 1:length(jsites)], length(omega[j]) * x[j] + sum(x[k] for k in omega[j]) <= length(omega[j])) 

Produces erroneous constraints (see the part in bold ):
con[1] : 8 x[1] + x[2] + x[3] + x[5] + x[6] + x[8] + x[10] <= 7.0
con[2] : 11 x[2] + x[1] + x[3] + x[4] + x[5] + x[6] + x[8] + x[9] + x[10] + x[11] <= 10.0
con[3] : 11 x[3] + x[1] + x[2] + x[4] + x[5] + x[6] + x[8] + x[10] + x[11] + x[12] <= 10.0
con[4] : 10 x[4] + x[2] + x[3] + x[5] + x[6] + x[7] + x[8] + x[9] + x[11] <= 9.0
con[5] : 13 x[5] + x[1] + x[2] + x[3] + x[4] + x[6] + x[8] + x[9] + x[10] + x[11] + x[12] + x[13] <= 12.0

So for con[1] the command length(omega[j]) in LHS produces 8, when in actuality it should be 7 (RHS). This repeats for all other constraints.

To work around the issue I have to manually deduct 1 from length(jsites) in LHS.

This could me an indexing issues or something else, or maybe I am using the Julia wrong. The following code produces correct constraints.

@constraint(aclp, con[j in 1:length(jsites)], **(length(omega[j])-1)** * x[j] + sum(x[k] for k in omega[j]) <= length(omega[j])) 

con[1] : 7 x[1] + x[2] + x[3] + x[5] + x[6] + x[8] + x[10] <= 7.0
con[2] : 10 x[2] + x[1] + x[3] + x[4] + x[5] + x[6] + x[8] + x[9] + x[10] + x[11] <= 10.0
con[3] : 10 x[3] + x[1] + x[2] + x[4] + x[5] + x[6] + x[8] + x[10] + x[11] + x[12] <= 10.0
con[4] : 9 x[4] + x[2] + x[3] + x[5] + x[6] + x[7] + x[8] + x[9] + x[11] <= 9.0
con[5] : 12 x[5] + x[1] + x[2] + x[3] + x[4] + x[6] + x[8] + x[9] + x[10] + x[11] + x[12] + x[13] <= 12.0

Full runnable code with data can be downloaded from here.

I checked different solvers and the error is the same, so this is not solver-related.
I am running Julia v1.4 inside VS Code. JuMP v0.21.2. Windows 10.

x-ref: Constraint macro RHS and LHS with length(dict[i]) command returns different values · Issue #2254 · jump-dev/JuMP.jl · GitHub

You should read: Please read: make it easier to help you - #19. In particular, it’s easier to help if you can provide a small example that we can copy-paste, rather than downloading and extracting a zip from a different site.

I’ll repeat my suggestion from the JuMP issue for posterity:

sum(x[k] for k in omega[j]) probably includes x[j] . Which would account for the extra coefficient in front of x[j] .

Thanks for reposting, @odow!

I check the dictionary of omegas and it did include the reference to self. Thank you for pointing it out!
I will make sure to follow the PSA guidelines next time I post.

Thanks again!

1 Like