Add agent reset for episodes
This commit is contained in:
@@ -15,6 +15,7 @@ class DataManipulationAgent(AbstractScriptedAgent):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
print("red start step: ", self.agent_settings.start_settings.start_step)
|
||||||
|
|
||||||
self._set_next_execution_timestep(self.agent_settings.start_settings.start_step)
|
self._set_next_execution_timestep(self.agent_settings.start_settings.start_step)
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ class DataManipulationAgent(AbstractScriptedAgent):
|
|||||||
-self.agent_settings.start_settings.variance, self.agent_settings.start_settings.variance
|
-self.agent_settings.start_settings.variance, self.agent_settings.start_settings.variance
|
||||||
)
|
)
|
||||||
self.next_execution_timestep = timestep + random_timestep_increment
|
self.next_execution_timestep = timestep + random_timestep_increment
|
||||||
|
print("next execution red step: ", self.next_execution_timestep)
|
||||||
|
|
||||||
def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]:
|
def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]:
|
||||||
"""Randomly sample an action from the action space.
|
"""Randomly sample an action from the action space.
|
||||||
@@ -41,8 +43,15 @@ class DataManipulationAgent(AbstractScriptedAgent):
|
|||||||
current_timestep = self.action_manager.game.step_counter
|
current_timestep = self.action_manager.game.step_counter
|
||||||
|
|
||||||
if current_timestep < self.next_execution_timestep:
|
if current_timestep < self.next_execution_timestep:
|
||||||
|
print("red agent doing nothing")
|
||||||
return "DONOTHING", {"dummy": 0}
|
return "DONOTHING", {"dummy": 0}
|
||||||
|
|
||||||
self._set_next_execution_timestep(current_timestep + self.agent_settings.start_settings.frequency)
|
self._set_next_execution_timestep(current_timestep + self.agent_settings.start_settings.frequency)
|
||||||
|
|
||||||
|
print("red agent doing an execute")
|
||||||
return "NODE_APPLICATION_EXECUTE", {"node_id": 0, "application_id": 0}
|
return "NODE_APPLICATION_EXECUTE", {"node_id": 0, "application_id": 0}
|
||||||
|
|
||||||
|
def reset_agent_for_episode(self) -> None:
|
||||||
|
"""Set the next execution timestep when the episode resets."""
|
||||||
|
super().reset_agent_for_episode()
|
||||||
|
self._set_next_execution_timestep(self.agent_settings.start_settings.start_step)
|
||||||
|
|||||||
@@ -135,6 +135,10 @@ class AbstractAgent(ABC):
|
|||||||
request = self.action_manager.form_request(action_identifier=action, action_options=options)
|
request = self.action_manager.form_request(action_identifier=action, action_options=options)
|
||||||
return request
|
return request
|
||||||
|
|
||||||
|
def reset_agent_for_episode(self) -> None:
|
||||||
|
"""Agent reset logic should go here."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AbstractScriptedAgent(AbstractAgent):
|
class AbstractScriptedAgent(AbstractAgent):
|
||||||
"""Base class for actors which generate their own behaviour."""
|
"""Base class for actors which generate their own behaviour."""
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ class PrimaiteGame:
|
|||||||
self.simulation.reset_component_for_episode(episode=self.episode_counter)
|
self.simulation.reset_component_for_episode(episode=self.episode_counter)
|
||||||
for agent in self.agents:
|
for agent in self.agents:
|
||||||
agent.reward_function.total_reward = 0.0
|
agent.reward_function.total_reward = 0.0
|
||||||
|
agent.reset_agent_for_episode()
|
||||||
|
|
||||||
def close(self) -> None:
|
def close(self) -> None:
|
||||||
"""Close the game, this will close the simulation."""
|
"""Close the game, this will close the simulation."""
|
||||||
|
|||||||
Reference in New Issue
Block a user