Originally posted by: excalibur1491
Hello,
I am very new to CPLEX and I am writing my first model for a MIP problem. I am using a lot of indicator constraints and CPLEX seems to struggle to solve the problems quickly for more than 500 variables.
The description of the problem is as follows:
You are given a grid (graph) where the weight of edges is unknown. For each edge ei, there are two possibles weights eiA or eiB (which are known as part of the data).
Then there is a matrix (the weighted Laplacian matrix L 1 ) that contains all these weight variables and is multiplied by a vector of variables v0,v1,...,vn like this L v = R, where R is a vector containing all 0's and a single 1.
As you can see, this is not linear because I am multiplying weight variables (in L) with other variables (of v).
So the way I have done this is by writing the equations resulting from the multiplication of L and v with some fake variables i_x_y. And so I have a bunch of linear equations like this:
i_1_2 + i_2_3 - i_3_4 - i_4_5 = 1
i_3_4 + i_5_7 - i_8_10 - i_8_9 = 0
i_2_3 - i_4_5 - i_7_6 = 0
......
And then a lot of indicator constraints as follows:
b1 = 1 -> i_1_2 - e1A * v0 =0 \ You chose weight A for edge e2
b1 = 0 -> i_1_2 - e1B *v0 = 0 \ You chose weight B for edge e1
b2 = 1 -> i_3_4 ...
b2 = 0 -> i_3_4 ....
.....
Therefore I have 2*number-of-edges indicator constraints (which may be a lot ?) and number_of_nodes linear equations (of at most 8 terms each, because its a grid graph). The indicator constraints bind the terms of the equations to the v variables.
Then there is a budget constraint that limits the number of boolean variables that can be true.
The objective is to minimize the value of one (yes, just one) of the variables in v (the one that is in the same row as the value 1 in the vector R previously described).
All my variables are free (or Binary). I should try to find bounds that can help CPLEX, but I haven't been able to yet. But in any case, there is no bound restriction on any of those variables.
It seems to be ok with small instances, but grids of size 10x10 create 636 columns (which I didn't think was too much) and CPLEX takes ~40s to solve it, but for 15x15 grids (~1400 vars) it takes a good 700s... Is my modelling choice wrong? I don't see any otehr way to do it without indicator constraints. Scalability is very important, I would like to solve grids of at least 30x30 (at the very least..)
--
1 The weighted Laplacian is defined as:
Lij = - weight_edge_i_to_j , if i != j
Lij = sum of weights of edges touching i , if i == j
Lij = 0 otherwise
--
Also, I should add that the log of CPLEx shows several times the word "unbounded" in the "Objective" column, which worries me. Should it actually worry me?
Nodes Cuts/
Node Left Objective IInf Best Integer Best Bound ItCnt Gap
0 0 unbounded 0
0 2 unbounded 0
Elapsed real time = 0.02 sec. (tree size = 0.01 MB, solutions = 0)
* 3 3 integral 0 1.8977 838 ---
29 7 cutoff 1.8977 11690 ---
49 7 cutoff 1.8977 22934 ---
69 7 cutoff 1.8977 31030 ---
89 7 cutoff 1.8977 39568 ---
109 7 cutoff 1.8977 50505 ---
129 7 cutoff 1.8977 58858 ---
149 7 cutoff 1.8977 67750 ---
169 7 cutoff 1.8977 76011 ---
261 7 cutoff 1.8977 110321 ---
Elapsed real time = 7.48 sec. (tree size = 0.01 MB, solutions = 0)
357 7 cutoff 1.8977 144265 ---
453 7 cutoff 1.8977 176141 ---
565 7 cutoff 1.8977 209336 ---
681 7 cutoff 1.8977 240631 ---
813 7 cutoff 1.8977 272101 ---
961 7 cutoff 1.8977 302109 ---
1133 7 cutoff 1.8977 330179 ---
1341 7 cutoff 1.8977 354329 ---
1643 7 unbounded 1.8977 369748 ---
1770 4 cutoff 1.8977 406808 ---
I didn't want to fill my post with code, but as an example, here is a small model (4x4 grid, in this example all the edges take weight 1 or 0.01):
Minimize
obj: v0
Subject To
l0: i_1_0 + i_2_0 - i_1_1 - i_2_3 = 1
l1: - i_1_0 + i_1_1 + i_3_1 + i_4_1 - i_3_2 - i_4_4 = 0
l2: - i_3_1 + i_3_2 + i_5_2 - i_5_5 = 0
l3: - i_2_0 + i_2_3 + i_6_3 + i_7_3 - i_6_4 - i_7_6 = 0
l4: - i_4_1 - i_6_3 + i_4_4 + i_6_4 + i_8_4 + i_9_4 - i_8_5 - i_9_7 = 0
l5: - i_5_2 - i_8_4 + i_5_5 + i_8_5 + i_10_5 = 0
l6: - i_7_3 + i_7_6 + i_11_6 - i_11_7 = 0
l7: - i_9_4 - i_11_6 + i_9_7 + i_11_7 + i_12_7 = 0
c0: b_1 = 1 -> i_1_0 - 1 v0 = 0
c1: b_1 = 0 -> i_1_0 - 0.01 v0 = 0
c2: b_2 = 1 -> i_2_0 - 1 v0 = 0
c3: b_2 = 0 -> i_2_0 - 0.01 v0 = 0
c4: b_1 = 1 -> i_1_1 - 1 v1 = 0
c5: b_1 = 0 -> i_1_1 - 0.01 v1 = 0
c6: b_2 = 1 -> i_2_3 - 1 v3 = 0
c7: b_2 = 0 -> i_2_3 - 0.01 v3 = 0
c8: b_3 = 1 -> i_3_1 - 1 v1 = 0
c9: b_3 = 0 -> i_3_1 - 0.01 v1 = 0
c10: b_4 = 1 -> i_4_1 - 1 v1 = 0
c11: b_4 = 0 -> i_4_1 - 0.01 v1 = 0
c12: b_3 = 1 -> i_3_2 - 1 v2 = 0
c13: b_3 = 0 -> i_3_2 - 0.01 v2 = 0
c14: b_4 = 1 -> i_4_4 - 1 v4 = 0
c15: b_4 = 0 -> i_4_4 - 0.01 v4 = 0
c16: b_5 = 1 -> i_5_2 - 1 v2 = 0
c17: b_5 = 0 -> i_5_2 - 0.01 v2 = 0
c18: b_5 = 1 -> i_5_5 - 1 v5 = 0
c19: b_5 = 0 -> i_5_5 - 0.01 v5 = 0
c20: b_6 = 1 -> i_6_3 - 1 v3 = 0
c21: b_6 = 0 -> i_6_3 - 0.01 v3 = 0
c22: b_7 = 1 -> i_7_3 - 1 v3 = 0
c23: b_7 = 0 -> i_7_3 - 0.01 v3 = 0
c24: b_6 = 1 -> i_6_4 - 1 v4 = 0
c25: b_6 = 0 -> i_6_4 - 0.01 v4 = 0
c26: b_7 = 1 -> i_7_6 - 1 v6 = 0
c27: b_7 = 0 -> i_7_6 - 0.01 v6 = 0
c28: b_8 = 1 -> i_8_4 - 1 v4 = 0
c29: b_8 = 0 -> i_8_4 - 0.01 v4 = 0
c30: b_9 = 1 -> i_9_4 - 1 v4 = 0
c31: b_9 = 0 -> i_9_4 - 0.01 v4 = 0
c32: b_8 = 1 -> i_8_5 - 1 v5 = 0
c33: b_8 = 0 -> i_8_5 - 0.01 v5 = 0
c34: b_9 = 1 -> i_9_7 - 1 v7 = 0
c35: b_9 = 0 -> i_9_7 - 0.01 v7 = 0
c36: b_10 = 1 -> i_10_5 - 1 v5 = 0
c37: b_10 = 0 -> i_10_5 - 0.01 v5 = 0
c38: b_11 = 1 -> i_11_6 - 1 v6 = 0
c39: b_11 = 0 -> i_11_6 - 0.01 v6 = 0
c40: b_11 = 1 -> i_11_7 - 1 v7 = 0
c41: b_11 = 0 -> i_11_7 - 0.01 v7 = 0
c42: b_12 = 1 -> i_12_7 - 1 v7 = 0
c43: b_12 = 0 -> i_12_7 - 0.01 v7 = 0
budget: 1 b_10 + 1 b_11 + 1 b_8 + 1 b_9 + 1 b_12 + 1 b_1 + 1 b_2 + 1 b_3 + 1 b_4 + 1 b_5
+ 1 b_6 + 1 b_7 <= 2
Bounds
v0 free
v1 free
v2 free
v3 free
v4 free
v5 free
v6 free
v7 free
i_6_4 free
i_6_3 free
i_5_2 free
i_5_5 free
i_9_4 free
i_9_7 free
i_7_6 free
i_8_4 free
i_8_5 free
i_7_3 free
i_12_7 free
i_1_1 free
i_1_0 free
i_3_2 free
i_3_1 free
i_11_7 free
i_11_6 free
i_2_3 free
i_2_0 free
i_10_5 free
i_4_1 free
i_4_4 free
Binaries
b_10
b_11
b_8
b_9
b_12
b_1
b_2
b_3
b_4
b_5
b_6
b_7
Thanks for your ideas
#CPLEXOptimizers#DecisionOptimization