You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
soil/examples/random_delays/random_delays_sim.py

48 lines
940 B
Python

2 years ago
"""
Example of setting a
Example of a fully programmatic simulation, without definition files.
2 years ago
"""
from soil import Simulation, agents, Environment
from soil.time import Delta
class MyAgent(agents.FSM):
2 years ago
"""
2 years ago
An agent that first does a ping
2 years ago
"""
2 years ago
2 years ago
defaults = {"pong_counts": 2}
@agents.default_state
@agents.state
2 years ago
def ping(self):
2 years ago
self.info("Ping")
return self.pong, Delta(self.random.expovariate(1 / 16))
2 years ago
@agents.state
def pong(self):
2 years ago
self.info("Pong")
2 years ago
self.pong_counts -= 1
self.info(str(self.pong_counts))
if self.pong_counts < 1:
return self.die()
2 years ago
return None, Delta(self.random.expovariate(1 / 16))
class RandomEnv(Environment):
def init(self):
self.add_agent(agent_class=MyAgent)
2 years ago
s = Simulation(
name="Programmatic",
model=RandomEnv,
iterations=1,
2 years ago
max_time=100,
dump=False,
2 years ago
)
envs = s.run()