Base Control¶
This module contains the abstract definition of a simulation control. It has the definition of BaseControl, that should be extended, implementing its abstract methods.
Example
Creating a discrete-event control:
class NewControl(BaseControl):
def __init__(
self,
simulator: BaseSimulator,
simulation_strategy: SimulationStrategy,
event_bus: EventBus = None,
):
BaseControl.__init__(self, simulator, simulation_strategy, event_bus)
def _execute(self, frequency: Time, wait_time: Time, stop_time: Time):
while not self._is_paused:
self._simulator.compute_next_state()
def start(
self,
start_input: Dict[str, ModelInput] = None,
frequency: Time = Time(1000),
stop_time: Time = 0,
wait_time: Time = 0,
):
self._is_paused = False
self._simulation_strategy.start_simulation(
self._execute, frequency, wait_time, stop_time
)
def pause(self):
self._is_paused = True
def stop(self):
self._is_paused = True
self._simulation_strategy.stop_simulation()
self.init()
def wait(self, timeout: Time = None):
self._simulation_strategy.wait_simulation(timeout)
-
class
gsf.control.core.base_control.
BaseControl
¶ Bases:
object
Simulation control
-
_simulator
¶ Simulator to be executed.
- Type
-
_is_paused
¶ Boolean that indicates if the simulation is paused.
- Type
bool
-
_simulation_strategy
¶ Strategy for infrastructure simulation details.
- Type
-
_event_bus
¶ Event bus of the module.
- Type
EventBus
-
abstract
_execute
(frequency: decimal.Decimal, wait_time: decimal.Decimal, stop_time: decimal.Decimal)¶ Executes the simulation loop number of seconds.
- Parameters
frequency (Time) – Frequency of the simulation computation.
wait_time (Time) – Delay execution for a given.
stop_time (Time) – Duration of the simulation.
-
init
()¶
-
abstract
pause
()¶ Pauses the simulation
-
abstract
start
(start_input: Dict[str, ModelInput] = None, frequency: Time = 0, stop_time: Time = 0, wait_time: Time = 0)¶ Starts the simulation
- Parameters
start_input – Input of the dynamic system.
frequency (Time) – Frequency of the simulation computation.
stop_time (Time) – Time of the simulation
wait_time (Time) – Delay execution for a given number of seconds.
-
abstract
stop
()¶ Stops the simulation
-
abstract
wait
(timeout: Optional[decimal.Decimal] = None)¶ Waits the simulation end
- Parameters
timeout (Time) – Time to wait.
-