代码拉取完成,页面将自动刷新
from typing import List, Set, Dict
#others
#ctrl+k &(ctrl+0 or ctrl+J)
#pyinstaller --onefile --windowed --icon=show.ico main.py
#pyinstaller --windowed --icon=mlogo.ico main.py
#pyrcc5 -o resources.py resource.qrc
# 检查员类
class People:
def __init__(self,name: str,masters: Set[str],nob: str,area: str,area2: Set[str],be_leader: int,had_work: int,max_time:int):
self.name = name # 姓名
self.masters = masters # 专业代码集合
self.nob = nob # 能力等级 A, B, C
self.area = area # 所在区域 1-10
self.area2 = area2 # 所在执行区域
self.be_leader = be_leader # 担任组长数
self.had_work = had_work # 分配到工厂检查的次数
self.max_time=max_time #最多分配的次数
# 工厂类
class Factory:
def __init__(
self, tasknum: str,fac_num:str,fac_name:str, masters: Set[str], leader: str, members: List[str], farea: str,people_num:int):
self.tasknum = tasknum # 任务编号
self.fac_num=fac_num #工厂编号
self.fac_name=fac_name #工厂名称
self.masters = masters # 任务专业代码集合
self.leader = leader # 检查组长 A 或 B
#self.members = members # 检查组员
self.farea = farea # 工厂所在区域
self.people_num=people_num #人日数
self.members = members if isinstance(members, list) else [] # 确保是列表
# 组队信息
class Team:
def __init__(self,masters: Set[str],leader: str,members: List[str],Tarea: Set[str],time: int,hadfactories: Set[str],):
self.masters = masters # 两个人的专业代码集合
self.leader = leader # 检查组长 A 或 B
self.members = members # 检查组员
self.Tarea = Tarea # 所在执行区域的集合
self.time = time # 相同组员组长被分配任务的次数
self.hadfactories = hadfactories # 任务编号的存储
# 输出结果的集合类
class Output:
def __init__(
self,
opFactoryTaskNum: int,
dealTaskNum:int,
opMaxFactoryMajor: int,
opPeopleNum: int,
opPeopleANum: int,
opPeopleBNum: int,
opPeopleCNum: int,
opPeopleMajorNum: Dict[str, int],
opMaxFactoryArea: Dict[str, int],
opPeopleAreaNum: Dict[str, int],
opTeam: List[Team],
):
self.opFactoryTaskNum = opFactoryTaskNum # 总的工厂任务数
self.dealTaskNum=dealTaskNum #成功分配的任务数
self.opMaxFactoryMajor = opMaxFactoryMajor # 工厂所需最多的专业
self.opPeopleNum = opPeopleNum # 输入的总人数
self.opPeopleANum = opPeopleANum # 传入能力为A的人数
self.opPeopleBNum = opPeopleBNum # 传入能力为B的人数
self.opPeopleCNum = opPeopleCNum # 传入能力为C的人数
self.opMaxFactoryArea = opMaxFactoryArea # {区域代码: 工厂数}
self.opPeopleMajorNum = opPeopleMajorNum # {'专业代码': 人数}
self.opPeopleAreaNum = opPeopleAreaNum # {区域代码: 人数}
self.opTeam = opTeam
# """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""##""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""##""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""#
# """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""##""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""##""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""#
# 判断一组检查员是否能覆盖任务的所有专业代码
def can_cover(team: List[People], task_masters: Set[str]) -> bool:
covered_masters = set()
for p in team:
covered_masters.update(p.masters) # 合并 team 中每个检查员的专业代码集合
return task_masters.issubset(covered_masters) # 判断是否所有任务专业代码都被覆盖
# """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""##""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""##""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""#
def find_existing_team_more_members(assigned_teams, leader_name, member_names):
for team in assigned_teams:
# 检查 leader 是否相同,并确保 members 集合匹配
if team.leader == leader_name and set(team.members) == set(member_names):
return team
return None
'''
def find_existing_team(assigned_teams, leader_name, member_names):
member_names_set = set(member_names) # 将要匹配的成员列表转换为集合
for team in assigned_teams:
# 检查 team 的 leader 是否匹配并且成员集合是否完全相同
if team.leader == leader_name and set(team.members) == member_names_set:
return team
return None
# 检查是否已有相同 team
def find_existing_team(assigned_teams: List[Team], leader: str, member: str) -> Team:
for team in assigned_teams:
if team.leader == leader and member in team.members:
return team
return None
'''
def assign_tasks(
factories: List[Factory], people: List[People], assigned_teams: List[Team]
) -> List[Factory]:
# 前置条件:如果 factory 的专业代码为空,则跳过分配
for factory in factories:
if factory.people_num == 1:
if not factory.masters:
continue
# 筛选符合专业代码、剩余分配次数 > 0 的候选人
candidates = [p for p in people if factory.masters.issubset(p.masters) and (p.max_time - p.had_work) > 0 and not p.nob=='C']
# 对候选人排序,按等级(A > B > C)、区域匹配、剩余分配次数优先级排序
candidates.sort(
key=lambda x: (
x.nob == 'A', # 等级 A 优先
x.nob == 'B', # 等级 B 次之
x.area == factory.farea, # 区域匹配优先
x.max_time - x.had_work # 剩余分配次数从高到低
),
reverse=True
)
if candidates:
leader = candidates[0]
existing_team = find_existing_team_more_members(assigned_teams, leader.name, "")
if existing_team:
# 如果已存在团队,更新任务编号和分配次数
existing_team.hadfactories.add(factory.tasknum)
existing_team.time += 1
else:
# 创建一个新团队,仅设置 leader,无需 members
new_team = Team(
masters=leader.masters,
leader=leader.name,
members=[], # members 与 leader 无关,保持为空
Tarea={factory.farea},
time=1,
hadfactories={factory.tasknum}
)
assigned_teams.append(new_team)
# 更新检查员的分配情况
leader.had_work += 1
leader.be_leader += 1
factory.leader = leader.name # 记录组长信息
if factory.people_num > 1:
#当大于2时
if factory.leader and factory.members:
continue
candidatesC = [[], [], []] # C 级候选人作为组员
candidatesA = [[], [], []] # A 级候选人作为组长
candidatesB = [[], [], []] # B 级候选人作为组长
# 1. 分类候选人
for p in people:
if p.nob == "C":
if p.area == factory.farea:
candidatesC[2].append(p)
elif factory.farea in p.area2:
candidatesC[1].append(p)
else:
candidatesC[0].append(p)
elif p.nob == "A":
if p.area == factory.farea:
candidatesA[2].append(p)
elif factory.farea in p.area2:
candidatesA[1].append(p)
else:
candidatesA[0].append(p)
elif p.nob == "B":
if p.area == factory.farea:
candidatesB[2].append(p)
elif factory.farea in p.area2:
candidatesB[1].append(p)
else:
candidatesB[0].append(p)
# 2. 存储所有可能的组合结果
result = []
# 定义用于将组合存入 result 的函数
def store_combination(leader: People, member: People):
team = [leader, member]
if can_cover(team, factory.masters) and not leader.had_work>=leader.max_time and not member.had_work>=member.max_time :
result.append((leader, member))
def assign_task_from_result(result, factory):
if result:
# 根据剩余最大值排序
result.sort(key=lambda pair: pair[0].max_time-pair[0].had_work + pair[1].max_time-pair[1].had_work)
#result.sort(key=lambda pair: pair[0].had_work + pair[1].had_work)
# 选择组合中的 leader 和 member
selected_leader, selected_member = result[0]
factory.leader = selected_leader.name
factory.members.append(selected_member.name)
# 更新人员的组长和工作次数
selected_leader.be_leader += 1
selected_leader.had_work += 1
selected_member.had_work += 1
if factory.people_num==3 or factory.people_num==4:
return True
# 查找是否已有相同的 team
existing_team = find_existing_team_more_members(
assigned_teams, selected_leader.name, selected_member.name
)
if existing_team:
# 如果已有相同的 team,则增加 time
existing_team.time += 1
existing_team.hadfactories.add(factory.tasknum)
# existing_team.Tarea.append(factory.farea)
existing_team.Tarea = sorted(
#set(map(str, existing_team.Tarea + [factory.farea]))
set(map(str, existing_team.Tarea + [factory.farea]))
)
else:
# 如果没有相同的 team,则创建新的 Team 对象
new_team = Team(
# masters=selected_leader.masters.union(selected_member.masters), #farea={factory.farea},
# 直接按照字符串进行排序# 这里是排序后的 masters 集合
masters=sorted(
map(
str,
selected_leader.masters.union(selected_member.masters),
)
),
leader=selected_leader.name,
members=[selected_member.name],
Tarea=sorted(
map(
str,
#selected_leader.area2.union(selected_member.area2),
[factory.farea],
)
),
time=1, # 新创建的 team 初始次数为 1
# Tarea={factory.farea},
hadfactories={factory.tasknum},
)
# 将 team 存入已分配的队伍列表中
assigned_teams.append(new_team)
return True # 表示成功找到并分配了任务
return False # 表示没有找到合适的组合
def assign_task_from_result1(result, factory,num):
if result:
# 根据 had_work 最大值排序
result.sort(key=lambda pair: max(pair[0].max_time - pair[0].had_work, pair[1].max_time - pair[1].had_work))
#result.sort(key=lambda pair: pair[0].had_work + pair[1].had_work)
# 选择组合中的 leader 和 member
selected_leader, selected_member = result[0]
factory.leader = selected_leader.name
if not num==2:
factory.members.append(selected_member.name)
# 更新人员的组长和工作次数
selected_leader.be_leader += 1
selected_leader.had_work += 1
selected_member.had_work += 1
if factory.people_num==3 or factory.people_num==4:
return True
# 查找是否已有相同的 team
existing_team = find_existing_team_more_members(
assigned_teams, selected_leader.name, selected_member.name
)
if existing_team:
# 如果已有相同的 team,则增加 time
existing_team.time += 1
existing_team.hadfactories.add(factory.tasknum)
# existing_team.Tarea.append(factory.farea)
existing_team.Tarea = sorted(
#set(map(str, existing_team.Tarea + [factory.farea]))
set(map(str, existing_team.Tarea + [factory.farea]))
)
else:
# 如果没有相同的 team,则创建新的 Team 对象
new_team = Team(
# masters=selected_leader.masters.union(selected_member.masters), #farea={factory.farea},
# 直接按照字符串进行排序# 这里是排序后的 masters 集合
masters=sorted(
map(
str,
selected_leader.masters.union(selected_member.masters),
)
),
leader=selected_leader.name,
members=[selected_member.name],
Tarea=sorted(
map(
str,
#selected_leader.area2.union(selected_member.area2),
[factory.farea],
)
),
time=1, # 新创建的 team 初始次数为 1
# Tarea={factory.farea},
hadfactories={factory.tasknum},
)
# 将 team 存入已分配的队伍列表中
assigned_teams.append(new_team)
return True # 表示成功找到并分配了任务
return False # 表示没有找到合适的组合
def find_person_by_name(name: str, people: List[People]) -> People:
for person in people:
if person.name == name:
return person
return None # 如果没找到对应的名字,可以返回 None 或抛出异常
def find_peoplelist_by_names(names: List[str], people: List[People]) -> List[People]:
result = []
for name in names:
person = find_person_by_name(name, people)
if person:
result.append(person)
return result
if not factory.leader and factory.members:
members_obj = find_peoplelist_by_names(factory.members, people) # 将成员名字转换为 People 对象
for member in members_obj:
if member.nob=="C":
for a in candidatesA[2]:
store_combination(a, member) # 现在传入的是 People 对象
if assign_task_from_result1(result, factory,2):
continue # 如果成功分配,继续下一个循环
for b in candidatesB[2]:
store_combination(b, member) # 现在传入的是 People 对象
if assign_task_from_result1(result, factory,2):
continue # 如果成功分配,继续下一个循环
for a in candidatesA[1]:
store_combination(a,member)
if assign_task_from_result1(result, factory,2):
continue # 如果成功分配,继续下一个循环
for b in candidatesB[1]:
store_combination(b,member)
if assign_task_from_result1(result, factory,2):
continue # 如果成功分配,继续下一个循环
for a in candidatesA[0]:
store_combination(a,member)
if assign_task_from_result1(result, factory,2):
continue # 如果成功分配,继续下一个循环
for b in candidatesB[0]:
store_combination(b,member)
if assign_task_from_result1(result, factory,2):
continue # 如果成功分配,继续下一个循环
if member.nob=="B":
for a in candidatesA[2]:
store_combination(a, member) # 现在传入的是 People 对象
if assign_task_from_result1(result, factory,2):
continue # 如果成功分配,继续下一个循环
for a in candidatesA[1]:
store_combination(a,member)
if assign_task_from_result1(result, factory,2):
continue # 如果成功分配,继续下一个循环
for a in candidatesA[0]:
store_combination(a,member)
if assign_task_from_result1(result, factory,2):
continue # 如果成功分配,继续下一个循环
if member.nob=="A":
for b in candidatesB[2]:
store_combination(b, member) # 现在传入的是 People 对象
if assign_task_from_result1(result, factory,2):
continue # 如果成功分配,继续下一个循环
for b in candidatesB[1]:
store_combination(b,member)
if assign_task_from_result1(result, factory,2):
continue # 如果成功分配,继续下一个循环
for b in candidatesB[0]:
store_combination(b,member)
if assign_task_from_result1(result, factory,2):
continue # 如果成功分配,继续下一个循环
elif not factory.members and factory.leader :
#查找对应的组长信息
leader_obj = find_person_by_name(factory.leader, people)
#遍历组员
for c in candidatesC[2]:
#查看组长和组员是否符合要求
store_combination(leader_obj, c)
if assign_task_from_result1(result, factory,1):
continue # 如果成功分配,继续下一个循环
for c in candidatesC[1]:
store_combination(leader_obj, c)
if assign_task_from_result1(result, factory,1):
continue # 如果成功分配,继续下一个循环
for c in candidatesC[0]:
store_combination(leader_obj, c)
if assign_task_from_result1(result, factory,1):
continue # 如果成功分配,继续下一个循环
if leader_obj.nob =="A":
for b in candidatesB[2]:
store_combination(leader_obj, b)
if assign_task_from_result1(result, factory,1):
continue # 如果成功分配,继续下一个循环
for b in candidatesB[1]:
store_combination(leader_obj, b)
if assign_task_from_result1(result, factory,1):
continue # 如果成功分配,继续下一个循环
for b in candidatesB[0]:
store_combination(leader_obj, b)
if assign_task_from_result1(result, factory,1):
continue # 如果成功分配,继续下一个循环
elif leader_obj.nob =="B":
for a in candidatesA[2]:
store_combination(leader_obj, a)
if assign_task_from_result1(result, factory,1):
continue # 如果成功分配,继续下一个循环
for a in candidatesA[1]:
store_combination(leader_obj, a)
if assign_task_from_result1(result, factory,1):
continue # 如果成功分配,继续下一个循环
for a in candidatesA[0]:
store_combination(leader_obj, a)
if assign_task_from_result1(result, factory,1):
continue # 如果成功分配,继续下一个循环
else :
# 使用新方法重构原有逻辑
# A[2] 和 C[2] 组合
for a in candidatesA[2]:
for c in candidatesC[2]:
store_combination(a, c)
# B[2] 和 C[2] 组合
for b in candidatesB[2]:
for c in candidatesC[2]:
store_combination(b, c)
# 如果找到合适的组合,选择分配任务
if assign_task_from_result(result, factory):
continue # 如果成功分配,继续下一个循环
# 3 A[2] 和 C[1] 组合
for a in candidatesA[2]:
for c in candidatesC[1]:
store_combination(a, c)
# 4 A[1] 和 C[2] 组合
for a in candidatesA[1]:
for c in candidatesC[2]:
store_combination(a, c)
# 5 B[2] 和 C[1] 组合
for b in candidatesB[2]:
for c in candidatesC[1]:
store_combination(b, c)
# 6 B[1] 和 C[2] 组合
for b in candidatesB[1]:
for c in candidatesC[2]:
store_combination(b, c)
# 检查并分配任务
if assign_task_from_result(result, factory):
continue
# 7 A[2] 和 C[0] 组合
for a in candidatesA[2]:
for c in candidatesC[0]:
store_combination(a, c)
# 8 B[2] 和 C[0] 组合
for b in candidatesB[2]:
for c in candidatesC[0]:
store_combination(b, c)
# 9 B[0] 和 C[2] 组合
for b in candidatesB[0]:
for c in candidatesC[2]:
store_combination(b, c)
# 10 A[0] 和 C[2] 组合
for a in candidatesA[0]:
for c in candidatesC[2]:
store_combination(a, c)
# 11 A[1] 和 C[1] 组合
for a in candidatesA[1]:
for c in candidatesC[1]:
store_combination(a, c)
# 12 B[1] 和 C[1] 组合
for b in candidatesB[1]:
for c in candidatesC[1]:
store_combination(b, c)
# 再次检查并分配任务
if assign_task_from_result(result, factory):
continue
# 13 A[1] 和 C[0] 组合
for a in candidatesA[1]:
for c in candidatesC[0]:
store_combination(a, c)
# 14 B[1] 和 C[0] 组合
for b in candidatesB[1]:
for c in candidatesC[0]:
store_combination(b, c)
# 15 A[0] 和 C[1] 组合
for a in candidatesA[0]:
for c in candidatesC[1]:
store_combination(a, c)
# 16 B[0] 和 C[1] 组合
for b in candidatesB[0]:
for c in candidatesC[1]:
store_combination(b, c)
# 再次检查并分配任务
if assign_task_from_result(result, factory):
continue
# 17 A[0] 和 C[0] 组合
for a in candidatesA[0]:
for c in candidatesC[0]:
store_combination(a, c)
# 18 B[0] 和 C[0] 组合
for b in candidatesB[0]:
for c in candidatesC[0]:
store_combination(b, c)
# 再次检查并分配任务
if assign_task_from_result(result, factory):
continue
# 19 A[2] 和 B[2] 组合
for a in candidatesA[2]:
for b in candidatesB[2]:
store_combination(a, b)
# 再次检查并分配任务
if assign_task_from_result(result, factory):
continue
# 20 A[2] 和 B[1] 组合
for a in candidatesA[2]:
for b in candidatesB[1]:
store_combination(a, b)
# 21 A[1] 和 B[2] 组合
for a in candidatesA[1]:
for b in candidatesB[2]:
store_combination(a, b)
# 最后检查并分配任务
assign_task_from_result(result, factory)
# 22 A[2] 和 B[0] 组合
for a in candidatesA[2]:
for b in candidatesB[0]:
store_combination(a, b)
# 23 A[0] 和 B[2] 组合
for a in candidatesA[0]:
for b in candidatesB[2]:
store_combination(a, b)
# 24 A[1] 和 B[1] 组合
for a in candidatesA[1]:
for b in candidatesB[1]:
store_combination(a, b)
# 最后检查并分配任务
assign_task_from_result(result, factory)
###################################################################################################################
#############################################################################################
#############################################################################################
#############################################################################################
#############################################################################################
#############################################################################################
for factory in factories:
# 如果工厂没有组长或没有成员,或人数需求不是3或4,跳过
if not factory.leader or not factory.members or factory.people_num not in [3, 4]:
continue
# 遍历人员,筛选符合条件的人员,确保任务分配次数没有超过最大分配次数
candidates = [] # 存储符合条件的候选人
for p in people:
# 排除已经超过最大任务分配次数的人,且排除已经是组长或成员的人
if p.had_work >= p.max_time or p.name == factory.leader or p.name in factory.members:
continue
else :
candidates.append(p)
# 按照剩余可分配任务次数(max_time - had_work)最多的优先排序
candidates.sort(key=lambda x: (x.max_time - x.had_work), reverse=True)
# 如果 factory.people_num == 3,工厂已分配 1 个组长,已分配 1 个成员,添加 1 个新成员
if factory.people_num == 3:
if candidates:
new_member = candidates[0]
if not isinstance(factory.members, list):
factory.members = [] # 确保是列表
# 确保有组长和至少一个成员
if not factory.members or not factory.leader:
continue
# 获取组长和已分配成员的对象
selected_leader = next((p for p in people if p.name == factory.leader), None)
selected_members = [p for p in people if p.name in factory.members]
# 检查组长和成员是否存在
if not selected_leader or not selected_members:
continue
# 更新组长和现有成员的任务分配次数
#selected_leader.be_leader += 1
#selected_leader.had_work += 1
#for member in selected_members:
# member.had_work += 1
# 更新新成员的任务分配次数并加入成员列表
new_member.had_work += 1
factory.members.append(new_member.name)
# 将新成员添加到 selected_members 中
selected_members.append(new_member)
# 查找是否已有相同的 team
existing_team = find_existing_team_more_members(
assigned_teams, selected_leader.name, [member.name for member in selected_members]
)
if existing_team:
# 如果已有相同的 team,则增加 time
existing_team.time += 1
existing_team.hadfactories.add(factory.tasknum)
# 更新执行区域 Tarea
existing_team.Tarea = sorted(
set(map(str, existing_team.Tarea + [factory.farea]))
)
else:
# 如果没有相同的 team,则创建新的 Team 对象
new_team = Team(
masters=sorted(
map(
str,
selected_leader.masters.union(
*[member.masters for member in selected_members]
),
)
),
leader=selected_leader.name,
members=[member.name for member in selected_members],
Tarea=sorted(
map(
str,
[factory.farea],
)
),
time=1, # 新创建的 team 初始次数为 1
hadfactories={factory.tasknum},
)
# 将 team 存入已分配的队伍列表中
assigned_teams.append(new_team)
else:
if not factory.leader and not factory.members:
continue
# 获取组长和已分配成员的对象
selected_leader = next((p for p in people if p.name == factory.leader), None)
selected_members = [p for p in people if p.name in factory.members]
# 检查组长和成员是否存在
if not selected_leader or not selected_members:
continue
# 更新组长和现有成员的任务分配次数
selected_leader.be_leader -= 1
selected_leader.had_work -= 1
for member in selected_members:
member.had_work -= 1
# 2. 如果 factory.people_num == 4,工厂已分配 1 个组长,已分配 1 个成员,添加 2 个新成员
elif factory.people_num == 4:
# 选择两个符合条件的成员
if len(candidates) >= 2:
new_members = candidates[:2] # 选择剩余可分配任务次数最多的两名成员
if not isinstance(factory.members, list):
factory.members = [] # 确保 factory.members 是列表
# 确保已经有组长和至少一个已分配的成员
if not factory.leader or not factory.members:
continue
# 获取已分配的组长和现有成员的对象
selected_leader = next((p for p in people if p.name == factory.leader), None)
selected_members = [p for p in people if p.name in factory.members]
# 检查组长和现有成员是否存在
if not selected_leader or not selected_members:
continue
# 更新新成员的任务分配次数并加入成员列表
for new_member in new_members:
new_member.had_work += 1
factory.members.append(new_member.name)
# 查找是否已有相同的 team
existing_team = find_existing_team_more_members(
assigned_teams,
selected_leader.name,
[member.name for member in selected_members] + [m.name for m in new_members],
)
if existing_team:
# 如果已有相同的 team,则增加 time
existing_team.time += 1
existing_team.hadfactories.add(factory.tasknum)
# 更新执行区域 Tarea
existing_team.Tarea = sorted(
set(map(str, existing_team.Tarea + [factory.farea]))
)
else:
# 如果没有相同的 team,则创建新的 Team 对象
new_team = Team(
masters=sorted(
map(
str,
selected_leader.masters.union(
*[member.masters for member in selected_members + new_members]
),
)
),
leader=selected_leader.name,
members=[member.name for member in selected_members + new_members],
Tarea=sorted(
map(
str,
[factory.farea],
)
),
time=1, # 新创建的 team 初始次数为 1
hadfactories={factory.tasknum},
)
# 将 team 存入已分配的队伍列表中
assigned_teams.append(new_team)
else:
# 若候选人不足两名,将之前分配好的两个人即leader和members记录下来
if not isinstance(factory.members, list):
factory.members = [] # 确保 factory.members 是列表
# 确保已经有组长和至少一个已分配的成员
if not factory.leader or not factory.members:
continue
# 获取已分配的组长和现有成员的对象
selected_leader = next((p for p in people if p.name == factory.leader), None)
selected_members = [p for p in people if p.name in factory.members]
# 检查组长和现有成员是否存在
if not selected_leader or not selected_members:
continue
# 查找是否已有相同的 team
existing_team = find_existing_team_more_members(
assigned_teams, selected_leader.name, selected_member.name
)
if existing_team:
# 如果已有相同的 team,则增加 time
existing_team.time += 1
existing_team.hadfactories.add(factory.tasknum)
# existing_team.Tarea.append(factory.farea)
existing_team.Tarea = sorted(
#set(map(str, existing_team.Tarea + [factory.farea]))
set(map(str, existing_team.Tarea + [factory.farea]))
)
else:
# 如果没有相同的 team,则创建新的 Team 对象
new_team = Team(
# masters=selected_leader.masters.union(selected_member.masters), #farea={factory.farea},
# 直接按照字符串进行排序# 这里是排序后的 masters 集合
masters=sorted(
map(
str,
selected_leader.masters.union(selected_member.masters),
)
),
leader=selected_leader.name,
members=[selected_member.name],
Tarea=sorted(
map(
str,
#selected_leader.area2.union(selected_member.area2),
[factory.farea],
)
),
time=1, # 新创建的 team 初始次数为 1
# Tarea={factory.farea},
hadfactories={factory.tasknum},
)
# 将 team 存入已分配的队伍列表中
assigned_teams.append(new_team)
return factories
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。