pymasep.common.environment
Classes
Represents the environment of the game. This object keeps all dynamic value of the game. |
Module Contents
- class pymasep.common.environment.Environment(id_env=None, cfg=None)
Represents the environment of the game. This object keeps all dynamic value of the game.
- Parameters:
id_env (str) – the id of the environment. If None, a new uuid will be set
cfg (omegaconf.DictConfig)
- Parm cfg:
the configuration of the environment
- id: str
Environment id.
- config
configuration of the environment.
- end_episode: bool = False
the current episode is finished
- current_step: int = 0
current step of the environment
- current_episode: int = 0
current episode of the environment
- current_state: pymasep.common.state.State | None = None
current state of the environment
- current_additional_info: dict
current additional information of the environment, related to the current state. Sort of meta information on the current state
- agents: Set[pymasep.common.agent.Agent]
set of agents in the current state
- controllers: Dict[str, pymasep.common.controller.Controller]
set of controllers that can be used in the environment
- _game: pymasep.common.game.Game | None = None
- next_action: Dict[str, pymasep.common.action.Action]
next action to be executed in the current state
- _level_logger
- logger
logger for the environment tasks
- __del__()
- property game: pymasep.common.game.Game
Game of the environment.
- Return type:
- get_current_coord_method(state=None)
Return the current coordination method according to the current game phase in the state
- Parameters:
state (Optional[pymasep.common.state.State]) – State to check the coordination method. If None, take the current state of the environment.
- Returns:
The current coordinate method
- Return type:
str
- get_observation_for_agent(agent)
Get the current observation. Current state at the moment
- Parameters:
agent (pymasep.common.agent.Agent) – The agent to get the observation for
- Returns:
The current observation
- Return type:
- get_additional_info_for_agent()
Get the current additional information. Could be filtered in the future (by agent)
- Returns:
The current additional information
- Return type:
dict
- get_reward_for_agent(agent)
Get the current reward for an agent.
- Parameters:
agent (pymasep.common.agent.Agent) – The agent to get the reward
- Returns:
The current reward of the agent
- Return type:
dict
- get_controller(agent_name, class_controller_)
Get the controller of an agent. If the controller is not created, create it. (Maybe I should change the name of this method…)
- Parameters:
agent_name (str) – The agent’s name
class_controller – the class of the controller to create if it is not created
class_controller_ (Type[pymasep.common.controller.Controller])
- Returns:
the instance of the agent’s controller
- Return type:
- calculate_end_episode()
Calculate the end of the episode. Modify self.end_episode if the conditions of the episode’s end are met.
- Return type:
None
- calculate_next_state()
Calculate the next state of the environment. Change the current state. Increase the step
- Return type:
None
- calculate_reward()
Calculate the reward from the current_state and add the result to additional info with key ‘reward’. For MDP point of view, support only (at the moment) \(R(s)\) and neither \(R(s,a)\) nor \(R(s,a,s')\)
- Return type:
None
- create_base_object(name=None, template=None, xml_node=None, parent=None)
Create a base object from a string represent the type
- Parameters:
name (Optional[str]) – The identification name of the BaseObject.
template (Optional[pymasep.common.template.Template]) – Template of the created object. If None and no XML is specified, will be the default template for this bo_type
xml_node (Optional[xml.etree.ElementTree.Element]) – XML node used for creating the base object
parent (Optional[pymasep.common.base_object.BaseObject]) – the parent of the current object. May be None.
- Returns:
The BaseObject instance
- get_type_controller(xml_node=None, template=None, control=None)
Get the type of controller according to a template or (exclusive) an XML node.
- Parameters:
xml_node (Optional[xml.etree.ElementTree.Element]) – XML node used to get the controller type. Use the attribute “controller”.
template (Optional[pymasep.common.template.Template]) – The template used to get the controller type.
control (Optional[str]) – ‘Interface’ if the agent is controlled by interface (only inside engine, and if template is used)
- Returns:
the class of the controller to use
- Return type:
- create_object(name=None, template=None, xml_node=None, parent=None, control=None)
Create an object. Add it into the object dictionary (if not already exists) and agent set if the object is Agent
- Parameters:
name (Optional[str]) – The identification name of the object. Not used if xml_node is used
template (Optional[pymasep.common.template.Template]) – the template of the class to create the object. Not used if xml_node is used
xml_node (Optional[xml.etree.ElementTree.Element]) – XML node describing the object to create
parent (Optional[pymasep.common.base_object.BaseObject]) – the parent of the current object. Maybe None
control (Optional[str]) – ‘interface’ if the agent is controlled by interface (only inside engine and if template is used)
- Returns:
the object instance
- create_action(action_type=None, xml_node=None)
Create an action
- Parameters:
action_type (Optional[int]) – The type of the action (Constants in Action class)
xml_node (xml.etree.ElementTree.Element) – XML to create Action
- Returns:
The Action created from XML or with just a type
- Return type:
- choose_action()
Tell all agents to choose their action
- Return type:
None
- clear_all_state_elements()
Clear all in the environment
- Return type:
None