Skip to content

Commit 9aafcf7

Browse files
committed
feat: implement ambulance team
1 parent 9cbd07c commit 9aafcf7

File tree

17 files changed

+225
-108
lines changed

17 files changed

+225
-108
lines changed

adf_core_python/core/agent/action/common/action_move.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ def get_command(self, agent_id: EntityID, time: int) -> Command:
3030
return AKMove(agent_id, time, path)
3131

3232
def __str__(self) -> str:
33-
return f"ActionMove(path={self.path}, destination_x={self.destination_x}, destination_y{self.destination_y})"
33+
path: str = ", ".join([str(p) for p in self.path])
34+
return f"ActionMove(path={path}, destination_x={self.destination_x}, destination_y={self.destination_y})"

adf_core_python/core/agent/info/world_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ def get_distance(self, entity_id1: EntityID, entity_id2: EntityID) -> float:
125125
f"One or both entities are invalid: entity_id1={entity_id1}, entity_id2={entity_id2}, entity1={entity1}, entity2={entity2}"
126126
)
127127

128-
location1_x, location1_y = entity1.get_location()
129-
location2_x, location2_y = entity2.get_location()
128+
location1_x, location1_y = entity1.get_x(), entity1.get_y()
129+
location2_x, location2_y = entity2.get_x(), entity2.get_y()
130130
if (
131131
location1_x is None
132132
or location1_y is None

adf_core_python/core/agent/module/module_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import importlib
44
from typing import TYPE_CHECKING, Any
55

6+
from adf_core_python.core.component.extaction.ext_action import ExtAction
67
from adf_core_python.core.component.module.abstract_module import AbstractModule
78

89
if TYPE_CHECKING:
@@ -11,7 +12,6 @@
1112
from adf_core_python.core.agent.info.agent_info import AgentInfo
1213
from adf_core_python.core.agent.info.scenario_info import ScenarioInfo
1314
from adf_core_python.core.agent.info.world_info import WorldInfo
14-
from adf_core_python.core.component.extaction.ext_action import ExtAction
1515

1616

1717
class ModuleManager:

adf_core_python/core/agent/platoon/platoon.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from rcrs_core.agents.agent import Agent
44
from rcrs_core.commands.Command import Command
5+
from rcrs_core.config.config import Config as RCRSConfig
56
from rcrs_core.worldmodel.changeSet import ChangeSet
67

78
from adf_core_python.core.agent.action.action import Action
@@ -14,6 +15,7 @@
1415
from adf_core_python.core.agent.module.module_manager import ModuleManager
1516
from adf_core_python.core.agent.precompute.precompute_data import PrecomputeData
1617
from adf_core_python.core.component.tactics.tactics_agent import TacticsAgent
18+
from adf_core_python.core.config.config import Config
1719

1820

1921
class Platoon(Agent):
@@ -53,7 +55,21 @@ def post_connect(self) -> None:
5355
# self._mode = Mode.NON_PRECOMPUTE
5456
self._mode = Mode.NON_PRECOMPUTE
5557

56-
self._scenario_info: ScenarioInfo = ScenarioInfo(self.config, self._mode) # type: ignore
58+
config = Config()
59+
if self.config is not None:
60+
rcrc_config: RCRSConfig = self.config
61+
for key, value in rcrc_config.data.items():
62+
config.set_value(key, value)
63+
for key, value in rcrc_config.int_data.items():
64+
config.set_value(key, value)
65+
for key, value in rcrc_config.float_data.items():
66+
config.set_value(key, value)
67+
for key, value in rcrc_config.boolean_data.items():
68+
config.set_value(key, value)
69+
for key, value in rcrc_config.array_data.items():
70+
config.set_value(key, value)
71+
72+
self._scenario_info: ScenarioInfo = ScenarioInfo(config, self._mode)
5773
self._module_manager: ModuleManager = ModuleManager(
5874
self._agent_info,
5975
self._world_info,
@@ -88,6 +104,8 @@ def post_connect(self) -> None:
88104
)
89105

90106
def think(self, time: int, change_set: ChangeSet, hear: list[Command]) -> None:
107+
self._agent_info.set_change_set(change_set)
108+
self._world_info.set_change_set(change_set)
91109
action: Action = self._tactics_agent.think(
92110
self._agent_info,
93111
self._world_info,
@@ -99,4 +117,4 @@ def think(self, time: int, change_set: ChangeSet, hear: list[Command]) -> None:
99117
)
100118
if action is not None and self.agent_id is not None:
101119
self._agent_info.set_executed_action(time, action)
102-
self.send_msg(action.get_command(self.agent_id, time))
120+
self.send_msg(action.get_command(self.agent_id, time).prepare_cmd())

adf_core_python/core/agent/platoon/platoon_ambulance.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from rcrs_core.connection import URN
1+
from rcrs_core.connection.URN import Entity as EntityURN
22

33
from adf_core_python.core.agent.config.module_config import ModuleConfig
44
from adf_core_python.core.agent.develop.develop_data import DevelopData
@@ -30,5 +30,5 @@ def __init__(
3030
def precompute(self) -> None:
3131
pass
3232

33-
def get_requested_entities(self) -> list[str]:
34-
return [URN.Entity.AMBULANCE_TEAM]
33+
def get_requested_entities(self) -> list[EntityURN]:
34+
return [EntityURN.AMBULANCE_TEAM]

adf_core_python/core/component/tactics/tactics_agent.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,29 +113,43 @@ def module_precompute(self, precompute_data: PrecomputeData) -> None:
113113
module.precompute(precompute_data)
114114
for action in self._actions:
115115
action.precompute(precompute_data)
116-
for executor in self._command_executor:
117-
executor.precompute(precompute_data)
116+
# for executor in self._command_executor:
117+
# executor.precompute(precompute_data)
118118

119119
def module_resume(self, precompute_data: PrecomputeData) -> None:
120120
for module in self._modules:
121121
module.resume(precompute_data)
122122
for action in self._actions:
123123
action.resume(precompute_data)
124-
for executor in self._command_executor:
125-
executor.resume(precompute_data)
124+
# for executor in self._command_executor:
125+
# executor.resume(precompute_data)
126126

127127
def module_prepare(self) -> None:
128128
for module in self._modules:
129129
module.prepare()
130130
for action in self._actions:
131131
action.prepare()
132-
for executor in self._command_executor:
133-
executor.prepare()
132+
# for executor in self._command_executor:
133+
# executor.prepare()
134134

135135
def module_update_info(self, message_manager: MessageManager) -> None:
136136
for module in self._modules:
137137
module.update_info(message_manager)
138138
for action in self._actions:
139139
action.update_info(message_manager)
140-
for executor in self._command_executor:
141-
executor.update_info(message_manager)
140+
# for executor in self._command_executor:
141+
# executor.update_info(message_manager)
142+
143+
def reset_count(self) -> None:
144+
for module in self._modules:
145+
module.reset_count_precompute()
146+
module.reset_count_resume()
147+
module.reset_count_prepare()
148+
module.reset_count_update_info()
149+
for action in self._actions:
150+
action.reset_count_precompute()
151+
action.reset_count_resume()
152+
action.reset_count_prepare()
153+
action.reset_count_update_info()
154+
# for executor in self._command_executor:
155+
# executor.reset_count()

adf_core_python/core/launcher/agent_launcher.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,26 @@
88
from adf_core_python.core.config.config import Config
99
from adf_core_python.core.launcher.config_key import ConfigKey
1010
from adf_core_python.core.launcher.connect.connector import Connector
11-
from adf_core_python.core.launcher.connect.connector_ambulance_centre import (
12-
ConnectorAmbulanceCentre,
13-
)
11+
12+
# from adf_core_python.core.launcher.connect.connector_ambulance_centre import (
13+
# ConnectorAmbulanceCentre,
14+
# )
1415
from adf_core_python.core.launcher.connect.connector_ambulance_team import (
1516
ConnectorAmbulanceTeam,
1617
)
17-
from adf_core_python.core.launcher.connect.connector_fire_brigade import (
18-
ConnectorFireBrigade,
19-
)
20-
from adf_core_python.core.launcher.connect.connector_fire_station import (
21-
ConnectorFireStation,
22-
)
23-
from adf_core_python.core.launcher.connect.connector_police_force import (
24-
ConnectorPoliceForce,
25-
)
26-
from adf_core_python.core.launcher.connect.connector_police_office import (
27-
ConnectorPoliceOffice,
28-
)
18+
19+
# from adf_core_python.core.launcher.connect.connector_fire_brigade import (
20+
# ConnectorFireBrigade,
21+
# )
22+
# from adf_core_python.core.launcher.connect.connector_fire_station import (
23+
# ConnectorFireStation,
24+
# )
25+
# from adf_core_python.core.launcher.connect.connector_police_force import (
26+
# ConnectorPoliceForce,
27+
# )
28+
# from adf_core_python.core.launcher.connect.connector_police_office import (
29+
# ConnectorPoliceOffice,
30+
# )
2931

3032

3133
class AgentLauncher:
@@ -63,12 +65,10 @@ def launch(self) -> None:
6365
component_launcher: ComponentLauncher = ComponentLauncher(port, host)
6466

6567
for connector in self.connectors:
66-
thread = threading.Thread(
67-
target=connector.connect,
68-
args=(component_launcher, self.config, self.loader),
69-
)
70-
thread.start()
71-
self.thread_list.append(thread)
68+
threads = connector.connect(component_launcher, self.config, self.loader)
69+
for thread in threads:
70+
thread.start()
71+
self.thread_list.extend(threads)
7272

7373
for thread in self.thread_list:
7474
thread.join()

adf_core_python/implement/default_loader.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import TYPE_CHECKING
2-
31
from adf_core_python.core.component.abstract_loader import AbstractLoader
42
from adf_core_python.core.component.tactics.tactics_ambulance_center import (
53
TacticsAmbulanceCenter,

adf_core_python/implement/extend_action/default_extend_action_move.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from logging import Logger, getLogger
12
from typing import Optional, cast
23

34
from rcrs_core.entities.area import Area
@@ -32,14 +33,15 @@ def __init__(
3233
)
3334
self._target_entity_id: Optional[EntityID] = None
3435
self._threshold_to_rest: int = develop_data.get_value("threshold_to_rest", 100)
36+
self._logger: Logger = getLogger(__name__)
3537

3638
match self.scenario_info.get_mode():
3739
case Mode.NON_PRECOMPUTE:
3840
self._path_planning: PathPlanning = cast(
3941
PathPlanning,
4042
self.module_manager.get_module(
4143
"DefaultExtendActionMove.PathPlanning",
42-
"adf_core_python.implement.module.astar_path_planning.AStarPathPlanning",
44+
"adf_core_python.implement.module.algorithm.a_star_path_planning.AStarPathPlanning",
4345
),
4446
)
4547
case Mode.PRECOMPUTATION:
@@ -87,20 +89,20 @@ def set_target_entity_id(self, target_entity_id: EntityID) -> ExtAction:
8789
elif isinstance(entity, Human):
8890
entity = entity.get_position()
8991

90-
if entity is None and isinstance(entity, Area):
91-
self._target_entity_id = None
92+
if entity is not None and isinstance(entity, Area):
93+
self._target_entity_id = entity.get_id()
9294

9395
return self
9496

9597
def calc(self) -> ExtAction:
96-
self._result = None
98+
self.result = None
9799
agent: Human = cast(Human, self.agent_info.get_myself())
98100

99101
path: list[EntityID] = self._path_planning.get_path(
100102
agent.get_position(), self._target_entity_id
101103
)
102104

103-
if path is not None or len(path) != 0:
105+
if path is not None and len(path) != 0:
104106
self.result = ActionMove(path)
105107

106108
return self

adf_core_python/implement/extend_action/default_extend_action_transport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(
4545
PathPlanning,
4646
self.module_manager.get_module(
4747
"DefaultExtendActionMove.PathPlanning",
48-
"adf_core_python.implement.module.astar_path_planning.AStarPathPlanning",
48+
"adf_core_python.implement.module.algorithm.a_star_path_planning.AStarPathPlanning",
4949
),
5050
)
5151
case Mode.PRECOMPUTATION:

0 commit comments

Comments
 (0)