starling_sim.basemodel.agent.agent
Module Contents
Classes
This class describes the basic features of a simulation agent. |
- class starling_sim.basemodel.agent.agent.Agent(simulation_model, agent_id, agent_type, mode, icon=None, **kwargs)
Bases:
starling_sim.basemodel.trace.trace.Traced
This class describes the basic features of a simulation agent.
It should be extended (through several layers) to give more specific features and behaviours (represented by their available methods), to finally implement a concrete agent that can be simulated in a specific model.
- SCHEMA
- update_class_schema
- classmethod get_schema()
Compute and return the class parameters schema.
This is the place to add eventual schema post-processing
- Returns:
class schema
- classmethod compute_schema()
Get the json schema that specifies the class init parameters.
The schema is generated recursively, by adding/mixing the properties of the current class to the schema of its parent class.
- Returns:
json schema of the class init parameters
- static update_class_schema(base_schema, class_schema, the_class, catch_error=True)
- execute_process(generator, store_process=False)
Create a process from the given generator and make it current process.
The process is obtained from the given generator using the scheduler. It can be set as the current_process attribute in order to access it later, for interrupting it for instance.
- Parameters:
generator – Python generator method
store_process – indicates if the process should be stored in self.current_process
- Returns:
Created SimPy Process object
- spend_time_(duration='inf')
Allow the simulation to flow while realising something, for the given duration.
- Parameters:
duration – wait duration, default is “inf” and leads to simulation limit
- Returns:
yield a timeout event with provided duration
- wait_(duration='inf', reason=None, message='')
Wait during the given duration and trace a WaitEvent.
- Parameters:
duration – wait duration. Default is “inf” and leads to simulation limit.
reason – reason of the wait time. Default is None.
message – message for the wait event. Default is “”.
- Returns:
yield a spend_time process with provided duration
- simpy_loop_()
Run the loop of the agent and catch simulation exceptions.
This method is the main SimPy process of the agent, added to the SimPy environment by the DynamicInput class.
- loop_()
This method represents the life cycle of an agent.
The loop process will be added to the simulation environment after the agent creation. Agents may perform actions that have a duration. They must then yield other processes such as waiting or moving, and will resume at the end of their action.
The loop must be extended to represent a specific behavior, using possibly inherited methods.
- leave_simulation(cause)
Raise a LeavingSimulation exception to make the agent leave its loop and terminate its process.
The cause is a leaving code that should be listed in the simulation model. It corresponds to a specific reason for the agent to leave the simulation.
- Parameters:
cause – leaving code
- Raises:
- simulation_error(description)
Raise a SimulationError exception to make the agent leave the simulation following a simulation error.
This method should be called when an unwanted event occurs in a simulation, like saying “We shouldn’t be here”.
- Parameters:
description – description of the unwanted event
- Raises:
- interrupt(message='')
Interrupts the process contained in the current_process attribute.
This process must handle the interruption exception