I'm using CPLEX 12.5.0.0 via the C# API.
Until now, I've never had a situation with an objective with a constant term - only constraints. With constraints, I have always been able to re-arrange the equation so the constant is always on one side, meaning each ILinearNumExpr
has no constant term on its own.
Now I have a quadratic programming problem, with an objective of the following type:
MAX Z =
c[1,2] * a[1] * a[2] - c[1,2] * (1 - a[1] * a[2]) +
c[1,3] * a[1] * a[3] - c[1,2] * (1 - a[1] * a[3]) +
c[2,3] * a[2] * a[3] - c[2,2] * (1 - a[2] * a[3])
c[,] is a constant, symmetric cost matrix. a[i] are binary variables.
So looking at the left halves of the 3 lines above, having both a[i] and a[j] together will contribute c[i,j] to the objective value. This is what is currently implemented, tested, and working.
I want to modify the objective so that, if a[i] and a[j] are not both equal to 1, rather than not contributing c[i,j] to the objective value, it will subtract it.
Now, I've looked up the CPLEX documentation (the authors of which are apparently allergic to providing clear explanations or examples), and there appears to be an ILinearNumExpr.Constant
property that allows me to set a constant for a given expression.
When I tried to modify my code with IQuadNumExpr
, I noticed it doesn't have that .Constant
property.
Is there any way to add constant terms to a quadratic objective function in CPLEX?