Переменные решения (x1, x2, ..., x8) в приведенном ниже коде являются повторяющимися, которые я хочу повторить, и поэтому я хочу знать, как будут изменены уравнения ограничения 1, 2, 3 и целевая функция. Я попытался перебрать параметр EH, и с этим код в настоящее время работает нормально, но я хочу убедиться, что это правильно, или мне нужно что-то там изменить. Спасибо
import time
start_time = time.time()
from pulp import *
from openpyxl import load_workbook
N=8
Time=16
Days=7
I=list(range(Days))
J=list(range(Time))
wb1=load_workbook(filename= 'Employer Interface.xlsx')
wse=wb1['Sheet1']
MH=[[0 for j in range(Time)] for i in range(Days)]
for i in range(Days):
for j in range(Time):
MH[i][j]=wse.cell(row=i+3, column=j+3).value
wb2=load_workbook(filename= 'Employee Interface.xlsx')
def employeeIF(sheet):
return wb2.worksheets[sheet]
EH=[[0 for j in range(Time)] for i in range(Days)]
def EH(eh):
for eh in list(range(1,9,1)):
for i in range(Days):
for j in range(Time):
return employeeIF(eh-1).cell(row=i+3, column=j+3).value
prob= LpProblem("EL-NR", LpMinimize)
x1= LpVariable.matrix("x1", (I,J), 0, 1, LpBinary)
x2= LpVariable.matrix("x2", (I,J), 0, 1, LpBinary)
x3= LpVariable.matrix("x3", (I,J), 0, 1, LpBinary)
x4= LpVariable.matrix("x4", (I,J), 0, 1, LpBinary)
x5= LpVariable.matrix("x5", (I,J), 0, 1, LpBinary)
x6= LpVariable.matrix("x6", (I,J), 0, 1, LpBinary)
x7= LpVariable.matrix("x7", (I,J), 0, 1, LpBinary)
x8= LpVariable.matrix("x8", (I,J), 0, 1, LpBinary)
prob+= lpSum([lpSum([x1[i][j]*EH(1) for j in J]) for i in I])+\
lpSum([lpSum([x2[i][j]*EH(2) for j in J]) for i in I])+\
lpSum([lpSum([x3[i][j]*EH(3) for j in J]) for i in I])+\
lpSum([lpSum([x4[i][j]*EH(4) for j in J]) for i in I])+\
lpSum([lpSum([x5[i][j]*EH(5) for j in J]) for i in I])+\
lpSum([lpSum([x6[i][j]*EH(6) for j in J]) for i in I])+\
lpSum([lpSum([x7[i][j]*EH(7) for j in J]) for i in I])+\
lpSum([lpSum([x8[i][j]*EH(8) for j in J]) for i in I]) #Objective Function
for i in I:
for j in J:
prob+=MH[i][j]==x1[i][j]*EH(1)+\
x2[i][j]*EH(2)+x3[i][j]*EH(3)+\
x4[i][j]*EH(4)+x5[i][j]*EH(5)+\
x6[i][j]*EH(6)+x7[i][j]*EH(7)+x8[i][j]*EH(8) #First constraint
prob+=lpSum([lpSum([x1[i][j] for j in J]) for i in I])<=37.5 #Second constraint
prob+=lpSum([lpSum([x2[i][j] for j in J]) for i in I])<=37.5 #Second constraint
prob+=lpSum([lpSum([x3[i][j] for j in J]) for i in I])<=37.5 #Second constraint
prob+=lpSum([lpSum([x4[i][j] for j in J]) for i in I])<=37.5 #Second constraint
prob+=lpSum([lpSum([x5[i][j] for j in J]) for i in I])<=37.5 #Second constraint
prob+=lpSum([lpSum([x6[i][j] for j in J]) for i in I])<=37.5 #Second constraint
prob+=lpSum([lpSum([x7[i][j] for j in J]) for i in I])<=37.5 #Second constraint
prob+=lpSum([lpSum([x8[i][j] for j in J]) for i in I])<=37.5 #Second constraint
for i in I:
for j in J:
prob+=EH(1)>=x1[i][j] #Third constraint
prob+=EH(2)>=x2[i][j] #Third constraint
prob+=EH(3)>=x3[i][j] #Third constraint
prob+=EH(4)>=x4[i][j] #Third constraint
prob+=EH(5)>=x5[i][j] #Third constraint
prob+=EH(6)>=x6[i][j] #Third constraint
prob+=EH(7)>=x7[i][j] #Third constraint
prob+=EH(8)>=x8[i][j] #Third constraint
prob.solve()
print(prob.objective.value())