• Gurobi Staff

Hi Srinivasan,

If you were to remove "constraint 3" then notice that your z variables don't appear anywhere else in the model - not in any other constraints, not in the objective function.  Gurobi will naturally set their values in an optimal solution to zero, which is why constraint 3 makes no difference to the optimal solution reported.

My guess is that you need to include some constraints that link the x and z variables together.

- Riley

Hi Riley,

I did make a change;
UB=len(items)
for k in range(UB):
for i in range(UB):
for j in range(UB):
if i != j:  # Avoid self-correlation
corr_coefficient, _ = pearsonr(items[i][3], items[j][3])
model.addConstr(corr_coefficient * (x[i, k] - x[j, k]) <= y[k],name=f"constraint_{i}_{j}_{k}")

This only depends on x now; it seems the condition is still not influencing the optimizer.

• Gurobi Staff

Hi Srinivasan,

Yes if I check the optimal solution with the following code:

for k,v in x.items():    if v.X > 0.5:        print(k, v)for k,v in y.items():    if v.X > 0.5:        print(k, v)

then it is apparent these constraints are redundant with respect to the optimal solution, i.e. they are satisfied by the optimal solution whether they are included in the model or not.

I'm not sure these are the constraints you want.  Is this what you are wanting to model:

"if correlation coefficient of item i and j is negative then they should be in the same bin"?

If this is correct here are a few follow up questions:

* if correlation coefficient of i and j is positive can they be in the same bin or must they be in different bins?
* if i and j are in the same bin do they have to have a negative correlation coefficient or can it be positive?

- Riley

Hi Riley,

if the correlation coefficient of items i and j is negative then they should be in the same bin"Yes they should be in the same bin if they have -ve correlation.

if correlation coefficient of i and j is positive can they be in the same bin or must they be in different bins?
They must be on different bins

* if i and j are in the same bin do they have to have a negative correlation coefficient or can it be positive?
If they are in the same bin, they should be -ve

• Gurobi Staff

Hi Srinivasan,

It sounds like you are describing a graph coloring problem.

The assignment based ILP model from section 2.2 of this paper:
https://arxiv.org/pdf/1706.10191.pdf
appears to be what you are trying to achieve.   Can you take a look and see if you agree?

- Riley