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

How to write sumation in IBM CPLEX Python API

我是 Cplex Python APIs 的新手,但我使用 Cplex OPL,在 OPL 中,您可以轻松编写此 objective 函数 Max [sum C_ij*X_ij] 为:

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

如果我们要使用python API,我们必须以向量格式Max C*X来定义它,其中C和X分别是系数和变量的向量。所以你需要从 C_ij 矩阵制作矢量格式。

有没有办法像我们在 OPL 中那样以矩阵格式编写它?

参考手册中的CPLEX Python API does not support this, but the DOcplex Modeling for Python API is similar to OPL. For a quick start to the later see the Creating a MP model in a nutshell page, and Model.sum