使用lpSum时,PuLP简单问题显示为“未解决”

时间:2019-04-16 16:02:50

标签: python linear-programming pulp

我有以下程序,使用PuLP不能解决:

emp_name = input("gimmie name: ") # Weiss

idx = name.index(emp_name) # 99% of the work is done right here.

print('{n} worked {h} hours at ${w:.2f} per hour, and earned ${p:.2f}'.format(
    n = name[idx], 
    h = hours[idx],
    w = float(wage[idx]), # Convert to float so you can show 2 decimals for currency
    p = float(wage[idx]) * hours[idx] # Calculate pay here
))

#Weiss worked 38.0 hours at $14.80 per hour, and earned $562.40

我删除了约束以简化问题,所以我们的想法是最大化功能
a0 * b0 + a1 * b1 + a2 * b2
并且由于变量的上界为1,因此解决方案应该为(a0 = 1,a1 = 1,a2 = 1),但是找不到。

当我尝试解决它时:

prob = LpProblem("Risk Decision",LpMaximize)

x = np.arange(3)
n = len(x)

a = pulp.LpVariable.dicts('a', x, lowBound=0, upBound=1, cat='Continuous')
b = np.array([1, 2, 3])

prob += lpSum([a[i]*b[i] for i in range(n)]), "Expected Utility"

它作为未解决。 我在做什么错了?

0 个答案:

没有答案