# 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 : 8 x + x + x + x + x + x + x <= 7.0
con : 11 x + x + x + x + x + x + x + x + x + x <= 10.0
con : 11 x + x + x + x + x + x + x + x + x + x <= 10.0
con : 10 x + x + x + x + x + x + x + x + x <= 9.0
con : 13 x + x + x + x + x + x + x + x + x + x + x + x <= 12.0

So for con 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 : 7 x + x + x + x + x + x + x <= 7.0
con : 10 x + x + x + x + x + x + x + x + x + x <= 10.0
con : 10 x + x + x + x + x + x + x + x + x + x <= 10.0
con : 9 x + x + x + x + x + x + x + x + x <= 9.0
con : 12 x + x + x + x + x + x + x + x + x + x + x + x <= 12.0

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.

You should read: PSA: make it easier to help you. 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