我有一个脚本,它根据Y数量的限制,在一个24/7的花名册中安排X数量的工人。输出是每个工人每天重复的24小时计划
当前的限制包括在机器上连续工作的最大小时数、每天在机器上工作的最大累计小时数、最大工作时间(机器上的小时数+工作休息时间)
我的问题是如何引入一个约束,限制每48小时(或两天)在机器上工作的累计小时数,并在每六天之后引入一个强制休息日
//these are the current parameters
param1 = {
"nWorkers": 9, //no. of workers
"nHours":24, //no. of hours in a day
"maxContinuousOnMachine": 2, //consecutive onMachine
"maxMachineHours": 6, //cumulative onMachine per day
"maxHoursAtWork": 8 //onMachine+Breaks during Wrok
}
params.append(param1)
//below are functions that shows how the constraints are currently executed
def start_end(worker):
start, end = -1,-1
for i in range(len(worker)):
if worker[i] == 1:
start = i
break
for i in reversed(range(len(worker))):
if worker[i] == 1:
end = i
break
return start, end
def max_consec(worker, maxContinuousOnMachine):
consec = 0
for i in range(len(worker)):
if worker[i]:
consec +=1
else:
consec = 0
if consec > maxContinuousOnMachine:
logging.info("fail in maxContinuousOnMachine")
return False
return True
def max_presence(worker, maxHoursAtWork):
start, end = start_end(worker)
logging.info("Start: %s End: %s", str(start), str(end))
if end - start + 1 > maxHoursAtWork:
logging.info("fail in maxHoursAtWork")
return False
return True
def max_hours(worker, maxMachineHours, maxHoursAtWork):
if sum(worker) > maxMachineHours:
return False
start, end = start_end(worker)
logging.info("Start: %s End: %s", str(start), str(end))
if end - start > math.ceil(maxMachineHours + maxHoursAtWork*0.2):
logging.info("fail in maxMachineHours")
return False
return True
# check that the worker can work in the new hour and all constraints are satisfied.
def can_work(worker, hour, constraints):
if worker[hour] == 1:
return False
worker[hour] = 1
if not max_consec(worker, constraints["maxContinuousOnMachine"]) or not max_presence(worker, constraints["maxHoursAtWork"]) or \
not max_hours(worker, constraints["maxMachineHours"], constraints["maxHoursAtWork"]) or not consec_and_rest(worker, constraints["maxContinuousOnMachine"]):
return False
return True
目前没有回答
相关问题 更多 >
编程相关推荐