Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions adf_core_python/core/agent/action/action.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from rcrs_core.commands.Command import Command
from rcrs_core.worldmodel.entityID import EntityID
from rcrs_core.commands.Command import Command
from rcrs_core.worldmodel.entityID import EntityID


class Action(ABC):
Expand Down
3 changes: 2 additions & 1 deletion adf_core_python/core/agent/action/common/action_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ def get_command(self, agent_id: EntityID, time: int) -> Command:
return AKMove(agent_id, time, path)

def __str__(self) -> str:
return f"ActionMove(path={self.path}, destination_x={self.destination_x}, destination_y{self.destination_y})"
path: str = ", ".join([str(p) for p in self.path])
return f"ActionMove(path={path}, destination_x={self.destination_x}, destination_y={self.destination_y})"
3 changes: 0 additions & 3 deletions adf_core_python/core/agent/config/module_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ def __init__(self, config_file_name: str = DEFAULT_CONFIG_FILE_NAME):
for key, value in flatten_data.items():
self.set_value(key, value)

for key, value in flatten_data.items():
print(f"{key}: {self.get_value(key)}")

def _read_from_yaml(self, file_name: str) -> dict[str, Any]:
"""
Read configuration from yaml file
Expand Down
4 changes: 2 additions & 2 deletions adf_core_python/core/agent/info/world_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def get_distance(self, entity_id1: EntityID, entity_id2: EntityID) -> float:
f"One or both entities are invalid: entity_id1={entity_id1}, entity_id2={entity_id2}, entity1={entity1}, entity2={entity2}"
)

location1_x, location1_y = entity1.get_location()
location2_x, location2_y = entity2.get_location()
location1_x, location1_y = entity1.get_x(), entity1.get_y()
location2_x, location2_y = entity2.get_x(), entity2.get_y()
if (
location1_x is None
or location1_y is None
Expand Down
2 changes: 1 addition & 1 deletion adf_core_python/core/agent/module/module_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import importlib
from typing import TYPE_CHECKING, Any

from adf_core_python.core.component.extaction.ext_action import ExtAction
from adf_core_python.core.component.module.abstract_module import AbstractModule

if TYPE_CHECKING:
Expand All @@ -11,7 +12,6 @@
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.component.extaction.ext_action import ExtAction


class ModuleManager:
Expand Down
22 changes: 20 additions & 2 deletions adf_core_python/core/agent/platoon/platoon.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from rcrs_core.agents.agent import Agent
from rcrs_core.commands.Command import Command
from rcrs_core.config.config import Config as RCRSConfig
from rcrs_core.worldmodel.changeSet import ChangeSet

from adf_core_python.core.agent.action.action import Action
Expand All @@ -14,6 +15,7 @@
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.tactics.tactics_agent import TacticsAgent
from adf_core_python.core.config.config import Config


class Platoon(Agent):
Expand Down Expand Up @@ -53,7 +55,21 @@ def post_connect(self) -> None:
# self._mode = Mode.NON_PRECOMPUTE
self._mode = Mode.NON_PRECOMPUTE

self._scenario_info: ScenarioInfo = ScenarioInfo(self.config, self._mode) # type: ignore
config = Config()
if self.config is not None:
rcrc_config: RCRSConfig = self.config
for key, value in rcrc_config.data.items():
config.set_value(key, value)
for key, value in rcrc_config.int_data.items():
config.set_value(key, value)
for key, value in rcrc_config.float_data.items():
config.set_value(key, value)
for key, value in rcrc_config.boolean_data.items():
config.set_value(key, value)
for key, value in rcrc_config.array_data.items():
config.set_value(key, value)

self._scenario_info: ScenarioInfo = ScenarioInfo(config, self._mode)
self._module_manager: ModuleManager = ModuleManager(
self._agent_info,
self._world_info,
Expand Down Expand Up @@ -88,6 +104,8 @@ def post_connect(self) -> None:
)

def think(self, time: int, change_set: ChangeSet, hear: list[Command]) -> None:
self._agent_info.set_change_set(change_set)
self._world_info.set_change_set(change_set)
action: Action = self._tactics_agent.think(
self._agent_info,
self._world_info,
Expand All @@ -99,4 +117,4 @@ def think(self, time: int, change_set: ChangeSet, hear: list[Command]) -> None:
)
if action is not None and self.agent_id is not None:
self._agent_info.set_executed_action(time, action)
self.send_msg(action.get_command(self.agent_id, time))
self.send_msg(action.get_command(self.agent_id, time).prepare_cmd())
6 changes: 3 additions & 3 deletions adf_core_python/core/agent/platoon/platoon_ambulance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from rcrs_core.connection import URN
from rcrs_core.connection.URN import Entity as EntityURN

from adf_core_python.core.agent.config.module_config import ModuleConfig
from adf_core_python.core.agent.develop.develop_data import DevelopData
Expand Down Expand Up @@ -30,5 +30,5 @@ def __init__(
def precompute(self) -> None:
pass

def get_requested_entities(self) -> list[str]:
return [URN.Entity.AMBULANCE_TEAM]
def get_requested_entities(self) -> list[EntityURN]:
return [EntityURN.AMBULANCE_TEAM]
41 changes: 20 additions & 21 deletions adf_core_python/core/component/abstract_loader.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Optional

if TYPE_CHECKING:
from adf_core_python.core.component.tactics.tactics_ambulance_center import (
TacticsAmbulanceCenter,
)
from adf_core_python.core.component.tactics.tactics_ambulance_team import (
TacticsAmbulanceTeam,
)
from adf_core_python.core.component.tactics.tactics_fire_brigade import (
TacticsFireBrigade,
)
from adf_core_python.core.component.tactics.tactics_fire_station import (
TacticsFireStation,
)
from adf_core_python.core.component.tactics.tactics_police_force import (
TacticsPoliceForce,
)
from adf_core_python.core.component.tactics.tactics_police_office import (
TacticsPoliceOffice,
)
from typing import Optional

from adf_core_python.core.component.tactics.tactics_ambulance_center import (
TacticsAmbulanceCenter,
)
from adf_core_python.core.component.tactics.tactics_ambulance_team import (
TacticsAmbulanceTeam,
)
from adf_core_python.core.component.tactics.tactics_fire_brigade import (
TacticsFireBrigade,
)
from adf_core_python.core.component.tactics.tactics_fire_station import (
TacticsFireStation,
)
from adf_core_python.core.component.tactics.tactics_police_force import (
TacticsPoliceForce,
)
from adf_core_python.core.component.tactics.tactics_police_office import (
TacticsPoliceOffice,
)


class AbstractLoader(ABC):
Expand Down
30 changes: 22 additions & 8 deletions adf_core_python/core/component/tactics/tactics_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,29 +113,43 @@ def module_precompute(self, precompute_data: PrecomputeData) -> None:
module.precompute(precompute_data)
for action in self._actions:
action.precompute(precompute_data)
for executor in self._command_executor:
executor.precompute(precompute_data)
# for executor in self._command_executor:
# executor.precompute(precompute_data)

def module_resume(self, precompute_data: PrecomputeData) -> None:
for module in self._modules:
module.resume(precompute_data)
for action in self._actions:
action.resume(precompute_data)
for executor in self._command_executor:
executor.resume(precompute_data)
# for executor in self._command_executor:
# executor.resume(precompute_data)

def module_prepare(self) -> None:
for module in self._modules:
module.prepare()
for action in self._actions:
action.prepare()
for executor in self._command_executor:
executor.prepare()
# for executor in self._command_executor:
# executor.prepare()

def module_update_info(self, message_manager: MessageManager) -> None:
for module in self._modules:
module.update_info(message_manager)
for action in self._actions:
action.update_info(message_manager)
for executor in self._command_executor:
executor.update_info(message_manager)
# for executor in self._command_executor:
# executor.update_info(message_manager)

def reset_count(self) -> None:
for module in self._modules:
module.reset_count_precompute()
module.reset_count_resume()
module.reset_count_prepare()
module.reset_count_update_info()
for action in self._actions:
action.reset_count_precompute()
action.reset_count_resume()
action.reset_count_prepare()
action.reset_count_update_info()
# for executor in self._command_executor:
# executor.reset_count()
52 changes: 26 additions & 26 deletions adf_core_python/core/launcher/agent_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@
from adf_core_python.core.config.config import Config
from adf_core_python.core.launcher.config_key import ConfigKey
from adf_core_python.core.launcher.connect.connector import Connector
from adf_core_python.core.launcher.connect.connector_ambulance_centre import (
ConnectorAmbulanceCentre,
)

# from adf_core_python.core.launcher.connect.connector_ambulance_centre import (
# ConnectorAmbulanceCentre,
# )
from adf_core_python.core.launcher.connect.connector_ambulance_team import (
ConnectorAmbulanceTeam,
)
from adf_core_python.core.launcher.connect.connector_fire_brigade import (
ConnectorFireBrigade,
)
from adf_core_python.core.launcher.connect.connector_fire_station import (
ConnectorFireStation,
)
from adf_core_python.core.launcher.connect.connector_police_force import (
ConnectorPoliceForce,
)
from adf_core_python.core.launcher.connect.connector_police_office import (
ConnectorPoliceOffice,
)

# from adf_core_python.core.launcher.connect.connector_fire_brigade import (
# ConnectorFireBrigade,
# )
# from adf_core_python.core.launcher.connect.connector_fire_station import (
# ConnectorFireStation,
# )
# from adf_core_python.core.launcher.connect.connector_police_force import (
# ConnectorPoliceForce,
# )
# from adf_core_python.core.launcher.connect.connector_police_office import (
# ConnectorPoliceOffice,
# )


class AgentLauncher:
Expand All @@ -48,12 +50,12 @@ def init_connector(self) -> None:
self.config.get_value(ConfigKey.KEY_TEAM_NAME),
)

self.connectors.append(ConnectorAmbulanceCentre())
# self.connectors.append(ConnectorAmbulanceCentre())
self.connectors.append(ConnectorAmbulanceTeam())
self.connectors.append(ConnectorFireBrigade())
self.connectors.append(ConnectorFireStation())
self.connectors.append(ConnectorPoliceForce())
self.connectors.append(ConnectorPoliceOffice())
# self.connectors.append(ConnectorFireBrigade())
# self.connectors.append(ConnectorFireStation())
# self.connectors.append(ConnectorPoliceForce())
# self.connectors.append(ConnectorPoliceOffice())

def launch(self) -> None:
host: str = self.config.get_value(ConfigKey.KEY_KERNEL_HOST, "localhost")
Expand All @@ -63,12 +65,10 @@ def launch(self) -> None:
component_launcher: ComponentLauncher = ComponentLauncher(port, host)

for connector in self.connectors:
thread = threading.Thread(
target=connector.connect,
args=(component_launcher, self.config, self.loader),
)
thread.start()
self.thread_list.append(thread)
threads = connector.connect(component_launcher, self.config, self.loader)
for thread in threads:
thread.start()
self.thread_list.extend(threads)

for thread in self.thread_list:
thread.join()
Expand Down
3 changes: 2 additions & 1 deletion adf_core_python/core/launcher/connect/connector.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import threading
from abc import ABC, abstractmethod

from rcrs_core.connection.componentLauncher import ComponentLauncher
Expand All @@ -16,7 +17,7 @@ def connect(
component_launcher: ComponentLauncher,
config: Config,
loader: AbstractLoader,
) -> None:
) -> list[threading.Thread]:
raise NotImplementedError

def get_connected_agent_count(self) -> int:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import threading
from logging import Logger, getLogger

from rcrs_core.agents.ambulanceCenterAgent import AmbulanceCenterAgent
Expand All @@ -21,10 +22,12 @@ def connect(
component_launcher: ComponentLauncher,
config: Config,
loader: AbstractLoader,
) -> None:
) -> list[threading.Thread]:
count: int = config.get_value(ConfigKey.KEY_AMBULANCE_CENTRE_COUNT, 0)
if count == 0:
return
return []

threads: list[threading.Thread] = []

for _ in range(count):
# tactics_ambulance_centre: TacticsAmbulanceCentre
Expand All @@ -50,12 +53,16 @@ def connect(
)

# TODO: component_launcher.generate_request_ID can cause race condition
component_launcher.connect(
# TODO: AmbulanceCenterAgent is not implemented precompute method and other methods
AmbulanceCenterAgent(
config.get_value(ConfigKey.KEY_PRECOMPUTE, False),
), # type: ignore
component_launcher.generate_request_ID(),
thread = threading.Thread(
target=component_launcher.connect,
args=(
AmbulanceCenterAgent(
config.get_value(ConfigKey.KEY_PRECOMPUTE, False),
), # type: ignore
component_launcher.generate_request_ID(),
),
)
threads.append(thread)

self.logger.info("Connected ambulance centre (count: %d)" % count)
return threads
Loading