Model¶
-
class
Model
(starttime=0, stoptime=0, dt=1, name='', scheduler=None, data_collector=None)¶ This is the main agent base / System dynamics / Hybrid model class It can run manually generated SD models, AB Models or define hybrid models.
-
add_equation
(equation, lambda_method)¶ - Add an equation. ALWAYS use this method to configure equations! Configures the memo as well!
- param equation
Name of the equation
- param lambda_method
A lambda function we can insert into the set of equations
- return
None
-
agent
(agent_id)¶ - Receive one agent by ID
- param agent_id
ID of agent (int)
- return
Agent object
-
agent_count
(agent_type)¶ - Get number of agents
- param agent_type
Agent type to get count for
- return
Number of agents (int)
-
agent_count_per_state
(agent_type, state)¶ - Get number of agents in a specific state
- param agent_type
Agent type to get count for
- param state
state of agents to get count for
- return
Integer
-
agent_ids
(agent_type)¶ - Receive agent ids for all agents of agent_type
- param agent_type
agent type to get ids for
- return
List
-
begin_episode
(episode_no)¶ When running a simulation repeatedly in episodes, this method is called by the framework to allow tidy up at the beginning of an episode, e.g. a “soft” reset of the simulation. The default implementation calls begin_episode on each agent.
- param episode_no
the number of the episode
- return
None
-
begin_round
(time, sim_round, step)¶ Should be called by a scheduler at the beginning of each round, before the agents act methods are called. Add any logic here that is needed to update dynamic properties.
- param time
t
- param sim_round
round number
- param step
step number of round
- return
None
-
biflow
(name)¶ - Create a SD biflow
- param name
Name of the biflow
- return
Biflow object
-
broadcast_event
(agent_type, event_factory)¶ - Broadcast an event to all agents of a particular agent_type
- param agent_type
Agent types that are to receive the event
- param event_factory
event factory (function) that creates an appropriate event for a given target agent_id
- return
-
configure
(config)¶ - Called to configure the model using a dictionary, which itself typically comes from a config file.
- param config
Configuration dictionary
- return
None
-
constant
(name)¶ - Create a SD constant
- param name
Name of the constant
- return
Constant object
-
converter
(name)¶ - Create a converter
- param name
Name of the converter
- return
Converter object
-
create_agent
(agent_type, agent_properties)¶ - Create one agent
- param agent_type
Type of agent
- return
None
-
create_agents
(agent_spec)¶ - Create agents
- param agent_spec
Specification of Agent (dictionary)
- return
None
-
end_episode
(episode_no)¶ - When running a simulation repeatedly in episodes, this method is called by the framework to allow tidy up at the end of an episode. The default implementation calls end_episode on each agent.
- param episode_no
the number of the episode
- return
None
-
end_round
(time, sim_round, step)¶ Should be called by a scheduler at the end of each round, before the agents act methods are called. Add any logic here that is needed to update dynamic properties.
- param time
t
- param sim_round
round number
- param step
step number of round
- return
None
-
enqueue_event
(event)¶ - Called by the framework to enqueue events. In general you don’t need to override this method.
- param event
Event instance
- return
None
-
equation
(equation, arg)¶ This method only exists for making SD-DSL models compatible with the new SDModel equation API. In later steps, we might want to extend this method to allow for arrayed equations as well! However, first the DSL needs to support arrays as well!
- param equation
equaiton name
- param arg
t
-
property
equation_prefix
¶ An id that is unique within this model that can be used to generate unique equation names :return:
-
evaluate_equation
(name, t)¶ - Evaluate an element’s equation
- param name
Name of the equation
- param t
timestep to evaluate for
- return
float of simulation result
-
flow
(name)¶ - Create a SD flow
- param name
Name of the flow
- return
Flow object
-
function
(name, fn)¶ Create a user defined function for SD models. :param name: name of the function :param fn: returns :return: a nary function that creates a NaryFunction class
-
get_property
(name)¶ - Get one property
- param name
Name of property
- return
Dictionary for property
-
static
get_random_integer
(min_value, max_value)¶ - Just compute a random integer within bounds
- param min_value
min value for random integer
- param max_value
max value for random integer
- return
Integer
-
instantiate_model
()¶ - Instantiate model stub. Called directly after the model is instantiated. Implement this method in your model to perform any kind of initialization you may need.
- return
None
-
lookup
(x, points)¶ - Lookup function: Interpolate between set of points. E.g. for “graphical functions” as known from SD
- param x
x-value to find the y value for
- param points
- return
-
memoize
(equation, arg)¶ - Memoize method - used by the system dynamics equations to remember values that have already been calculated.
- param equation
name of equation
- param arg
argument (t)
- return
result of equation
-
next_agent
(agent_type, state)¶ - Get the next agent by type and state.
- param agent_type
Agent type
- param state
State the agent is in
- return
Agent object
-
random_agents
(agent_type, num_agents)¶ - Receive a number of random agents
- param agent_type
Type of agent
- param num_agents
Number of agents to receive
- return
Agent IDs list
-
random_events
(agent_type, num_agents, event_factory)¶ - Distribute a number of random events
- param agent_type
Agent types supposed to receive events
- param num_agents
Number of random agents
- param event_factory
event factory (function) that creates an appropriate event for a given target agent_id
- return
None.
-
register_agent_factory
(agent_type, agent_factory)¶ - Register an agent factory
- param agent_type
Type of agent to register
- param agent_factory
Function (typically lambda, but not limited to). Input: agent_id, model -> Output: Agent of agent_type
- return
None
-
reset
()¶ - Reset simulation
- return
None
-
reset_cache
()¶ - Reset memo of all equations
- return
None
-
run
(show_progress_widget=False, collect_data=True)¶ - Initiate simulation - this esssentially just calls the run method of the models scheduler.
- param show_progress_widget
Boolean: If true, shows a progress widget (only in Jupyter environment!)
- return
None
-
run_specs
(starttime, stoptime, dt)¶ - Configure the runspecs of the model.
- param starttime
The starttime of the model.
- param stoptime
The stoptime of the model.
- param dt
The dt of the model.
- return
None
-
set_property
(name, property_spec)¶ - Configure a property of the simulation
- param property_spec
Specification of property (dictionary)
- return
-
set_scenario_manager
(scenario_manager)¶ - Set the scenario manager name
- param scenario_manager
String
- return
None
-
statistics
()¶ - Get statistics from DataCollector
- return
None
-
stock
(name)¶ - Create a SD stock
- param name
name of the stock
- return
Stock object
-