Is there a way to get the product of two different decision variables in cplex java and add it to an objective function?
Ex.
decision variable -> x[i]
decision variable -> y[j]
-> x[i]*y[j]
Such a multiplikation should be possible, since it is still linear right?
Thanks to
@TimChippingtonDerrick ( https://stackoverflow.com/users/2108433/timchippingtonderrick )
and
@rkersh ( https://stackoverflow.com/users/1718477/rkersh )
I have found the answer to my problem.
At first such an objective function is not linear. This is the reason why for example
IloLinearNumExpr expressionName = cplex.linearNumExpr(); expressionName.addTerm(x[i],y[j]);
will not work, since such a multiplication is not being supported in a linear model. Only a variable with a coefficient can be added to such a linear expression.
For the second part, through the example provided by Cplex QPex1.java
I could write the product of two decision variables and add them to an objective function as in the following example:
IloNumExpr objective = cplex.numExpr();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
objective = cplex.sum(objective,cplex.prod(y[i], z[j][i]));
}
}
cplex.addMinimize(objective);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.