Я хотел бы оптимизировать следующий код, но я получаю ошибку следующим образом, касающуюся 4-й строки в ограничениях (я думаю). Любая помощь будет очень признателен, спасибо:
model += A[i] == min(P[i], C[i])
TypeError: '<' not supported between instances of 'int' and 'LpVariable'
P0 = [[1,0,4],[2,0,3],[4,6,2],[5,2,1],[1,0,0]]
x = [2,3,0]
xMax = [14,12,13]
C = [122, 99, 158, 37, 44]
# Instantiate our problem class
model = pulp.LpProblem("Clem", pulp.LpMaximize)
# Construct our decision variable lists
x = pulp.LpVariable.dicts('pInstal', (i for i in range(3)), lowBound = 0, cat = 'Continuous')
tx = pulp.LpVariable('tauxAutoconso', 0)
for i in range(5):
P = pulp.LpVariable.dicts('vectProduction',(i for i in range(5)), lowBound = 0, cat = 'Continuous')
A = pulp.LpVariable.dicts('vectAutoConso',(i for i in range(5)), lowBound = 0, cat = 'Continuous')
# Objective Function
model += tx
# Constraints
for i in range(3):
model += x[i] <= xMax[i]
for i in range(5):
model += P[i] == sum([P0[i][j] * x[j] for j in range(3)])
model += A[i] == min(P[i], C[i])
model += tx == sum(A) / sum(P)
model += sum(x) == sum(C)
# Solve our problem
if pulp.LpStatus[model.status] != 'Optimal':
print('Solution qualité :', pulp.LpStatus[model.status])