Constraint programming in CPLEX Python - logical expr

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值