1
0
mirror of https://github.com/gsi-upm/soil synced 2024-09-21 15:51:43 +00:00
soil/examples/programmatic/programmatic.py

42 lines
914 B
Python
Raw Normal View History

2022-10-17 18:23:57 +00:00
"""
Example of a fully programmatic simulation, without definition files.
2022-10-17 18:23:57 +00:00
"""
from soil import Simulation, agents
from networkx import Graph
import logging
def mygenerator():
# Add only a node
G = Graph()
G.add_node(1)
return G
class MyAgent(agents.FSM):
@agents.default_state
@agents.state
def neutral(self):
2022-10-17 18:23:57 +00:00
self.debug("I am running")
2022-04-04 14:47:58 +00:00
if agents.prob(0.2):
2022-10-17 18:23:57 +00:00
self.info("This runs 2/10 times on average")
2022-10-17 18:23:57 +00:00
s = Simulation(
name="Programmatic",
network_params={"generator": mygenerator},
num_trials=1,
max_time=100,
agent_class=MyAgent,
dry_run=True,
)
2022-04-04 14:47:58 +00:00
# By default, logging will only print WARNING logs (and above).
# You need to choose a lower logging level to get INFO/DEBUG traces
logging.basicConfig(level=logging.INFO)
envs = s.run()
2022-04-04 14:47:58 +00:00
# Uncomment this to output the simulation to a YAML file
# s.dump_yaml('simulation.yaml')