简体   繁体   English

两个决策变量的Java Cplex乘积

[英]Java Cplex Product of two Decision Variables

Is there a way to get the product of two different decision variables in cplex java and add it to an objective function? 有没有办法在cplex java中获得两个不同决策变量的乘积并将其添加到目标函数中?

Ex. 防爆。

decision variable -> x[i] 决策变量-> x [i]

decision variable -> y[j] 决策变量-> y [j]

-> x[i]*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 ) @TimChippingtonDerrick( https://stackoverflow.com/users/2108433/timchippingtonderrick

and

@rkersh ( https://stackoverflow.com/users/1718477/rkersh ) @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 对于第二部分,通过Cplex QPex1.java提供的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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM