2022-10-17 18:23:57 +00:00
|
|
|
"""
|
2022-03-07 09:48:59 +00:00
|
|
|
Example of setting a
|
|
|
|
Example of a fully programmatic simulation, without definition files.
|
2022-10-17 18:23:57 +00:00
|
|
|
"""
|
2022-03-07 09:48:59 +00:00
|
|
|
from soil import Simulation, agents
|
|
|
|
from soil.time import Delta
|
|
|
|
|
|
|
|
|
|
|
|
class MyAgent(agents.FSM):
|
2022-10-17 18:23:57 +00:00
|
|
|
"""
|
2022-03-07 10:17:27 +00:00
|
|
|
An agent that first does a ping
|
2022-10-17 18:23:57 +00:00
|
|
|
"""
|
2022-03-07 10:17:27 +00:00
|
|
|
|
2022-10-17 18:23:57 +00:00
|
|
|
defaults = {"pong_counts": 2}
|
2022-03-07 09:48:59 +00:00
|
|
|
|
|
|
|
@agents.default_state
|
|
|
|
@agents.state
|
2022-03-07 10:17:27 +00:00
|
|
|
def ping(self):
|
2022-10-17 18:23:57 +00:00
|
|
|
self.info("Ping")
|
|
|
|
return self.pong, Delta(self.random.expovariate(1 / 16))
|
2022-03-07 10:17:27 +00:00
|
|
|
|
|
|
|
@agents.state
|
|
|
|
def pong(self):
|
2022-10-17 18:23:57 +00:00
|
|
|
self.info("Pong")
|
2022-03-07 10:17:27 +00:00
|
|
|
self.pong_counts -= 1
|
|
|
|
self.info(str(self.pong_counts))
|
|
|
|
if self.pong_counts < 1:
|
|
|
|
return self.die()
|
2022-10-17 18:23:57 +00:00
|
|
|
return None, Delta(self.random.expovariate(1 / 16))
|
|
|
|
|
|
|
|
|
|
|
|
s = Simulation(
|
|
|
|
name="Programmatic",
|
2022-11-13 19:31:05 +00:00
|
|
|
model_params={
|
|
|
|
'agents': [{'agent_class': MyAgent}],
|
|
|
|
},
|
2022-10-17 18:23:57 +00:00
|
|
|
num_trials=1,
|
|
|
|
max_time=100,
|
|
|
|
dry_run=True,
|
|
|
|
)
|
2022-03-07 09:48:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
envs = s.run()
|