Very long solving time
AnsweredHi
I am solving an optimization problem, which comprises of 481 variables and 160 equality constraints. Whereas my objective function is just a one-variable, and I am trying to minimize that. The problem is running for more than one day but still doesn't finish the computation. My code is below
from gurobipy import *
f = Model("SF")
f.params.NonConvex = 2
x = {}
for i in range(1,457,1):
x[i] = f.addVar(lb=0, ub=1, obj=0, vtype = GRB.CONTINUOUS, name="x")
y = f.addVars(6, lb=-GRB.INFINITY, ub=GRB.INFINITY, obj=0, vtype = GRB.INTEGER, name="Delta0")
z = f.addVars(6, lb=-GRB.INFINITY, ub=GRB.INFINITY, obj=0, vtype = GRB.INTEGER, name="Delta1")
a0 = f.addVar(lb=-GRB.INFINITY, ub=GRB.INFINITY, obj=0, vtype = GRB.INTEGER, name = "a0")
b0 = f.addVar(lb=-GRB.INFINITY, ub=GRB.INFINITY, obj=0, vtype = GRB.INTEGER, name = "b0")
c0 = f.addVar(lb=-GRB.INFINITY, ub=GRB.INFINITY, obj=0, vtype = GRB.INTEGER, name = "c0")
e0 = f.addVar(lb=-GRB.INFINITY, ub=GRB.INFINITY, obj=0, vtype = GRB.INTEGER, name = "e0")
a1 = f.addVar(lb=-GRB.INFINITY, ub=GRB.INFINITY, obj=0, vtype = GRB.INTEGER, name = "a1")
b1 = f.addVar(lb=-GRB.INFINITY, ub=GRB.INFINITY, obj=0, vtype = GRB.INTEGER, name = "b1")
c1 = f.addVar(lb=-GRB.INFINITY, ub=GRB.INFINITY, obj=0, vtype = GRB.INTEGER, name = "c1")
e1 = f.addVar(lb=-GRB.INFINITY, ub=GRB.INFINITY, obj=0, vtype = GRB.INTEGER, name = "e1")
h = f.addVars(4, lb=-GRB.INFINITY, ub=GRB.INFINITY, obj=0, vtype = GRB.INTEGER, name = "h")
d = f.addVar(lb=0, ub=3, obj=0, vtype = GRB.INTEGER, name = "d")
f.setObjective(d, GRB.MINIMIZE)
f.addConstr( x[2] - x[3] + x[4] - x[5] + x[6] - x[7] == 0, "c1")
f.addConstr(-x[2] + x[3] + x[8] - x[9] == -1, "c2")
f.addQConstr(-x[4] + x[5] + x[10] -x[11] + x[14]*y[0] + x[15]*y[3] == 0, "c3")
f.addQConstr(x[12] - x[13] + x[14]*y[1] + x[15]*y[4] == 1, "c4")
f.addQConstr(x[1] + 4*x[4] - 4*x[5] + 7*x[7] + 7*x[9] + 7*x[11] + 7*x[13] + x[14]*y[2] + x[15]*y[5] - d == 0, "c5")
f.addConstr(x[17] - x[18] + x[19] - x[20] + x[21] - x[22] == 0, "c6")
f.addConstr(-x[17] + x[18] + x[23] - x[24] == 1, "c7")
f.addQConstr(-x[19] + x[20] + x[25] -x[26] + x[29]*y[0] + x[30]*y[3] == 0, "c8")
f.addQConstr(x[27] - x[28] + x[29]*y[1] + x[30]*y[4] == -1, "c9")
f.addQConstr(x[16]+ 4*x[19] -4*x[20] + 7*x[22] + 7*x[24] + 7*x[26] + 7*x[28] + x[29]*y[2] + x[30]*y[5] - d == 0, "c10")
f.addConstr(x[32] - x[33] + x[34] - x[35] + x[36] - x[37] == 0, "c11")
f.addConstr(-x[32] + x[33] + x[38] - x[39] == -1, "c12")
f.addQConstr(-x[34] + x[35] + x[40] -x[41] + x[44]*y[0] + x[45]*y[3] == 0, "c13")
f.addQConstr(x[42] - x[43] + x[44]*y[1] + x[45]*y[4] == 1, "14")
f.addQConstr(x[31]- 4*x[34] + 4*x[35] + 7*x[37] + 7*x[39] + 7*x[41] + 7*x[43] + x[44]*y[2] + x[45]*y[5] - d == 0, "c15")
f.addConstr(x[47] - x[48] + x[49] - x[50] + x[51] - x[52] == 0, "c16")
f.addConstr(-x[47] + x[48] + x[53] - x[54] == 1, "c17")
f.addQConstr(-x[49] + x[50] + x[55] -x[56] + x[59]*y[0] + x[60]*y[3] == 0, "c18")
f.addQConstr(x[57] - x[58] + x[59]*y[1] + x[60]*y[4] == -1, "c19")
f.addQConstr(x[46]- 4*x[49] + 4*x[50] + 7*x[52] + 7*x[54] + 7*x[56] + 7*x[58] + x[59]*y[2] + x[60]*y[5] - d == 0, "c20")
f.addConstr(x[62] - x[63] + x[64] - x[65] + x[66] - x[67] == 0, "c21")
f.addConstr(-x[62] + x[63] + x[68] - x[69] == -1, "c22")
f.addQConstr(-x[64] + x[65] + x[70] -x[71] + x[74]*z[0] + x[75]*z[3] == 0, "c23")
f.addQConstr(x[72] - x[73] + x[74]*z[1] + x[75]*z[4] == 1, "c24")
f.addQConstr(x[61] + 4*x[64] - 4*x[65] + 7*x[67] + 7*x[69] + 7*x[71] + 7*x[73] + x[74]*z[2] + x[75]*z[5] - d == 0, "c25")
f.addConstr(x[77] - x[78] + x[79] - x[80] + x[81] - x[82] == 0, "c26")
f.addConstr(-x[77] + x[78] + x[83] - x[84] == 1, "c27")
f.addQConstr(-x[79] + x[80] + x[85] -x[86] + x[89]*z[0] + x[90]*z[3] == 0, "c28")
f.addQConstr(x[87] - x[88] + x[89]*z[1] + x[90]*z[4] == -1, "c29")
f.addQConstr(x[76] + 4*x[79] - 4*x[80] + 7*x[82] + 7*x[84] + 7*x[86] + 7*x[88] + x[89]*z[2] + x[90]*z[5] - d == 0, "c30")
f.addConstr(x[92] - x[93] + x[94] - x[95] + x[96] - x[97] == 0, "c31")
f.addConstr(-x[92] + x[93] + x[98] - x[99] == -1, "c32")
f.addQConstr(-x[94] + x[95] + x[100] -x[101] + x[104]*z[0] + x[105]*z[3] == 0, "c33")
f.addQConstr(x[102] - x[103] + x[104]*z[1] + x[105]*z[4] == 1, "c34")
f.addQConstr(x[91] - 4*x[94] + 4*x[95] + 7*x[97] + 7*x[99] + 7*x[101] + 7*x[103] + x[104]*z[2] + x[105]*z[5] - d == 0, "c35")
f.addConstr(x[107] - x[108] + x[109] - x[110] + x[111] - x[112] == 0, "c36")
f.addConstr(-x[107] + x[108] + x[113] - x[114] == 1, "c37")
f.addQConstr(-x[109] + x[110] + x[115] -x[116] + x[119]*z[0] + x[120]*z[3] == 0, "c38")
f.addQConstr(x[117] - x[118] + x[119]*z[1] + x[120]*z[4] == -1, "c39")
f.addQConstr(x[106] - 4*x[109] + 4*x[110] + 7*x[112] + 7*x[114] + 7*x[116] + 7*x[118] + x[119]*z[2] + x[120]*z[5] - d == 0, "c40")
f.addQConstr(x[122] - x[123] + x[124] - x[125] + x[126] - x[127] + x[132]*a0 - x[133]*a0 - x[134]*h[0] == 0, "c41")
f.addQConstr(-x[122] + x[123] + x[128] - x[129] + x[132]*b0 - x[133]*b0 - x[134]*h[1] == 0, "c42")
f.addQConstr(-x[124] + x[125] + x[130] - x[131] + x[132]*c0 - x[133]*c0 - x[134]*h[2] == 0, "c43")
f.addConstr(-x[132] + x[133] == 0, "c44")
f.addQConstr(x[121] + 4*x[124] - 4*x[125] + 7*x[127] + 7*x[129] + 7*x[131] + x[132]*e0 - x[133]*e0 - x[134]*h[3] == 0, "c45")
f.addQConstr(x[136] - x[137] + x[138] - x[139] + x[140] - x[141] + x[146]*a0 - x[147]*a0 - x[148]*h[0] == 0, "c46")
f.addQConstr(-x[136] + x[137] + x[142] - x[143] + x[146]*b0 - x[147]*b0 - x[148]*h[1] == 0, "c47")
f.addQConstr(-x[138] + x[139] + x[144] - x[145] + x[146]*c0 - x[147]*c0 - x[148]*h[2] == 0, "c48")
f.addConstr(-x[146] + x[147] == -1, "c49")
f.addQConstr(x[135] + 4*x[138] - 4*x[139] + 7*x[141] + 7*x[143] + 7*x[145] + x[146]*e0 - x[147]*e0 - x[148]*h[3] == 7, "c50")
f.addQConstr(x[150] - x[151] + x[152] - x[153] + x[154] - x[155] + x[160]*a0 - x[161]*a0 - x[162]*h[0] == 0, "c51")
f.addQConstr(-x[150] + x[151] + x[156] - x[157] + x[160]*b0 - x[161]*b0 - x[162]*h[1] == -1, "c52")
f.addQConstr(-x[152] + x[153] + x[158] - x[159] + x[160]*c0 - x[161]*c0 - x[162]*h[2] == 0, "c53")
f.addConstr(-x[160] + x[161] == 1, "c54")
f.addQConstr(x[149] + 4*x[152] - 4*x[153] + 7*x[155] + 7*x[157] + 7*x[159] + x[160]*e0 - x[161]*e0 - x[162]*h[3] - d == 0, "c55")
f.addQConstr(x[164] - x[165] + x[166] - x[167] + x[168] - x[169] + x[174]*a0 - x[175]*a0 - x[176]*h[0] == 0, "c56")
f.addQConstr(-x[164] + x[165] + x[170] - x[171] + x[174]*b0 - x[175]*b0 - x[176]*h[1] == 1, "c57")
f.addQConstr(-x[166] + x[167] + x[172] - x[173] + x[174]*c0 - x[175]*c0 - x[176]*h[2] == 0, "c58")
f.addConstr(-x[174] + x[175] == -1, "c59")
f.addQConstr(x[163] + 4*x[166] - 4*x[167] + 7*x[169] + 7*x[171] + 7*x[173] + x[174]*e0 - x[175]*e0 - x[176]*h[3] - d == 0, "c60")
f.addQConstr(x[178] - x[179] + x[180] - x[181] + x[182] - x[183] + x[188]*a0 - x[189]*a0 - x[190]*h[0] == 0, "c61")
f.addQConstr(-x[178] + x[179] + x[184] - x[185] + x[188]*b0 - x[189]*b0 - x[190]*h[1] == 0, "c62")
f.addQConstr(-x[180] + x[181] + x[186] - x[187] + x[188]*c0 - x[189]*c0 - x[190]*h[2]- y[0] == 0, "c63")
f.addConstr(-x[188] + x[189] - y[1] == 0, "c64")
f.addQConstr(x[177] + 4*x[180] - 4*x[181] + 7*x[183] + 7*x[185] + 7*x[187] + x[188]*e0 - x[189]*e0 - x[190]*h[3] - y[2] == 0, "c65")
f.addQConstr(x[192] - x[193] + x[194] - x[195] + x[196] - x[197] + x[202]*a0 - x[203]*a0 - x[204]*h[0] == 0, "c66")
f.addQConstr(-x[192] + x[193] + x[198] - x[199] + x[202]*b0 - x[203]*b0 - x[204]*h[1] == 0, "c67")
f.addQConstr(-x[194] + x[195] + x[200] - x[201] + x[202]*c0 - x[203]*c0 - x[204]*h[2]- y[3] == 0, "c68")
f.addConstr(-x[202] + x[203] - y[4] == 0, "c69")
f.addQConstr(x[191] + 4*x[194] - 4*x[195] + 7*x[197] + 7*x[199] + 7*x[201] + x[202]*e0 - x[203]*e0 - x[204]*h[3] - y[5] == 0, "c70")
f.addQConstr(x[206] - x[207] + x[208] - x[209] + x[210] - x[211] + x[216]*a0 - x[217]*a0 - x[218]*h[0] == 0, "c71")
f.addQConstr(-x[206] + x[207] + x[212] - x[213] + x[216]*b0 - x[217]*b0 - x[218]*h[1] == 0, "c72")
f.addQConstr(-x[208] + x[209] + x[214] - x[215] + x[216]*c0 - x[217]*c0 - x[218]*h[2] == 0, "c73")
f.addConstr(-x[216] + x[217] == 1, "c74")
f.addQConstr(x[205] - 4*x[208] + 4*x[209] + 7*x[211] + 7*x[213] + 7*x[215] + x[216]*e0 - x[217]*e0 - x[218]*h[3] == 0, "c75")
f.addQConstr(x[220] - x[221] + x[222] - x[223] + x[224] - x[225] + x[230]*a0 - x[231]*a0 - x[232]*h[0] == 0, "c76")
f.addQConstr(-x[220] + x[221] + x[226] - x[227] + x[230]*b0 - x[231]*b0 - x[232]*h[1] == 0, "c77")
f.addQConstr(-x[222] + x[223] + x[228] - x[229] + x[230]*c0 - x[231]*c0 - x[232]*h[2] == 0, "c78")
f.addConstr(-x[230] + x[231] == - 1, "c79")
f.addQConstr(x[219] - 4*x[222] + 4*x[223] + 7*x[225] + 7*x[227] + 7*x[229] + x[230]*e0 - x[231]*e0 - x[232]*h[3] == 7, "c80")
f.addQConstr(x[234] - x[235] + x[236] - x[237] + x[238] - x[239] + x[244]*a0 - x[245]*a0 - x[246]*h[0] == 0, "c81")
f.addQConstr(-x[234] + x[235] + x[240] - x[241] + x[244]*b0 - x[245]*b0 - x[246]*h[1] == -1, "c82")
f.addQConstr(-x[236] + x[237] + x[242] - x[243] + x[244]*c0 - x[245]*c0 - x[246]*h[2] == 0, "c83")
f.addConstr(-x[244] + x[245] == 1, "c84")
f.addQConstr(x[233] - 4*x[236] + 4*x[237] + 7*x[239] + 7*x[241] + 7*x[243] + x[244]*e0 - x[245]*e0 - x[246]*h[3] - d == 0, "c85")
f.addQConstr(x[248] - x[249] + x[250] - x[251] + x[252] - x[253] + x[258]*a0 - x[259]*a0 - x[260]*h[0] == 0, "c86")
f.addQConstr(-x[248] + x[249] + x[254] - x[255] + x[258]*b0 - x[259]*b0 - x[260]*h[1] == 1, "c87")
f.addQConstr(-x[250] + x[251] + x[256] - x[257] + x[258]*c0 - x[259]*c0 - x[260]*h[2] == 0, "c88")
f.addConstr(-x[258] + x[259] == -1, "c89")
f.addQConstr(x[247] - 4*x[250] + 4*x[251] + 7*x[253] + 7*x[255] + 7*x[257] + x[258]*e0 - x[259]*e0 - x[260]*h[3] - d == 0, "c90")
f.addQConstr(x[262] - x[263] + x[264] - x[265] + x[266] - x[267] + x[272]*a0 - x[273]*a0 - x[274]*h[0] == 0, "c91")
f.addQConstr(-x[262] + x[263] + x[268] - x[269] + x[272]*b0 - x[273]*b0 - x[274]*h[1] == 0, "c92")
f.addQConstr(-x[264] + x[265] + x[270] - x[271] + x[272]*c0 - x[273]*c0 - x[274]*h[2] - y[0] == 0, "c93")
f.addConstr(-x[272] + x[273] - y[1] == 0, "c94")
f.addQConstr(x[261] - 4*x[264] + 4*x[265] + 7*x[267] + 7*x[269] + 7*x[271] + x[272]*e0 - x[273]*e0 - x[274]*h[3] - y[2] == 0, "c95")
f.addQConstr(x[276] - x[277] + x[278] - x[279] + x[280] - x[281] + x[286]*a0 - x[287]*a0 - x[288]*h[0] == 0, "c96")
f.addQConstr(-x[276] + x[277] + x[282] - x[283] + x[286]*b0 - x[287]*b0 - x[288]*h[1] == 0, "c97")
f.addQConstr(-x[278] + x[279] + x[284] - x[285] + x[286]*c0 - x[287]*c0 - x[288]*h[2] - y[3] == 0, "c98")
f.addConstr(-x[286] + x[287] - y[4] == 0, "c99")
f.addQConstr(x[275] - 4*x[278] + 4*x[279] + 7*x[281] + 7*x[283] + 7*x[285] + x[286]*e0 - x[287]*e0 - x[288]*h[3] - y[5] == 0, "c100")
f.addQConstr(x[290] - x[291] + x[292] - x[293] + x[294] - x[295] + x[300]*a1 - x[301]*a1 + x[302]*h[0] == 0, "c101")
f.addQConstr(-x[290] + x[291] + x[296] - x[297] + x[300]*b1 - x[301]*b1 + x[302]*h[1] == 0, "c102")
f.addQConstr(-x[292] + x[293] + x[298] - x[299] + x[300]*c1 - x[301]*c1 + x[302]*h[2] == 0, "c103")
f.addConstr(-x[300] + x[301] == 1, "c104")
f.addQConstr(x[289] + 4*x[292] - 4*x[293] + 7*x[295] + 7*x[297] + 7*x[299] + x[300]*e1 - x[301]*e1 + x[302]*h[3] == 0, "c105")
f.addQConstr(x[304] - x[305] + x[306] - x[307] + x[308] - x[309] + x[314]*a1 - x[315]*a1 + x[316]*h[0] == 0, "c106")
f.addQConstr(-x[304] + x[305] + x[310] - x[311] + x[314]*b1 - x[315]*b1 + x[316]*h[1] == 0, "c107")
f.addQConstr(-x[306] + x[307] + x[312] - x[313] + x[314]*c1 - x[315]*c1 + x[316]*h[2] == 0, "c108")
f.addConstr(-x[314] + x[315] == -1, "c109")
f.addQConstr(x[303] + 4*x[306] - 4*x[307] + 7*x[309] + 7*x[311] + 7*x[313] + x[314]*e1 - x[315]*e1 + x[316]*h[3] == 7, "c110")
f.addQConstr(x[318] - x[319] + x[320] - x[321] + x[322] - x[323] + x[328]*a1 - x[329]*a1 + x[330]*h[0] == 0, "c111")
f.addQConstr(-x[318] + x[319] + x[324] - x[325] + x[328]*b1 - x[329]*b1 + x[330]*h[1] == -1, "c112")
f.addQConstr(-x[320] + x[321] + x[326] - x[327] + x[328]*c1 - x[329]*c1 + x[330]*h[2] == 0, "c113")
f.addConstr(-x[328] + x[329] == 1, "c114")
f.addQConstr(x[317] + 4*x[320] - 4*x[321] + 7*x[323] + 7*x[325] + 7*x[327] + x[328]*e1 - x[329]*e1 + x[330]*h[3] - d == 0, "c115")
f.addQConstr(x[332] - x[333] + x[334] - x[335] + x[336] - x[337] + x[342]*a1 - x[343]*a1 + x[344]*h[0] == 0, "c116")
f.addQConstr(-x[332] + x[333] + x[338] - x[339] + x[342]*b1 - x[343]*b1 + x[344]*h[1] == 1, "c117")
f.addQConstr(-x[334] + x[335] + x[340] - x[341] + x[342]*c1 - x[343]*c1 + x[344]*h[2] == 0, "c118")
f.addConstr(-x[342] + x[343] == -1, "c119")
f.addQConstr(x[331] + 4*x[334] - 4*x[335] + 7*x[337] + 7*x[339] + 7*x[341] + x[342]*e1 - x[343]*e1 + x[344]*h[3] - d == 0, "c120")
f.addQConstr(x[346] - x[347] + x[348] - x[349] + x[350] - x[351] + x[356]*a1 - x[357]*a1 + x[358]*h[0] == 0, "c121")
f.addQConstr(-x[346] + x[347] + x[352] - x[353] + x[356]*b1 - x[357]*b1 + x[358]*h[1] == 0, "c122")
f.addQConstr(-x[348] + x[349] + x[354] - x[355] + x[356]*c1 - x[357]*c1 + x[358]*h[2] - z[0] == 0, "c123")
f.addConstr(-x[356] + x[357] - z[1] == 0, "c124")
f.addQConstr(x[345] + 4*x[348] - 4*x[349] + 7*x[351] + 7*x[353] + 7*x[355] + x[356]*e1 - x[357]*e1 + x[358]*h[3] - z[2] == 0, "c125")
f.addQConstr(x[360] - x[361] + x[362] - x[363] + x[364] - x[365] + x[370]*a1 - x[371]*a1 + x[372]*h[0] == 0, "c126")
f.addQConstr(-x[360] + x[361] + x[366] - x[367] + x[370]*b1 - x[371]*b1 + x[372]*h[1] == 0, "c127")
f.addQConstr(-x[362] + x[363] + x[368] - x[369] + x[370]*c1 - x[371]*c1 + x[372]*h[2] - z[3] == 0, "c128")
f.addConstr(-x[370] + x[371] - z[4] == 0, "c129")
f.addQConstr(x[359] + 4*x[362] - 4*x[363] + 7*x[365] + 7*x[367] + 7*x[369] + x[370]*e1 - x[371]*e1 + x[372]*h[3] - z[5] == 0, "c130")
f.addQConstr(x[374] - x[375] + x[376] - x[377] + x[378] - x[379] + x[384]*a1 - x[385]*a1 + x[386]*h[0] == 0, "c131")
f.addQConstr(-x[374] + x[375] + x[380] - x[381] + x[384]*b1 - x[385]*b1 + x[386]*h[1] == 0, "c132")
f.addQConstr(-x[376] + x[377] + x[382] - x[383] + x[384]*c1 - x[385]*c1 + x[386]*h[2] == 0, "c133")
f.addConstr(-x[384] + x[385] == 1, "c134")
f.addQConstr(x[373] - 4*x[376] + 4*x[377] + 7*x[379] + 7*x[381] + 7*x[383] + x[384]*e1 - x[385]*e1 + x[386]*h[3] == 0, "c135")
f.addQConstr(x[388] - x[389] + x[390] - x[391] + x[392] - x[393] + x[398]*a1 - x[399]*a1 + x[400]*h[0] == 0, "c136")
f.addQConstr(-x[388] + x[389] + x[394] - x[395] + x[398]*b1 - x[399]*b1 + x[400]*h[1] == 0, "c137")
f.addQConstr(-x[390] + x[391] + x[396] - x[397] + x[398]*c1 - x[399]*c1 + x[400]*h[2] == 0, "c138")
f.addConstr(-x[398] + x[399] == -1, "c139")
f.addQConstr(x[387] - 4*x[390] + 4*x[391] + 7*x[393] + 7*x[395] + 7*x[397] + x[398]*e1 - x[399]*e1 + x[400]*h[3] == 7, "c140")
f.addQConstr(x[402] - x[403] + x[404] - x[405] + x[406] - x[407] + x[412]*a1 - x[413]*a1 + x[414]*h[0] == 0, "c141")
f.addQConstr(-x[402] + x[403] + x[408] - x[409] + x[412]*b1 - x[413]*b1 + x[414]*h[1] == -1, "c142")
f.addQConstr(-x[404] + x[405] + x[410] - x[411] + x[412]*c1 - x[413]*c1 + x[414]*h[2] == 0, "c143")
f.addConstr(-x[412] + x[413] == 1, "c144")
f.addQConstr(x[401] - 4*x[404] + 4*x[405] + 7*x[407] + 7*x[409] + 7*x[411] + x[412]*e1 - x[413]*e1 + x[414]*h[3] - d == 0, "c145")
f.addQConstr(x[416] - x[417] + x[418] - x[419] + x[420] - x[421] + x[426]*a1 - x[427]*a1 + x[428]*h[0] == 0, "c146")
f.addQConstr(-x[416] + x[417] + x[422] - x[423] + x[426]*b1 - x[427]*b1 + x[428]*h[1] == 1, "c147")
f.addQConstr(-x[418] + x[419] + x[424] - x[425] + x[426]*c1 - x[427]*c1 + x[428]*h[2] == 0, "c148")
f.addConstr(-x[426] + x[427] == -1, "c149")
f.addQConstr(x[415] - 4*x[418] + 4*x[419] + 7*x[421] + 7*x[423] + 7*x[425] + x[426]*e1 - x[427]*e1 + x[428]*h[3] - d == 0, "c150")
f.addQConstr(x[430] - x[431] + x[432] - x[433] + x[434] - x[435] + x[440]*a1 - x[441]*a1 + x[442]*h[0] == 0, "c151")
f.addQConstr(-x[430] + x[431] + x[436] - x[437] + x[440]*b1 - x[441]*b1 + x[442]*h[1] == 0, "c152")
f.addQConstr(-x[432] + x[433] + x[438] - x[439] + x[440]*c1 - x[441]*c1 + x[442]*h[2] - z[0] == 0, "c53")
f.addConstr(-x[440] + x[441] - z[1] == 0, "c154")
f.addQConstr(x[429] - 4*x[432] + 4*x[433] + 7*x[435] + 7*x[437] + 7*x[439] + x[440]*e1 - x[441]*e1 + x[442]*h[3] - z[2] == 0, "c155")
f.addQConstr(x[444] - x[445] + x[446] - x[447] + x[448] - x[449] + x[454]*a1 - x[455]*a1 + x[456]*h[0] == 0, "c156")
f.addQConstr(-x[444] + x[445] + x[450] - x[451] + x[454]*b1 - x[455]*b1 + x[456]*h[1] == 0, "c157")
f.addQConstr(-x[446] + x[447] + x[452] - x[453] + x[454]*c1 - x[455]*c1 + x[456]*h[2] - z[3] == 0, "c158")
f.addConstr(-x[454] + x[455] - z[4] == 0, "c159")
f.addQConstr(x[443] - 4*x[446] + 4*x[447] + 7*x[449] + 7*x[451] + 7*x[453] + x[454]*e1 - x[455]*e1 + x[456]*h[3] - z[5] == 0, "c160")
f.optimize()
assert f. Status == GRB . Status . OPTIMAL
for v in f.getVars():
print(v.varName, v.x)
print('maximum distance:', f.objVal)
It is not a very big problem I think, however, I don't know why it is taking a much longer time. Could you please help me?
Thanks
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi,
Non-convex problems don't have to be large to be challenging.
I have written your problem to an \(\texttt{LP}\) file by using the Model.write() function and am referring to the variables and constraints found therein.For non-convex quadratic programs, we recommend to always provide bounds on variables occurring non-linearly in the model. In your case these, this would be variables \(\texttt{y, z, a0, b0, c0, e0, a1, b1, c1, e1, h, d}\). Moreover, it is important that these bounds are as tight as possible, e.g., for \(\texttt{Delta0[0]}\) the bounds \([-1,1]\) are valid bounds, because constraint \(\texttt{c64}\) states that \(\texttt{Delta0[0] = - x[188] + x[189]}\) and all \(x\) variables are in \([0,1]\) . This is especially important for variables for which it is not so easy for the solver to deduce valid lower and upper bound.
It may be advantageous to replace the integer variables occurring in the quadratic constraints by continuous ones. In your case this can be done for, e.g., \(\texttt{Delta0[0]}\) by replacing \(\texttt{Delta0[0]}\) by \(\texttt{- x[188] + x[189]}\) as for constraint \(\texttt{c64}\).Another idea would be to try a different formulation for your problem, in best case one with less integers and quadratic constraints. Do you know if there is any alternative formulation for your application in the literature?
Best regards,
Jaromił0 -
Respected Sir
Thank you so much for your response.
I forgot to mention that actually I want to minimize the distance d, and want to find a suitable Dalta0 and Dalta1 as well. So I can't replace it. However, I will try the problem with tight bounds for the variables you have mentioned.
Sir, geometrically my problem is a polyhedron and convex, but I am getting an error while compilation and asking to set the nonconvex parameter to 2, that's why I did that. Moreover, my problem got universal and existential quantifiers, and I have reformulated it by using Affine Form of Farkas Lemma to get a quantifier-free problem.
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.30.8036
Affine Form of Farkas Lemma is given on page 16 as Theorem 7. To apply this lemma I have to introduced 456 auxiliary variables, and due to this, I am getting a lot of bilinear terms in constraints that make this problem quadratic as well.
Presently, I don't know any other formulation. However, If I get to know some other technique to get rid of the quantifiers then this problem would be very small.
Any help in this regard will be highly appreciated.
Thanks
Umair
0 -
Dear Umair,
Ok, so you applied the Affine Form of Farkas Lemma to get rid of quantifiers and this resulted in many bilinear terms. Did you try formulating the logic quantifiers via the introduction of binary variables as recommended by Eli in your previous post?
For example, if you have a constraint like \(\exists x_i = 1, i \in\{1,2\}, x_i \in \{0,1\}\), you can reformulate it as \(x_1 + x_2 \geq 1\). Like this, you can avoid the addition of many bilinear terms, which may indeed be more complex than solving a linear integer problem of a similar size.
Best regards,
Jaromił0
Post is closed for comments.
Comments
4 comments