[英]possibles permutations between 2 list of tuples (Scheduling algoritm)
I'm trying to solve a particular problem with permutations using python.我正在尝试使用 python 解决一个特定的排列问题。
In general terms, I have a list with employees ID, a list with the shifts available and a list with the nums of days like this:一般而言,我有一个包含员工 ID 的列表、一个包含可用班次的列表以及一个包含天数的列表,如下所示:
employees = [1, 5,34,234,233,534,33,2,11,3,7,6,8]
days = [0,1,2,3,4]
shift = [0,1,2]
I do the possible permutations between these three lists using these lines of code:我使用这些代码行在这三个列表之间进行可能的排列:
lists = [days, shift, days]
Compbinations = list(itertools.product(*lists))
So far everything is fine but I have another problem... I Need to assign the possible permutations to the corresponding days based on availability.到目前为止一切都很好,但我还有另一个问题......我需要根据可用性将可能的排列分配给相应的日期。
I have this array with the availability per day per turn:我有这个数组,每回合每天可用:
Shift_Availabilities = [
(1,2,3),
(3,3,3),
(0,1,2),
(3,1,2),
(0,0,1)
]
But I don't know how I can do the possible permutations based on this constraint.但我不知道如何根据此约束进行可能的排列。
Any idea how I can do this?知道我该怎么做吗?
Thanks!谢谢!
If you have conditions to apply, step away from itertools and just make a list comprehension... they are incredibly flexible in terms of conditions, etc. This will develop "valid" assignment options based on some made up criteria.如果您有条件适用,请远离 itertools 并仅进行列表理解……它们在条件等方面非常灵活。这将根据某些组合标准开发“有效”分配选项。
emp_ids = [55, 202, 70]
days = list('MTWRF')
shifts = [1, 2, 3]
emp_avail = { 55: ['M', 'T'],
202: ['T', 'W', 'R', 'F'],
70: ['W', 'R', 'F']}
shifts_avail = {'M': [1, 2],
'T': [3],
'W': [2, 3],
'F': [1]}
poss_assignments = [(emp, day, shift)
for emp in emp_ids
for day in days
for shift in shifts
if day in emp_avail.get(emp, []) # employee avail on day
and shift in shifts_avail.get(day, [])] # shift is active on day
for asmt in poss_assignments:
print(asmt)
(55, 'M', 1)
(55, 'M', 2)
(55, 'T', 3)
(202, 'T', 3)
(202, 'W', 2)
(202, 'W', 3)
(202, 'F', 1)
(70, 'W', 2)
(70, 'W', 3)
(70, 'F', 1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.