From da037c0ce7dcd4b855b5af7fd3eab467cc62e3f6 Mon Sep 17 00:00:00 2001 From: shima004 Date: Fri, 15 Nov 2024 18:09:34 +0900 Subject: [PATCH 1/6] feat: add CLI template and configuration files for agent team setup --- adf_core_python/cli/__init__.py | 0 adf_core_python/cli/cli.py | 53 ++++++ .../cli/template/config/development.json | 3 + .../cli/template/config/launcher.yaml | 35 ++++ .../cli/template/config/module.yaml | 113 +++++++++++++ .../cli/template/src//__init__.py | 0 .../src//module/__init__.py | 0 .../complex/_human_detector.py | 149 +++++++++++++++++ .../complex/_road_detector.py | 158 ++++++++++++++++++ .../module/complex/_search.py | 106 ++++++++++++ ...//module/complex/__init__.py | 0 config/module.yaml | 2 - poetry.lock | 16 +- pyproject.toml | 18 +- 14 files changed, 643 insertions(+), 10 deletions(-) create mode 100644 adf_core_python/cli/__init__.py create mode 100644 adf_core_python/cli/cli.py create mode 100644 adf_core_python/cli/template/config/development.json create mode 100644 adf_core_python/cli/template/config/launcher.yaml create mode 100644 adf_core_python/cli/template/config/module.yaml create mode 100644 adf_core_python/cli/template/src//__init__.py create mode 100644 adf_core_python/cli/template/src//module/__init__.py create mode 100644 adf_core_python/cli/template/src//module/complex/_human_detector.py create mode 100644 adf_core_python/cli/template/src//module/complex/_road_detector.py create mode 100644 adf_core_python/cli/template/src//module/complex/_search.py create mode 100644 adf_core_python/cli/template/src//module/complex/__init__.py diff --git a/adf_core_python/cli/__init__.py b/adf_core_python/cli/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/adf_core_python/cli/cli.py b/adf_core_python/cli/cli.py new file mode 100644 index 00000000..acf3c484 --- /dev/null +++ b/adf_core_python/cli/cli.py @@ -0,0 +1,53 @@ +import os + +import click + +LOWER_NAME_PLACEHOLDER = "" +UPPER_NAME_PLACEHOLDER = "" + + +@click.command() +@click.option( + "--name", prompt="Your agent team name", help="The name of your agent team" +) +def main(name): + # load template dir and create a new agent team + click.echo(f"Creating a new agent team with name: {name}") + lower_name = name.lower() + upper_name = name.upper() + # 自身がいるディレクトリを取得 + template_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), "template") + click.echo(f"Current file path: {template_dir}") + # コマンドラインのカレントディレクトリを取得 + current_dir = os.getcwd() + click.echo(f"Current directory: {current_dir}") + + _copy_template(template_dir, current_dir, lower_name, upper_name) + + +def _copy_template(src, dest, lower_name, upper_name): + if os.path.isdir(src): + if not os.path.exists(dest): + os.makedirs(dest) + for item in os.listdir(src): + s = os.path.join(src, item) + d = os.path.join( + dest, + item.replace(LOWER_NAME_PLACEHOLDER, lower_name).replace( + UPPER_NAME_PLACEHOLDER, upper_name + ), + ) + _copy_template(s, d, lower_name, upper_name) + else: + with open(src, "r") as f: + content = f.read() + with open(dest, "w") as f: + f.write( + content.replace(LOWER_NAME_PLACEHOLDER, lower_name).replace( + UPPER_NAME_PLACEHOLDER, upper_name + ) + ) + + +if __name__ == "__main__": + main() diff --git a/adf_core_python/cli/template/config/development.json b/adf_core_python/cli/template/config/development.json new file mode 100644 index 00000000..d0ae716d --- /dev/null +++ b/adf_core_python/cli/template/config/development.json @@ -0,0 +1,3 @@ +{ + "test": "test" +} diff --git a/adf_core_python/cli/template/config/launcher.yaml b/adf_core_python/cli/template/config/launcher.yaml new file mode 100644 index 00000000..35fbb756 --- /dev/null +++ b/adf_core_python/cli/template/config/launcher.yaml @@ -0,0 +1,35 @@ +kernel: + host: localhost + port: 27931 + +team: + name: + +adf: + launcher: + precompute: 0 + debug: + flag: 0 + agent: + moduleconfig: + filename: config/module.yaml + + develop: + flag: 1 + filename: config/development.json + + team: + platoon: + ambulance: + count: 1 + fire: + count: 0 + police: + count: 0 + office: + ambulance: + count: -1 + fire: + count: -1 + police: + count: -1 diff --git a/adf_core_python/cli/template/config/module.yaml b/adf_core_python/cli/template/config/module.yaml new file mode 100644 index 00000000..dd85c56a --- /dev/null +++ b/adf_core_python/cli/template/config/module.yaml @@ -0,0 +1,113 @@ +## DefaultTacticsAmbulanceTeam +DefaultTacticsAmbulanceTeam: + HumanDetector: .module.complex._human_detector.HumanDetector + Search: .module.complex._search.Search + ExtendActionTransport: adf_core_python.implement.action.default_extend_action_transport.DefaultExtendActionTransport + ExtendActionMove: adf_core_python.implement.action.default_extend_action_move.DefaultExtendActionMove + CommandExecutorAmbulance: adf_core_python.implement.centralized.DefaultCommandExecutorAmbulance + CommandExecutorScout: adf_core_python.implement.centralized.DefaultCommandExecutorScout + +# ## DefaultTacticsFireBrigade +DefaultTacticsFireBrigade: + HumanDetector: .module.complex._human_detector.HumanDetector + Search: .module.complex._search.Search + ExtendActionRescue: adf_core_python.implement.action.default_extend_action_rescue.DefaultExtendActionRescue + ExtendActionMove: adf_core_python.implement.action.default_extend_action_move.DefaultExtendActionMove + CommandExecutorFire: adf_core_python.implement.centralized.DefaultCommandExecutorFire + CommandExecutorScout: adf_core_python.implement.centralized.DefaultCommandExecutorScout + +# ## DefaultTacticsPoliceForce +DefaultTacticsPoliceForce: + RoadDetector: .module.complex._road_detector.RoadDetector + Search: .module.complex._search.Search + ExtendActionClear: adf_core_python.implement.action.default_extend_action_clear.DefaultExtendActionClear + ExtendActionMove: adf_core_python.implement.action.default_extend_action_move.DefaultExtendActionMove + CommandExecutorPolice: adf_core_python.implement.centralized.DefaultCommandExecutorPolice + CommandExecutorScout: adf_core_python.implement.centralized.DefaultCommandExecutorScoutPolice + +# ## DefaultTacticsAmbulanceCentre +# DefaultTacticsAmbulanceCentre: +# TargetAllocator: sample_team.module.complex.SampleAmbulanceTargetAllocator +# CommandPicker: adf_core_python.implement.centralized.DefaultCommandPickerAmbulance + +# ## DefaultTacticsFireStation +# DefaultTacticsFireStation: +# TargetAllocator: sample_team.module.complex.SampleFireTargetAllocator +# CommandPicker: adf_core_python.implement.centralized.DefaultCommandPickerFire + +# ## DefaultTacticsPoliceOffice +# DefaultTacticsPoliceOffice: +# TargetAllocator: sample_team.module.complex.SamplePoliceTargetAllocator +# CommandPicker: adf_core_python.implement.centralized.DefaultCommandPickerPolice + +## SampleSearch +SampleSearch: + PathPlanning: adf_core_python.implement.module.algorithm.a_star_path_planning.AStarPathPlanning + Clustering: adf_core_python.implement.module.algorithm.k_means_clustering.KMeansClustering + +# ## SampleBuildDetector +# SampleBuildingDetector: +# Clustering: adf_core_python.implement.module.algorithm.KMeansClustering + +# ## SampleRoadDetector +# SampleRoadDetector: +# Clustering: adf_core_python.implement.module.algorithm.KMeansClustering +# PathPlanning: adf_core_python.implement.module.algorithm.DijkstraPathPlanning + +# ## SampleHumanDetector +# SampleHumanDetector: +# Clustering: adf_core_python.implement.module.algorithm.KMeansClustering + +# ## DefaultExtendActionClear +# DefaultExtendActionClear: +# PathPlanning: adf_core_python.implement.module.algorithm.DijkstraPathPlanning + +# ## DefaultExtendActionFireFighting +# DefaultExtendActionFireFighting: +# PathPlanning: adf_core_python.implement.module.algorithm.DijkstraPathPlanning + +# ## DefaultExtendActionRescue +# DefaultExtendActionRescue: +# PathPlanning: adf_core_python.implement.module.algorithm.DijkstraPathPlanning + +# ## DefaultExtendActionMove +# DefaultExtendActionMove: +# PathPlanning: adf_core_python.implement.module.algorithm.DijkstraPathPlanning + +# ## DefaultExtendActionTransport +# DefaultExtendActionTransport: +# PathPlanning: adf_core_python.implement.module.algorithm.DijkstraPathPlanning +# ## DefaultCommandExecutorAmbulance +# DefaultCommandExecutorAmbulance: +# PathPlanning: adf_core_python.implement.module.algorithm.DijkstraPathPlanning +# ExtendActionTransport: adf_core_python.implement.action.DefaultExtendActionTransport +# ExtendActionMove: adf_core_python.implement.action.DefaultExtendActionMove + +# ## DefaultCommandExecutorFire +# DefaultCommandExecutorFire: +# PathPlanning: adf_core_python.implement.module.algorithm.DijkstraPathPlanning +# EtxActionFireRescue: adf_core_python.implement.action.DefaultExtendActionRescue +# EtxActionFireFighting: adf_core_python.implement.action.DefaultExtendActionFireFighting +# ExtendActionMove: adf_core_python.implement.action.DefaultExtendActionMove + +# ## DefaultCommandExecutorPolice +# DefaultCommandExecutorPolice: +# PathPlanning: adf_core_python.implement.module.algorithm.DijkstraPathPlanning +# ExtendActionClear: adf_core_python.implement.action.DefaultExtendActionClear +# ExtendActionMove: adf_core_python.implement.action.DefaultExtendActionMove + +# ## DefaultCommandExecutorScout +# DefaultCommandExecutorScout: +# PathPlanning: adf_core_python.implement.module.algorithm.DijkstraPathPlanning + +# ## DefaultCommandExecutorScoutPolice +# DefaultCommandExecutorScoutPolice: +# PathPlanning: adf_core_python.implement.module.algorithm.DijkstraPathPlanning +# ExtendActionClear: adf_core_python.implement.action.DefaultExtendActionClear + +# ## MessageManager +MessageManager: + PlatoonChannelSubscriber: adf_core_python.implement.module.communication.default_channel_subscriber.DefaultChannelSubscriber + CenterChannelSubscriber: adf_core_python.implement.module.communication.default_channel_subscriber.DefaultChannelSubscriber + PlatoonMessageCoordinator: adf_core_python.implement.module.communication.default_message_coordinator.DefaultMessageCoordinator + CenterMessageCoordinator: adf_core_python.implement.module.communication.default_message_coordinator.DefaultMessageCoordinator diff --git a/adf_core_python/cli/template/src//__init__.py b/adf_core_python/cli/template/src//__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/adf_core_python/cli/template/src//module/__init__.py b/adf_core_python/cli/template/src//module/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/adf_core_python/cli/template/src//module/complex/_human_detector.py b/adf_core_python/cli/template/src//module/complex/_human_detector.py new file mode 100644 index 00000000..47202260 --- /dev/null +++ b/adf_core_python/cli/template/src//module/complex/_human_detector.py @@ -0,0 +1,149 @@ +from typing import Optional, cast + +from rcrs_core.connection.URN import Entity as EntityURN +from rcrs_core.entities.civilian import Civilian +from rcrs_core.entities.entity import Entity +from rcrs_core.entities.human import Human +from rcrs_core.worldmodel.entityID import EntityID + +from adf_core_python.core.agent.develop.develop_data import DevelopData +from adf_core_python.core.agent.info.agent_info import AgentInfo +from adf_core_python.core.agent.info.scenario_info import ScenarioInfo +from adf_core_python.core.agent.info.world_info import WorldInfo +from adf_core_python.core.agent.module.module_manager import ModuleManager +from adf_core_python.core.component.module.algorithm.clustering import Clustering +from adf_core_python.core.component.module.complex.human_detector import HumanDetector +from adf_core_python.core.logger.logger import get_agent_logger + + +class DefaultHumanDetector(HumanDetector): + def __init__( + self, + agent_info: AgentInfo, + world_info: WorldInfo, + scenario_info: ScenarioInfo, + module_manager: ModuleManager, + develop_data: DevelopData, + ) -> None: + super().__init__( + agent_info, world_info, scenario_info, module_manager, develop_data + ) + self._clustering: Clustering = cast( + Clustering, + module_manager.get_module( + "DefaultHumanDetector.Clustering", + "adf_core_python.implement.module.algorithm.k_means_clustering.KMeansClustering", + ), + ) + self.register_sub_module(self._clustering) + + self._result: Optional[EntityID] = None + self._logger = get_agent_logger( + f"{self.__class__.__module__}.{self.__class__.__qualname__}", + self._agent_info, + ) + + def calculate(self) -> HumanDetector: + transport_human: Optional[Human] = self._agent_info.some_one_on_board() + if transport_human is not None: + self._result = transport_human.get_id() + return self + + if self._result is not None: + if not self._is_valid_human(self._result): + self._result = None + + if self._result is None: + self._result = self._select_target() + + return self + + def _select_target(self) -> Optional[EntityID]: + if self._result is not None and self._is_valid_human(self._result): + return self._result + + cluster_index: int = self._clustering.get_cluster_index( + self._agent_info.get_entity_id() + ) + cluster_entities: list[Entity] = self._clustering.get_cluster_entities( + cluster_index + ) + + cluster_valid_human_entities: list[Entity] = [ + entity + for entity in cluster_entities + if self._is_valid_human(entity.get_id()) and isinstance(entity, Civilian) + ] + if len(cluster_valid_human_entities) != 0: + nearest_human_entity = cluster_valid_human_entities[0] + nearest_distance = self._world_info.get_distance( + self._agent_info.get_entity_id(), + nearest_human_entity.get_id(), + ) + for entity in cluster_valid_human_entities: + distance = self._world_info.get_distance( + self._agent_info.get_entity_id(), + entity.get_id(), + ) + if distance < nearest_distance: + nearest_distance = distance + nearest_human_entity = entity + return nearest_human_entity.get_id() + + world_valid_human_entities: list[Entity] = [ + entity + for entity in self._world_info.get_entities_of_types([Civilian]) + if self._is_valid_human(entity.get_id()) + ] + if len(world_valid_human_entities) != 0: + nearest_human_entity = world_valid_human_entities[0] + nearest_distance = self._world_info.get_distance( + self._agent_info.get_entity_id(), + nearest_human_entity.get_id(), + ) + for entity in world_valid_human_entities: + distance = self._world_info.get_distance( + self._agent_info.get_entity_id(), + entity.get_id(), + ) + if distance < nearest_distance: + nearest_distance = distance + nearest_human_entity = entity + return nearest_human_entity.get_id() + + return None + + def _is_valid_human(self, target_entity_id: EntityID) -> bool: + target: Optional[Entity] = self._world_info.get_entity(target_entity_id) + if target is None: + return False + if not isinstance(target, Human): + return False + hp: Optional[int] = target.get_hp() + if hp is None or hp <= 0: + return False + buriedness: Optional[int] = target.get_buriedness() + if buriedness is None: + return False + myself = self._agent_info.get_myself() + if myself.get_urn() == EntityURN.FIRE_BRIGADE and buriedness == 0: + return False + if myself.get_urn() == EntityURN.AMBULANCE_TEAM and buriedness > 0: + return False + damage: Optional[int] = target.get_damage() + if damage is None or damage == 0: + return False + position_entity_id: Optional[EntityID] = target.get_position() + if position_entity_id is None: + return False + position: Optional[Entity] = self._world_info.get_entity(position_entity_id) + if position is None: + return False + urn: EntityURN = position.get_urn() + if urn == EntityURN.REFUGE or urn == EntityURN.AMBULANCE_TEAM: + return False + + return True + + def get_target_entity_id(self) -> Optional[EntityID]: + return self._result diff --git a/adf_core_python/cli/template/src//module/complex/_road_detector.py b/adf_core_python/cli/template/src//module/complex/_road_detector.py new file mode 100644 index 00000000..adad2d8c --- /dev/null +++ b/adf_core_python/cli/template/src//module/complex/_road_detector.py @@ -0,0 +1,158 @@ +from typing import Optional, cast + +from rcrs_core.entities.building import Building +from rcrs_core.entities.gassStation import GasStation +from rcrs_core.entities.refuge import Refuge +from rcrs_core.entities.road import Road +from rcrs_core.worldmodel.entityID import EntityID + +from adf_core_python.core.agent.communication.message_manager import MessageManager +from adf_core_python.core.agent.develop.develop_data import DevelopData +from adf_core_python.core.agent.info.agent_info import AgentInfo +from adf_core_python.core.agent.info.scenario_info import Mode, ScenarioInfo +from adf_core_python.core.agent.info.world_info import WorldInfo +from adf_core_python.core.agent.module.module_manager import ModuleManager +from adf_core_python.core.agent.precompute.precompute_data import PrecomputeData +from adf_core_python.core.component.module.algorithm.path_planning import ( + PathPlanning, +) +from adf_core_python.core.component.module.complex.road_detector import RoadDetector + + +class DefaultRoadDetector(RoadDetector): + def __init__( + self, + agent_info: AgentInfo, + world_info: WorldInfo, + scenario_info: ScenarioInfo, + module_manager: ModuleManager, + develop_data: DevelopData, + ) -> None: + super().__init__( + agent_info, world_info, scenario_info, module_manager, develop_data + ) + match scenario_info.get_mode(): + case Mode.NON_PRECOMPUTE: + self._path_planning: PathPlanning = cast( + PathPlanning, + module_manager.get_module( + "DefaultRoadDetector.PathPlanning", + "adf_core_python.implement.module.algorithm.a_star_path_planning.AStarPathPlanning", + ), + ) + + self.register_sub_module(self._path_planning) + self._result = None + + def precompute(self, precompute_data: PrecomputeData) -> RoadDetector: + super().precompute(precompute_data) + return self + + def resume(self, precompute_data: PrecomputeData) -> RoadDetector: + super().resume(precompute_data) + if self.get_count_resume() >= 2: + return self + + self._target_areas: set[EntityID] = set() + entities = self._world_info.get_entities_of_types( + [Refuge, Building, GasStation] + ) + for entity in entities: + if not isinstance(entity, Building): + continue + for entity_id in entity.get_neighbours(): + neighbor = self._world_info.get_entity(entity_id) + if isinstance(neighbor, Road): + self._target_areas.add(entity_id) + + self._priority_roads = set() + for entity in self._world_info.get_entities_of_types([Refuge]): + if not isinstance(entity, Building): + continue + for entity_id in entity.get_neighbours(): + neighbor = self._world_info.get_entity(entity_id) + if isinstance(neighbor, Road): + self._priority_roads.add(entity_id) + + return self + + def prepare(self) -> RoadDetector: + super().prepare() + if self.get_count_prepare() >= 2: + return self + + self._target_areas = set() + entities = self._world_info.get_entities_of_types( + [Refuge, Building, GasStation] + ) + for entity in entities: + building: Building = cast(Building, entity) + for entity_id in building.get_neighbours(): + neighbor = self._world_info.get_entity(entity_id) + if isinstance(neighbor, Road): + self._target_areas.add(entity_id) + + self._priority_roads = set() + for entity in self._world_info.get_entities_of_types([Refuge]): + refuge: Refuge = cast(Refuge, entity) + for entity_id in refuge.get_neighbours(): + neighbor = self._world_info.get_entity(entity_id) + if isinstance(neighbor, Road): + self._priority_roads.add(entity_id) + + return self + + def update_info(self, message_manager: MessageManager) -> RoadDetector: + super().update_info(message_manager) + if self.get_count_update_info() >= 2: + return self + + if self._result is not None: + if self._agent_info.get_position_entity_id == self._result: + entity = self._world_info.get_entity(self._result) + if isinstance(entity, Building): + self._result = None + elif isinstance(entity, Road): + road: Road = cast(Road, entity) + if road.get_blockades() == []: + self._target_areas.remove(self._result) + self._result = None + + return self + + def calculate(self) -> RoadDetector: + if self._result is None: + position_entity_id: EntityID = self._agent_info.get_position_entity_id() + if position_entity_id in self._target_areas: + self._result = position_entity_id + return self + remove_list = [] + for entity_id in self._priority_roads: + if entity_id not in self._target_areas: + remove_list.append(entity_id) + + self._priority_roads = self._priority_roads - set(remove_list) + if len(self._priority_roads) > 0: + _nearest_target_area = self._agent_info.get_position_entity_id() + _nearest_distance = float("inf") + for target_area in self._target_areas: + if ( + self._world_info.get_distance( + self._agent_info.get_position_entity_id(), target_area + ) + < _nearest_distance + ): + _nearest_target_area = target_area + _nearest_distance = self._world_info.get_distance( + self._agent_info.get_position_entity_id(), target_area + ) + path: list[EntityID] = self._path_planning.get_path( + self._agent_info.get_position_entity_id(), _nearest_target_area + ) + if path is not None and len(path) > 0: + self._result = path[-1] + + return self + + def get_target_entity_id(self) -> Optional[EntityID]: + return self._result diff --git a/adf_core_python/cli/template/src//module/complex/_search.py b/adf_core_python/cli/template/src//module/complex/_search.py new file mode 100644 index 00000000..05d7c888 --- /dev/null +++ b/adf_core_python/cli/template/src//module/complex/_search.py @@ -0,0 +1,106 @@ +from typing import Optional, cast + +from rcrs_core.entities.building import Building +from rcrs_core.entities.entity import Entity +from rcrs_core.entities.refuge import Refuge +from rcrs_core.worldmodel.entityID import EntityID + +from adf_core_python.core.agent.communication.message_manager import MessageManager +from adf_core_python.core.agent.develop.develop_data import DevelopData +from adf_core_python.core.agent.info.agent_info import AgentInfo +from adf_core_python.core.agent.info.scenario_info import ScenarioInfo +from adf_core_python.core.agent.info.world_info import WorldInfo +from adf_core_python.core.agent.module.module_manager import ModuleManager +from adf_core_python.core.component.module.algorithm.clustering import Clustering +from adf_core_python.core.component.module.algorithm.path_planning import PathPlanning +from adf_core_python.core.component.module.complex.search import Search +from adf_core_python.core.logger.logger import get_agent_logger + + +class DefaultSearch(Search): + def __init__( + self, + agent_info: AgentInfo, + world_info: WorldInfo, + scenario_info: ScenarioInfo, + module_manager: ModuleManager, + develop_data: DevelopData, + ) -> None: + super().__init__( + agent_info, world_info, scenario_info, module_manager, develop_data + ) + + self._unreached_building_ids: set[EntityID] = set() + self._result: Optional[EntityID] = None + + self._clustering: Clustering = cast( + Clustering, + module_manager.get_module( + "DefaultSearch.Clustering", + "adf_core_python.implement.module.algorithm.k_means_clustering.KMeansClustering", + ), + ) + + self._path_planning: PathPlanning = cast( + PathPlanning, + module_manager.get_module( + "DefaultSearch.PathPlanning", + "adf_core_python.implement.module.algorithm.a_star_path_planning.AStarPathPlanning", + ), + ) + + self._logger = get_agent_logger( + f"{self.__class__.__module__}.{self.__class__.__qualname__}", + self._agent_info, + ) + + self.register_sub_module(self._clustering) + self.register_sub_module(self._path_planning) + + def update_info(self, message_manager: MessageManager) -> Search: + super().update_info(message_manager) + if self.get_count_update_info() > 1: + return self + + self._logger.debug( + f"unreached_building_ids: {[str(id) for id in self._unreached_building_ids]}" + ) + + searched_building_id = self._agent_info.get_position_entity_id() + self._unreached_building_ids.discard(searched_building_id) + + if len(self._unreached_building_ids) == 0: + self._unreached_building_ids = self._get_search_targets() + + return self + + def calculate(self) -> Search: + nearest_building_id: Optional[EntityID] = None + nearest_distance: Optional[float] = None + for building_id in self._unreached_building_ids: + distance = self._world_info.get_distance( + self._agent_info.get_entity_id(), building_id + ) + if nearest_distance is None or distance < nearest_distance: + nearest_building_id = building_id + nearest_distance = distance + self._result = nearest_building_id + return self + + def get_target_entity_id(self) -> Optional[EntityID]: + return self._result + + def _get_search_targets(self) -> set[EntityID]: + cluster_index: int = self._clustering.get_cluster_index( + self._agent_info.get_entity_id() + ) + cluster_entities: list[Entity] = self._clustering.get_cluster_entities( + cluster_index + ) + building_entity_ids: list[EntityID] = [ + entity.get_id() + for entity in cluster_entities + if isinstance(entity, Building) and not isinstance(entity, Refuge) + ] + + return set(building_entity_ids) diff --git a/adf_core_python/cli/template/src//module/complex/__init__.py b/adf_core_python/cli/template/src//module/complex/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/config/module.yaml b/config/module.yaml index b4fbba11..958fbc78 100644 --- a/config/module.yaml +++ b/config/module.yaml @@ -111,5 +111,3 @@ MessageManager: CenterChannelSubscriber: adf_core_python.implement.module.communication.default_channel_subscriber.DefaultChannelSubscriber PlatoonMessageCoordinator: adf_core_python.implement.module.communication.default_message_coordinator.DefaultMessageCoordinator CenterMessageCoordinator: adf_core_python.implement.module.communication.default_message_coordinator.DefaultMessageCoordinator -# ## VisualDebug -# VisualDebug: true diff --git a/poetry.lock b/poetry.lock index c1d9ac7b..d30279be 100644 --- a/poetry.lock +++ b/poetry.lock @@ -146,6 +146,20 @@ files = [ {file = "bitarray-3.0.0.tar.gz", hash = "sha256:a2083dc20f0d828a7cdf7a16b20dae56aab0f43dc4f347a3b3039f6577992b03"}, ] +[[package]] +name = "click" +version = "8.1.7" +description = "Composable command line interface toolkit" +optional = false +python-versions = ">=3.7" +files = [ + {file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"}, + {file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} + [[package]] name = "colorama" version = "0.4.6" @@ -782,4 +796,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "6e8244db0f75c542b50338580672c5e11b1cdfe38b0a62d01b757b31d4eddaf0" +content-hash = "62d5fde0d4a35f29aa7f21a31f5c1f4679c7a576c0f57c0363ec0b0cd6dc9e91" diff --git a/pyproject.toml b/pyproject.toml index 35dee4b5..ba652afd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,13 +5,13 @@ description = "Agent Development Framework for Python" authors = [ "Haruki Uehara ", "Yuki Shimada ", - ] +] readme = "README.md" package-mode = true [tool.poetry.dependencies] python = "^3.12" -rcrs_core = {git = "https://github.com/adf-python/rcrs-core-python"} +rcrs_core = { git = "https://github.com/adf-python/rcrs-core-python" } pyyaml = "^6.0.2" pytest = "^8.3.2" types-pyyaml = "^6.0.12.20240808" @@ -19,6 +19,7 @@ scikit-learn = "^1.5.2" structlog = "^24.4.0" bitarray = "^3.0.0" shapely = "^2.0.6" +click = "^8.1.7" [tool.poetry.group.dev.dependencies] @@ -31,6 +32,9 @@ ruff = "^0.4.4" requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" +[tool.script] +adf-core-python = "adf_core_python.cli.cli:main" + [tool.taskipy.tasks] format = "ruff format ." lint = "ruff check ." @@ -120,9 +124,9 @@ docstring-code-line-length = "dynamic" [tool.mypy] ignore_missing_imports = true -show_error_context = true # エラー時のメッセージを詳細表示 -show_column_numbers = true # エラー発生箇所の行数/列数を表示 +show_error_context = true # エラー時のメッセージを詳細表示 +show_column_numbers = true # エラー発生箇所の行数/列数を表示 disallow_untyped_defs = true # 関数定義の引数/戻り値に型アノテーション必須 -no_implicit_optional = true # デフォルト引数に None を取る場合型アノテーションに Optional 必須 -check_untyped_defs = true # 型注釈がない関数やメソッドに対して型チェックを行う -warn_redundant_casts = true # 冗長なキャストに警告 +no_implicit_optional = true # デフォルト引数に None を取る場合型アノテーションに Optional 必須 +check_untyped_defs = true # 型注釈がない関数やメソッドに対して型チェックを行う +warn_redundant_casts = true # 冗長なキャストに警告 From 68f2be064d32f2ded650454a5b9844d2f4e7414e Mon Sep 17 00:00:00 2001 From: shima004 Date: Fri, 15 Nov 2024 18:20:16 +0900 Subject: [PATCH 2/6] refactor: rename main function to cli and update script entry point in pyproject.toml --- adf_core_python/cli/cli.py | 6 +----- pyproject.toml | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/adf_core_python/cli/cli.py b/adf_core_python/cli/cli.py index acf3c484..23a51462 100644 --- a/adf_core_python/cli/cli.py +++ b/adf_core_python/cli/cli.py @@ -10,7 +10,7 @@ @click.option( "--name", prompt="Your agent team name", help="The name of your agent team" ) -def main(name): +def cli(name): # load template dir and create a new agent team click.echo(f"Creating a new agent team with name: {name}") lower_name = name.lower() @@ -47,7 +47,3 @@ def _copy_template(src, dest, lower_name, upper_name): UPPER_NAME_PLACEHOLDER, upper_name ) ) - - -if __name__ == "__main__": - main() diff --git a/pyproject.toml b/pyproject.toml index ba652afd..71f60d0f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,8 +32,8 @@ ruff = "^0.4.4" requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" -[tool.script] -adf-core-python = "adf_core_python.cli.cli:main" +[tool.poetry.scripts] +adf-core-python = "adf_core_python.cli.cli:cli" [tool.taskipy.tasks] format = "ruff format ." From 89b9fbbd91753f8e38db05831db41a0cf03b9bcf Mon Sep 17 00:00:00 2001 From: shima004 Date: Fri, 15 Nov 2024 18:27:00 +0900 Subject: [PATCH 3/6] refactor: update placeholder names and file structure for team templates --- adf_core_python/cli/cli.py | 9 +++++++-- adf_core_python/cli/template/config/launcher.yaml | 2 +- adf_core_python/cli/template/config/module.yaml | 12 ++++++------ .../src/{ => team_name}/__init__.py | 0 .../{ => team_name}/module/__init__.py | 0 .../module/complex/__init__.py | 0 .../module/complex/team_name_human_detector.py} | 2 +- .../module/complex/team_name_road_detector.py} | 2 +- .../module/complex/team_name_search.py} | 2 +- 9 files changed, 17 insertions(+), 12 deletions(-) rename adf_core_python/cli/template/src/{ => team_name}/__init__.py (100%) rename adf_core_python/cli/template/src/{ => team_name}/module/__init__.py (100%) rename adf_core_python/cli/template/src/{ => team_name}/module/complex/__init__.py (100%) rename adf_core_python/cli/template/src/{/module/complex/_human_detector.py => team_name/module/complex/team_name_human_detector.py} (99%) rename adf_core_python/cli/template/src/{/module/complex/_road_detector.py => team_name/module/complex/team_name_road_detector.py} (99%) rename adf_core_python/cli/template/src/{/module/complex/_search.py => team_name/module/complex/team_name_search.py} (99%) diff --git a/adf_core_python/cli/cli.py b/adf_core_python/cli/cli.py index 23a51462..1031fa23 100644 --- a/adf_core_python/cli/cli.py +++ b/adf_core_python/cli/cli.py @@ -2,8 +2,8 @@ import click -LOWER_NAME_PLACEHOLDER = "" -UPPER_NAME_PLACEHOLDER = "" +LOWER_NAME_PLACEHOLDER = "team_name" +UPPER_NAME_PLACEHOLDER = "TeamName" @click.command() @@ -47,3 +47,8 @@ def _copy_template(src, dest, lower_name, upper_name): UPPER_NAME_PLACEHOLDER, upper_name ) ) + new_dest = dest.replace(LOWER_NAME_PLACEHOLDER, lower_name).replace( + UPPER_NAME_PLACEHOLDER, upper_name + ) + if new_dest != dest: + os.rename(dest, new_dest) diff --git a/adf_core_python/cli/template/config/launcher.yaml b/adf_core_python/cli/template/config/launcher.yaml index 35fbb756..42525854 100644 --- a/adf_core_python/cli/template/config/launcher.yaml +++ b/adf_core_python/cli/template/config/launcher.yaml @@ -3,7 +3,7 @@ kernel: port: 27931 team: - name: + name: team_name adf: launcher: diff --git a/adf_core_python/cli/template/config/module.yaml b/adf_core_python/cli/template/config/module.yaml index dd85c56a..3f7467a7 100644 --- a/adf_core_python/cli/template/config/module.yaml +++ b/adf_core_python/cli/template/config/module.yaml @@ -1,7 +1,7 @@ ## DefaultTacticsAmbulanceTeam DefaultTacticsAmbulanceTeam: - HumanDetector: .module.complex._human_detector.HumanDetector - Search: .module.complex._search.Search + HumanDetector: team_name.module.complex.team_name_human_detector.TeamNameHumanDetector + Search: team_name.module.complex.team_name_search.TeamNameSearch ExtendActionTransport: adf_core_python.implement.action.default_extend_action_transport.DefaultExtendActionTransport ExtendActionMove: adf_core_python.implement.action.default_extend_action_move.DefaultExtendActionMove CommandExecutorAmbulance: adf_core_python.implement.centralized.DefaultCommandExecutorAmbulance @@ -9,8 +9,8 @@ DefaultTacticsAmbulanceTeam: # ## DefaultTacticsFireBrigade DefaultTacticsFireBrigade: - HumanDetector: .module.complex._human_detector.HumanDetector - Search: .module.complex._search.Search + HumanDetector: team_name.module.complex.team_name_human_detector.TeamNameHumanDetector + Search: team_name.module.complex.team_name_search.TeamNameSearch ExtendActionRescue: adf_core_python.implement.action.default_extend_action_rescue.DefaultExtendActionRescue ExtendActionMove: adf_core_python.implement.action.default_extend_action_move.DefaultExtendActionMove CommandExecutorFire: adf_core_python.implement.centralized.DefaultCommandExecutorFire @@ -18,8 +18,8 @@ DefaultTacticsFireBrigade: # ## DefaultTacticsPoliceForce DefaultTacticsPoliceForce: - RoadDetector: .module.complex._road_detector.RoadDetector - Search: .module.complex._search.Search + RoadDetector: team_name.module.complex.team_name_road_detector.TeamNameRoadDetector + Search: team_name.module.complex.team_name_search.TeamNameSearch ExtendActionClear: adf_core_python.implement.action.default_extend_action_clear.DefaultExtendActionClear ExtendActionMove: adf_core_python.implement.action.default_extend_action_move.DefaultExtendActionMove CommandExecutorPolice: adf_core_python.implement.centralized.DefaultCommandExecutorPolice diff --git a/adf_core_python/cli/template/src//__init__.py b/adf_core_python/cli/template/src/team_name/__init__.py similarity index 100% rename from adf_core_python/cli/template/src//__init__.py rename to adf_core_python/cli/template/src/team_name/__init__.py diff --git a/adf_core_python/cli/template/src//module/__init__.py b/adf_core_python/cli/template/src/team_name/module/__init__.py similarity index 100% rename from adf_core_python/cli/template/src//module/__init__.py rename to adf_core_python/cli/template/src/team_name/module/__init__.py diff --git a/adf_core_python/cli/template/src//module/complex/__init__.py b/adf_core_python/cli/template/src/team_name/module/complex/__init__.py similarity index 100% rename from adf_core_python/cli/template/src//module/complex/__init__.py rename to adf_core_python/cli/template/src/team_name/module/complex/__init__.py diff --git a/adf_core_python/cli/template/src//module/complex/_human_detector.py b/adf_core_python/cli/template/src/team_name/module/complex/team_name_human_detector.py similarity index 99% rename from adf_core_python/cli/template/src//module/complex/_human_detector.py rename to adf_core_python/cli/template/src/team_name/module/complex/team_name_human_detector.py index 47202260..4cacc73c 100644 --- a/adf_core_python/cli/template/src//module/complex/_human_detector.py +++ b/adf_core_python/cli/template/src/team_name/module/complex/team_name_human_detector.py @@ -16,7 +16,7 @@ from adf_core_python.core.logger.logger import get_agent_logger -class DefaultHumanDetector(HumanDetector): +class TeamNameHumanDetector(HumanDetector): def __init__( self, agent_info: AgentInfo, diff --git a/adf_core_python/cli/template/src//module/complex/_road_detector.py b/adf_core_python/cli/template/src/team_name/module/complex/team_name_road_detector.py similarity index 99% rename from adf_core_python/cli/template/src//module/complex/_road_detector.py rename to adf_core_python/cli/template/src/team_name/module/complex/team_name_road_detector.py index adad2d8c..222d7170 100644 --- a/adf_core_python/cli/template/src//module/complex/_road_detector.py +++ b/adf_core_python/cli/template/src/team_name/module/complex/team_name_road_detector.py @@ -19,7 +19,7 @@ from adf_core_python.core.component.module.complex.road_detector import RoadDetector -class DefaultRoadDetector(RoadDetector): +class TeamNameRoadDetector(RoadDetector): def __init__( self, agent_info: AgentInfo, diff --git a/adf_core_python/cli/template/src//module/complex/_search.py b/adf_core_python/cli/template/src/team_name/module/complex/team_name_search.py similarity index 99% rename from adf_core_python/cli/template/src//module/complex/_search.py rename to adf_core_python/cli/template/src/team_name/module/complex/team_name_search.py index 05d7c888..286cde14 100644 --- a/adf_core_python/cli/template/src//module/complex/_search.py +++ b/adf_core_python/cli/template/src/team_name/module/complex/team_name_search.py @@ -17,7 +17,7 @@ from adf_core_python.core.logger.logger import get_agent_logger -class DefaultSearch(Search): +class TeamNameSearch(Search): def __init__( self, agent_info: AgentInfo, From 04565526f0e1e3c2169e3e3844a4b1542ace9969 Mon Sep 17 00:00:00 2001 From: shima004 Date: Wed, 20 Nov 2024 23:58:13 +0900 Subject: [PATCH 4/6] refactor: update placeholder names and class references in CLI templates --- adf_core_python/cli/cli.py | 37 ++++++++++--------- .../cli/template/config/module.yaml | 12 +++--- ...n_detector.py => sample_human_detector.py} | 2 +- ...ad_detector.py => sample_road_detector.py} | 2 +- .../{team_name_search.py => sample_search.py} | 2 +- 5 files changed, 28 insertions(+), 27 deletions(-) rename adf_core_python/cli/template/src/team_name/module/complex/{team_name_human_detector.py => sample_human_detector.py} (99%) rename adf_core_python/cli/template/src/team_name/module/complex/{team_name_road_detector.py => sample_road_detector.py} (99%) rename adf_core_python/cli/template/src/team_name/module/complex/{team_name_search.py => sample_search.py} (99%) diff --git a/adf_core_python/cli/cli.py b/adf_core_python/cli/cli.py index 1031fa23..853e3604 100644 --- a/adf_core_python/cli/cli.py +++ b/adf_core_python/cli/cli.py @@ -2,8 +2,7 @@ import click -LOWER_NAME_PLACEHOLDER = "team_name" -UPPER_NAME_PLACEHOLDER = "TeamName" +NAME_PLACEHOLDER = "team_name" @click.command() @@ -13,8 +12,6 @@ def cli(name): # load template dir and create a new agent team click.echo(f"Creating a new agent team with name: {name}") - lower_name = name.lower() - upper_name = name.upper() # 自身がいるディレクトリを取得 template_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), "template") click.echo(f"Current file path: {template_dir}") @@ -22,10 +19,18 @@ def cli(name): current_dir = os.getcwd() click.echo(f"Current directory: {current_dir}") - _copy_template(template_dir, current_dir, lower_name, upper_name) + _copy_template( + template_dir, + current_dir, + name, + ) -def _copy_template(src, dest, lower_name, upper_name): +def _copy_template( + src, + dest, + name, +): if os.path.isdir(src): if not os.path.exists(dest): os.makedirs(dest) @@ -33,22 +38,18 @@ def _copy_template(src, dest, lower_name, upper_name): s = os.path.join(src, item) d = os.path.join( dest, - item.replace(LOWER_NAME_PLACEHOLDER, lower_name).replace( - UPPER_NAME_PLACEHOLDER, upper_name - ), + item.replace(NAME_PLACEHOLDER, name), ) - _copy_template(s, d, lower_name, upper_name) + _copy_template(s, d, name) else: with open(src, "r") as f: content = f.read() with open(dest, "w") as f: - f.write( - content.replace(LOWER_NAME_PLACEHOLDER, lower_name).replace( - UPPER_NAME_PLACEHOLDER, upper_name - ) - ) - new_dest = dest.replace(LOWER_NAME_PLACEHOLDER, lower_name).replace( - UPPER_NAME_PLACEHOLDER, upper_name - ) + f.write(content.replace(NAME_PLACEHOLDER, name)) + new_dest = dest.replace(NAME_PLACEHOLDER, name) if new_dest != dest: os.rename(dest, new_dest) + + +if __name__ == "__main__": + cli() diff --git a/adf_core_python/cli/template/config/module.yaml b/adf_core_python/cli/template/config/module.yaml index 3f7467a7..80a7b35f 100644 --- a/adf_core_python/cli/template/config/module.yaml +++ b/adf_core_python/cli/template/config/module.yaml @@ -1,7 +1,7 @@ ## DefaultTacticsAmbulanceTeam DefaultTacticsAmbulanceTeam: - HumanDetector: team_name.module.complex.team_name_human_detector.TeamNameHumanDetector - Search: team_name.module.complex.team_name_search.TeamNameSearch + HumanDetector: team_name.module.complex.sample_human_detector.SampleHumanDetector + Search: team_name.module.complex.sample_search.SampleSearch ExtendActionTransport: adf_core_python.implement.action.default_extend_action_transport.DefaultExtendActionTransport ExtendActionMove: adf_core_python.implement.action.default_extend_action_move.DefaultExtendActionMove CommandExecutorAmbulance: adf_core_python.implement.centralized.DefaultCommandExecutorAmbulance @@ -9,8 +9,8 @@ DefaultTacticsAmbulanceTeam: # ## DefaultTacticsFireBrigade DefaultTacticsFireBrigade: - HumanDetector: team_name.module.complex.team_name_human_detector.TeamNameHumanDetector - Search: team_name.module.complex.team_name_search.TeamNameSearch + HumanDetector: team_name.module.complex.sample_human_detector.SampleHumanDetector + Search: team_name.module.complex.sample_search.SampleSearch ExtendActionRescue: adf_core_python.implement.action.default_extend_action_rescue.DefaultExtendActionRescue ExtendActionMove: adf_core_python.implement.action.default_extend_action_move.DefaultExtendActionMove CommandExecutorFire: adf_core_python.implement.centralized.DefaultCommandExecutorFire @@ -18,8 +18,8 @@ DefaultTacticsFireBrigade: # ## DefaultTacticsPoliceForce DefaultTacticsPoliceForce: - RoadDetector: team_name.module.complex.team_name_road_detector.TeamNameRoadDetector - Search: team_name.module.complex.team_name_search.TeamNameSearch + RoadDetector: team_name.module.complex.sample_road_detector.SampleRoadDetector + Search: team_name.module.complex.sample_search.SampleSearch ExtendActionClear: adf_core_python.implement.action.default_extend_action_clear.DefaultExtendActionClear ExtendActionMove: adf_core_python.implement.action.default_extend_action_move.DefaultExtendActionMove CommandExecutorPolice: adf_core_python.implement.centralized.DefaultCommandExecutorPolice diff --git a/adf_core_python/cli/template/src/team_name/module/complex/team_name_human_detector.py b/adf_core_python/cli/template/src/team_name/module/complex/sample_human_detector.py similarity index 99% rename from adf_core_python/cli/template/src/team_name/module/complex/team_name_human_detector.py rename to adf_core_python/cli/template/src/team_name/module/complex/sample_human_detector.py index 4cacc73c..c3b95871 100644 --- a/adf_core_python/cli/template/src/team_name/module/complex/team_name_human_detector.py +++ b/adf_core_python/cli/template/src/team_name/module/complex/sample_human_detector.py @@ -16,7 +16,7 @@ from adf_core_python.core.logger.logger import get_agent_logger -class TeamNameHumanDetector(HumanDetector): +class SampleHumanDetector(HumanDetector): def __init__( self, agent_info: AgentInfo, diff --git a/adf_core_python/cli/template/src/team_name/module/complex/team_name_road_detector.py b/adf_core_python/cli/template/src/team_name/module/complex/sample_road_detector.py similarity index 99% rename from adf_core_python/cli/template/src/team_name/module/complex/team_name_road_detector.py rename to adf_core_python/cli/template/src/team_name/module/complex/sample_road_detector.py index 222d7170..a46e67e7 100644 --- a/adf_core_python/cli/template/src/team_name/module/complex/team_name_road_detector.py +++ b/adf_core_python/cli/template/src/team_name/module/complex/sample_road_detector.py @@ -19,7 +19,7 @@ from adf_core_python.core.component.module.complex.road_detector import RoadDetector -class TeamNameRoadDetector(RoadDetector): +class SampleRoadDetector(RoadDetector): def __init__( self, agent_info: AgentInfo, diff --git a/adf_core_python/cli/template/src/team_name/module/complex/team_name_search.py b/adf_core_python/cli/template/src/team_name/module/complex/sample_search.py similarity index 99% rename from adf_core_python/cli/template/src/team_name/module/complex/team_name_search.py rename to adf_core_python/cli/template/src/team_name/module/complex/sample_search.py index 286cde14..d1bbe049 100644 --- a/adf_core_python/cli/template/src/team_name/module/complex/team_name_search.py +++ b/adf_core_python/cli/template/src/team_name/module/complex/sample_search.py @@ -17,7 +17,7 @@ from adf_core_python.core.logger.logger import get_agent_logger -class TeamNameSearch(Search): +class SampleSearch(Search): def __init__( self, agent_info: AgentInfo, From a17f233a2d9f0ea99c70e9cbf507328eaec08a5f Mon Sep 17 00:00:00 2001 From: shima004 Date: Thu, 21 Nov 2024 11:47:27 +0900 Subject: [PATCH 5/6] feat: update team configuration and add main launcher script for CLI --- adf_core_python/cli/template/config/launcher.yaml | 6 +++--- adf_core_python/cli/template/config/module.yaml | 12 ++++++------ adf_core_python/cli/template/main.py | 5 +++++ 3 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 adf_core_python/cli/template/main.py diff --git a/adf_core_python/cli/template/config/launcher.yaml b/adf_core_python/cli/template/config/launcher.yaml index 42525854..67826727 100644 --- a/adf_core_python/cli/template/config/launcher.yaml +++ b/adf_core_python/cli/template/config/launcher.yaml @@ -21,11 +21,11 @@ adf: team: platoon: ambulance: - count: 1 + count: 100 fire: - count: 0 + count: 100 police: - count: 0 + count: 100 office: ambulance: count: -1 diff --git a/adf_core_python/cli/template/config/module.yaml b/adf_core_python/cli/template/config/module.yaml index 80a7b35f..dbf215b5 100644 --- a/adf_core_python/cli/template/config/module.yaml +++ b/adf_core_python/cli/template/config/module.yaml @@ -1,7 +1,7 @@ ## DefaultTacticsAmbulanceTeam DefaultTacticsAmbulanceTeam: - HumanDetector: team_name.module.complex.sample_human_detector.SampleHumanDetector - Search: team_name.module.complex.sample_search.SampleSearch + HumanDetector: src.team_name.module.complex.sample_human_detector.SampleHumanDetector + Search: src.team_name.module.complex.sample_search.SampleSearch ExtendActionTransport: adf_core_python.implement.action.default_extend_action_transport.DefaultExtendActionTransport ExtendActionMove: adf_core_python.implement.action.default_extend_action_move.DefaultExtendActionMove CommandExecutorAmbulance: adf_core_python.implement.centralized.DefaultCommandExecutorAmbulance @@ -9,8 +9,8 @@ DefaultTacticsAmbulanceTeam: # ## DefaultTacticsFireBrigade DefaultTacticsFireBrigade: - HumanDetector: team_name.module.complex.sample_human_detector.SampleHumanDetector - Search: team_name.module.complex.sample_search.SampleSearch + HumanDetector: src.team_name.module.complex.sample_human_detector.SampleHumanDetector + Search: src.team_name.module.complex.sample_search.SampleSearch ExtendActionRescue: adf_core_python.implement.action.default_extend_action_rescue.DefaultExtendActionRescue ExtendActionMove: adf_core_python.implement.action.default_extend_action_move.DefaultExtendActionMove CommandExecutorFire: adf_core_python.implement.centralized.DefaultCommandExecutorFire @@ -18,8 +18,8 @@ DefaultTacticsFireBrigade: # ## DefaultTacticsPoliceForce DefaultTacticsPoliceForce: - RoadDetector: team_name.module.complex.sample_road_detector.SampleRoadDetector - Search: team_name.module.complex.sample_search.SampleSearch + RoadDetector: src.team_name.module.complex.sample_road_detector.SampleRoadDetector + Search: src.team_name.module.complex.sample_search.SampleSearch ExtendActionClear: adf_core_python.implement.action.default_extend_action_clear.DefaultExtendActionClear ExtendActionMove: adf_core_python.implement.action.default_extend_action_move.DefaultExtendActionMove CommandExecutorPolice: adf_core_python.implement.centralized.DefaultCommandExecutorPolice diff --git a/adf_core_python/cli/template/main.py b/adf_core_python/cli/template/main.py new file mode 100644 index 00000000..82ce430f --- /dev/null +++ b/adf_core_python/cli/template/main.py @@ -0,0 +1,5 @@ +from adf_core_python.launcher import Launcher + +if __name__ == "__main__": + launcher = Launcher("./config/launcher.yaml") + launcher.launch() From b80f8ce0ffcca6bd3267bdb9ad90d2f52d9ca2a1 Mon Sep 17 00:00:00 2001 From: shima004 Date: Thu, 21 Nov 2024 12:20:32 +0900 Subject: [PATCH 6/6] refactor: add type hints to CLI function and update parameter definitions --- adf_core_python/cli/cli.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/adf_core_python/cli/cli.py b/adf_core_python/cli/cli.py index 853e3604..fe2b3436 100644 --- a/adf_core_python/cli/cli.py +++ b/adf_core_python/cli/cli.py @@ -9,15 +9,13 @@ @click.option( "--name", prompt="Your agent team name", help="The name of your agent team" ) -def cli(name): +def cli(name: str) -> None: # load template dir and create a new agent team click.echo(f"Creating a new agent team with name: {name}") # 自身がいるディレクトリを取得 template_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), "template") - click.echo(f"Current file path: {template_dir}") # コマンドラインのカレントディレクトリを取得 current_dir = os.getcwd() - click.echo(f"Current directory: {current_dir}") _copy_template( template_dir, @@ -27,10 +25,10 @@ def cli(name): def _copy_template( - src, - dest, - name, -): + src: str, + dest: str, + name: str, +) -> None: if os.path.isdir(src): if not os.path.exists(dest): os.makedirs(dest)