使用 Pulp 在 Optimization 中给出约束

Giving constraints in Optimization using Pulp

我目前正在 Python 中使用 Pulp 模块解决优化问题。我想将我的变量设置为 7500.So 的整数倍 我创建了一个如下所示的约束,但它显示错误。

import pandas as pd
import numpy as np
from pulp import *

prob = LpProblem('Cost minimization' , LpMinimize)
X = LpVariable.dicts('',tsap.varName, lowBound=0, upBound=None,     cat=LpInteger)
prob += lpSum( X[i] * j for i,j in zip(tsap.varName, tsap.coeff)),'Total cost'

l=7500

for i in X:
prob += i % l == 0

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-9-73548ad8b39f> in <module>()
        1 for i in X:
  ----> 2     prob += i % l == 0
        3 

TypeError: not all arguments converted during string formatting

有什么方法可以达到预期的目标吗?

您不能在 pulp 中使用模运算符,因为那样会成为非线性问题。

但是,简单的解决方案是保持 X[i] 整数,然后在约束中使用 7500*X[i] 并相应地报告解决方案。