纸浆溶液
经过研究,我认为你的目标函数不是线性的。我在Pythonpulp库中重新创建了这个问题,但是pulp不喜欢我们用float和'LpAffineExpression'分隔。This answer表明线性规划“不理解划分”,但该注释是在添加约束的上下文中,而不是在目标函数中。那条评论把我指向了“Mixed Integer Linear Fractional Programming (MILFP)”和Wikipedia。
如果它真的起作用了(也许有人能弄清楚原因),你可以用纸浆来做:import pulp
data = [(481.79, 5), (412.04, 4), (365.54, 3)] #, (375.88, 3), (379.75, 3), (632.92, 5), (127.89, 1), (835.71, 6), (200.21, 1)]
x = pulp.LpVariable.dicts('x', range(len(data)), lowBound=0, upBound=7, cat=pulp.LpInteger)
numerator = dict((i,tup[0]) for i,tup in enumerate(data))
denom_int = dict((i,tup[1]) for i,tup in enumerate(data))
problem = pulp.LpProblem('Mixed Integer Linear Programming', sense=pulp.LpMinimize)
# objective function (doesn't work)
# TypeError: unsupported operand type(s) for /: 'float'