-
-
Notifications
You must be signed in to change notification settings - Fork 411
Description
So this might as well be my first ticket on Github, so I apologize in advance if the formatting and/or ordering is wrong.
I am trying to run a relatively easy anti-covering model. I can provide a complete runnable code and data if necessary.
jsites = 1:n;
omega =Dict(i => sort(findall(dd[i,:] .< r)) for i in 1:size(dd)[1] )
And dd is simply an OD cost matrix, r - is a fixed threshold distance.
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
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.