Originally posted by: LeandroCC
Hello all,
I want to add a quadratic term to the objective function. Let Q be a matrix of coefficients, and x be my binary variables:
I would need something like
//quadratic cost
for(int i = 1; i < n + 1; ++i)
for(int j = 1; j < m + 1; ++j)
for (int k=1; k < n+1; ++k)
for(int l = 1; l < m+1; ++l)
objexpr += Q[i][j][k][l] * x[i][j] * x[k][l];
I can then do a
IloObjective obj(env, objexpr);
But when I do
model.add(obj);
Then CPLEX stays for over one hour on the normalize() function (as seem from my debugger).
I tried simplifying things a bit by changing my loops to
//quadratic cost
for(int i = 1; i < n + 1; ++i)
for(int j = 1; j < m + 1; ++j)
for (int k=i+1; k < n+1; ++k)
for(int l = 1; l < m+1; ++l)
if ( l!=j )
objexpr += ( Q[i][j][k][l] + Q[k][l][i][j]) * x[i][j] * x[k][l];
but it didnt help at all. For what matters, the sizes of n and m range around 50.
Any help is much appreciated. Thanks!
#CPLEXOptimizers#DecisionOptimization