我正在研究最初在PuLP
. 然而,在开发过程中,一些约束以及目标变得非线性。在比较了一些包之后,我选择了GEKKO,但不知何故无法启动并运行我的优化。
我面临两个问题:
1. 约束制定
假设我有像这样的简单约束。
在PuLP
我有类似的东西:
# Each position p must be assigned to exactly one employee e
for p in position_names:
succession_prob += pulp.lpSum([X[p][e] for e in employee_names]) == 1
# Only employees e that are qualified for position p can be selected
for p in position_names:
for e in employee_names:
succession_prob += X[p][e] <= position_mapping[p][e]
我试图做这样的事情GEKKO
:
# Each position p must be assigned to exactly one employee e
for p in range(len(position_names)):
m.Equation(sum(X[p][e] for e in range(len(employee_names))) == 1)
# Only employees e that are qualified for position p can be selected
for p in range(len(position_names)):
for e in range(len(employee_names)):
m.Equation(X[p][e] <= position_mapping.iloc[e][p])
这不会给我一个错误,但我不确定它是否正确。但是,当我尝试拆分(相当复杂的)目标函数时出现错误:
2.分割目标函数
# Dummy functions
numerator = pulp.lpSum(some expression)
denominator = pulp.lpSum(some other expression)
succession_prob += numerator / denominator
我再次尝试做这样的事情GEKKO
:
numerator = m.Param(some expression)
denominator = m.Param(some other expression)
# Objective function: RCD moves -> max
m.Obj((numerator / denominator)*(-1))
>>> ERROR: unsupported operand type(s) for *: 'float' and 'generator'
我想知道我的约束代码是否正确(变量类型的选择等),以及如何修复拆分目标。我很感激任何帮助,因为我已经尝试了不同的变量并且无法运行。