(cls, instance: "AssignmentConfig")
| 67 | |
| 68 | @classmethod |
| 69 | def post_validate(cls, instance: "AssignmentConfig"): |
| 70 | |
| 71 | REMOVE_UNUSED_IN_DEFINITION = True |
| 72 | REMOVE_UNUSED_IN_CONCURRENCY = True |
| 73 | |
| 74 | # Step 1. Check if all agents and tasks are defined, and remove unused agents and tasks |
| 75 | |
| 76 | agent_in_assignment = set() |
| 77 | task_in_assignment = set() |
| 78 | for assignment in instance.assignments: |
| 79 | assert ( |
| 80 | assignment.agent in instance.definition.agent |
| 81 | ), f"Agent {assignment.agent} is not defined." |
| 82 | agent_in_assignment.add(assignment.agent) |
| 83 | assert ( |
| 84 | assignment.task in instance.definition.task |
| 85 | ), f"Task {assignment.task} is not defined." |
| 86 | task_in_assignment.add(assignment.task) |
| 87 | |
| 88 | for agent in agent_in_assignment: |
| 89 | assert ( |
| 90 | agent in instance.concurrency.agent |
| 91 | ), f"Concurrency of {agent} is not specified." |
| 92 | for task in task_in_assignment: |
| 93 | assert ( |
| 94 | task in instance.concurrency.task |
| 95 | ), f"Concurrency of {task} is not specified." |
| 96 | |
| 97 | def remove_unused( |
| 98 | target: Union[DefinitionConfig, ConcurrencyConfig], warning_suffix: str |
| 99 | ): |
| 100 | nonlocal agent_in_assignment, task_in_assignment |
| 101 | removed_agents = set() |
| 102 | removed_tasks = set() |
| 103 | |
| 104 | for definition_agent in target.agent.keys(): |
| 105 | if definition_agent not in agent_in_assignment: |
| 106 | removed_agents.add(definition_agent) |
| 107 | |
| 108 | for definition_task in target.task.keys(): |
| 109 | if definition_task not in task_in_assignment: |
| 110 | removed_tasks.add(definition_task) |
| 111 | |
| 112 | if len(removed_agents) > 0 or len(removed_tasks) > 0: |
| 113 | |
| 114 | print( |
| 115 | ColorMessage.yellow( |
| 116 | f"Warning: {len(removed_agents)} agent(s) and {len(removed_tasks)} task(s) are " |
| 117 | + warning_suffix |
| 118 | ), |
| 119 | file=sys.stderr, |
| 120 | ) |
| 121 | print(ColorMessage.yellow(f" Agent: {removed_agents}")) |
| 122 | print(ColorMessage.yellow(f" Task: {removed_tasks}")) |
| 123 | |
| 124 | for agent in removed_agents: |
| 125 | target.agent.pop(agent) |
| 126 |
nothing calls this directly
no test coverage detected