Skip to content

Commit 533157a

Browse files
authored
Merge pull request #54 from adf-python/ambulanceteam
AmbulanceTeamが動くようにする
2 parents 6a340b6 + 9aafcf7 commit 533157a

28 files changed

+449
-160
lines changed

adf_core_python/core/agent/action/action.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from abc import ABC, abstractmethod
2-
from typing import TYPE_CHECKING
32

4-
if TYPE_CHECKING:
5-
from rcrs_core.commands.Command import Command
6-
from rcrs_core.worldmodel.entityID import EntityID
3+
from rcrs_core.commands.Command import Command
4+
from rcrs_core.worldmodel.entityID import EntityID
75

86

97
class Action(ABC):

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/config/module_config.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ def __init__(self, config_file_name: str = DEFAULT_CONFIG_FILE_NAME):
3535
for key, value in flatten_data.items():
3636
self.set_value(key, value)
3737

38-
for key, value in flatten_data.items():
39-
print(f"{key}: {self.get_value(key)}")
40-
4138
def _read_from_yaml(self, file_name: str) -> dict[str, Any]:
4239
"""
4340
Read configuration from yaml file

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/abstract_loader.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
from abc import ABC, abstractmethod
2-
from typing import TYPE_CHECKING, Optional
3-
4-
if TYPE_CHECKING:
5-
from adf_core_python.core.component.tactics.tactics_ambulance_center import (
6-
TacticsAmbulanceCenter,
7-
)
8-
from adf_core_python.core.component.tactics.tactics_ambulance_team import (
9-
TacticsAmbulanceTeam,
10-
)
11-
from adf_core_python.core.component.tactics.tactics_fire_brigade import (
12-
TacticsFireBrigade,
13-
)
14-
from adf_core_python.core.component.tactics.tactics_fire_station import (
15-
TacticsFireStation,
16-
)
17-
from adf_core_python.core.component.tactics.tactics_police_force import (
18-
TacticsPoliceForce,
19-
)
20-
from adf_core_python.core.component.tactics.tactics_police_office import (
21-
TacticsPoliceOffice,
22-
)
2+
from typing import Optional
3+
4+
from adf_core_python.core.component.tactics.tactics_ambulance_center import (
5+
TacticsAmbulanceCenter,
6+
)
7+
from adf_core_python.core.component.tactics.tactics_ambulance_team import (
8+
TacticsAmbulanceTeam,
9+
)
10+
from adf_core_python.core.component.tactics.tactics_fire_brigade import (
11+
TacticsFireBrigade,
12+
)
13+
from adf_core_python.core.component.tactics.tactics_fire_station import (
14+
TacticsFireStation,
15+
)
16+
from adf_core_python.core.component.tactics.tactics_police_force import (
17+
TacticsPoliceForce,
18+
)
19+
from adf_core_python.core.component.tactics.tactics_police_office import (
20+
TacticsPoliceOffice,
21+
)
2322

2423

2524
class AbstractLoader(ABC):

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: 26 additions & 26 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:
@@ -48,12 +50,12 @@ def init_connector(self) -> None:
4850
self.config.get_value(ConfigKey.KEY_TEAM_NAME),
4951
)
5052

51-
self.connectors.append(ConnectorAmbulanceCentre())
53+
# self.connectors.append(ConnectorAmbulanceCentre())
5254
self.connectors.append(ConnectorAmbulanceTeam())
53-
self.connectors.append(ConnectorFireBrigade())
54-
self.connectors.append(ConnectorFireStation())
55-
self.connectors.append(ConnectorPoliceForce())
56-
self.connectors.append(ConnectorPoliceOffice())
55+
# self.connectors.append(ConnectorFireBrigade())
56+
# self.connectors.append(ConnectorFireStation())
57+
# self.connectors.append(ConnectorPoliceForce())
58+
# self.connectors.append(ConnectorPoliceOffice())
5759

5860
def launch(self) -> None:
5961
host: str = self.config.get_value(ConfigKey.KEY_KERNEL_HOST, "localhost")
@@ -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()

0 commit comments

Comments
 (0)