pymasep.common.state
Classes
State or Observation of the environment |
Module Contents
- class pymasep.common.state.State(environment, name=None, parent=None, xml_node=None, template=None, src_copy=None)
Bases:
pymasep.common.base_object.BaseObjectState or Observation of the environment
- Parameters:
environment – an Environment instance
name (Optional[str]) – name of the Agent.
xml_node (Optional[xml.etree.ElementTree.Element]) – XML used to create the state.
template – Template of the state. Needed if no xml_node.
parent (Optional[pymasep.common.base_object.BaseObject]) – Parent object (see objects hierarchy)
src_copy (Optional[State]) – The State to copy. Needed if no xml_node or template. The copy is not made into the constructor.
- Raises:
pymasep.common.exception.CreationException – If no XML or no template or src_copy is present
- agents: Set[pymasep.common.agent.Agent]
set of agent in the state. Can be different from the environment if the state is a partial observation
- objects
Objects in the state
- is_final: bool = False
is the state final of an episode?
- step: int = 0
current step of the episode.
- state()
State of the State (hum…). “Init” if one of its objects is in init state.
- Returns:
The state of the Object
- Return type:
str
- id_str()
Create a string unique ID of the State. Depends on the content of the base object and the id_str of all objects in the state
- Returns:
The string unique ID
- Return type:
str
- __eq__(other)
Test the equality of two states. Two states are equals if they have the same type and their id_str() are equals. Note : in some extreme cases, two different states can have the same id_str() but should not be equals. This case may occur, for example, with characteristic name Name and Name0 with Name=’00’ and Name0=’0’. But you have to have a twisted mind to model the state this way. Please don’t :) The code will remain simpler :)
- add_object(obj)
Add an object into the state. The object is added in self.agents if the object is an Agent
- Parameters:
obj – Object to add into state.
- Return type:
None
- to_xml()
Transform the State to XML.z See Serialization for more information.
- Returns:
XML version of the State
- Return type:
xml.etree.ElementTree.Element
- from_xml(environment, xml_node)
Transform an XML to a State. The instance must be created before (with __init__(), passing the xml_node). See Serialization for more information.
- Parameters:
environment – The environment where the State is created.
xml_node (xml.etree.ElementTree.Element) – The XML node that contains the State data.
- Raises:
pymasep.common.exception.CreationException – SubElement must be present if initializer is not present. At creation, Initializer must be present for all characteristics if initializer is not present for ObjectState
- Return type:
None
- copy_obs(params)
Deep copy the State to a new instance.
- Parameters:
params (dict) – Not used in this method.