简体   繁体   English

如何在 IBM CPLEX Python API 中编写求和

[英]How to write sumation in IBM CPLEX Python API

I am new to Cplex Python APIs, but I worked with Cplex OPL, in OPL, you can easily write this objective function Max [sum C_ij*X_ij] as:我是 Cplex Python API 的新手,但我使用过 Cplex OPL,在 OPL 中,您可以轻松地将此目标函数 Max [sum C_ij*X_ij] 编写为:

Maximize sum(i in set1,j in set2) C_ij*X_ij最大化总和(i in set1,j in set2) C_ij*X_ij

if we want to use python API, we have to define it in vector format Max C*X, which C and X are both vectors of coefficients and variables respectively.如果我们要使用python API,我们必须以向量格式Max C*X来定义它,其中C和X分别是系数和变量的向量。 So you need to make the vector format from C_ij matrix.所以你需要从 C_ij 矩阵制作矢量格式。

Is there any way to write it in matrix format like what we do in OPL?有没有办法像我们在 OPL 中所做的那样以矩阵格式编写它?

The CPLEX Python API does not support this, but the DOcplex Modeling for Python API is similar to OPL. CPLEX Python API不支持此功能,但Python APIDOcplex 建模类似于 OPL。 For a quick start to the later see the Creating a MP model in a nutshell page, and Model.sum in the reference manual.要快速开始后面的内容,请参阅简明页面中的创建 MP 模型和参考手册中的Model.sum

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

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