Logical expressions in CPLEX
Learn logical expressions from docplex.cp.modeler:
http://ibmdecisionoptimization.github.io/docplex-doc/cp/docplex.cp.modeler.py.html
Use logical_and to express “if”:
ct = modeler.logical_and(xr <= modeler.element(temp_a, xd), modeler.element(temp_a, xd) != -1)
cplex_model.add(ct)
Remember to use modeler.xxx to override the python function
For example, if you want to find the minimum of two expressions, do not use “min” but instead “modeler.min”, which takes an array as input.
In the example below, temp_obj_expr is the objective function. xl and xu are decision variables, and the others are data.
The right way:

本文介绍了如何在CPLEX Python中利用docplex(cp.modeler)库来表达逻辑条件,特别是使用logical_and来表示'if'条件。强调在使用时要通过modeler.xxx来覆盖Python内置函数,例如,用modeler.min替代Python的min函数来寻找两个表达式的最小值。文中给出了正确和错误的示例,涉及目标函数temp_obj_expr以及决策变量xl和xu。
最低0.47元/天 解锁文章
712

被折叠的 条评论
为什么被折叠?



