mirror of
https://github.com/gsi-upm/soil
synced 2024-11-22 03:02:28 +00:00
Update examples
This commit is contained in:
parent
42ddc02318
commit
affeeb9643
@ -1 +1 @@
|
|||||||
ipython==7.23
|
ipython==7.31.1
|
||||||
|
@ -17,7 +17,7 @@ class DumbViewer(FSM):
|
|||||||
def neutral(self):
|
def neutral(self):
|
||||||
if self['has_tv']:
|
if self['has_tv']:
|
||||||
if prob(self.env['prob_tv_spread']):
|
if prob(self.env['prob_tv_spread']):
|
||||||
self.set_state(self.infected)
|
return self.infected
|
||||||
|
|
||||||
@state
|
@state
|
||||||
def infected(self):
|
def infected(self):
|
||||||
@ -26,6 +26,12 @@ class DumbViewer(FSM):
|
|||||||
neighbor.infect()
|
neighbor.infect()
|
||||||
|
|
||||||
def infect(self):
|
def infect(self):
|
||||||
|
'''
|
||||||
|
This is not a state. It is a function that other agents can use to try to
|
||||||
|
infect this agent. DumbViewer always gets infected, but other agents like
|
||||||
|
HerdViewer might not become infected right away
|
||||||
|
'''
|
||||||
|
|
||||||
self.set_state(self.infected)
|
self.set_state(self.infected)
|
||||||
|
|
||||||
|
|
||||||
@ -35,12 +41,13 @@ class HerdViewer(DumbViewer):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
def infect(self):
|
def infect(self):
|
||||||
|
'''Notice again that this is NOT a state. See DumbViewer.infect for reference'''
|
||||||
infected = self.count_neighboring_agents(state_id=self.infected.id)
|
infected = self.count_neighboring_agents(state_id=self.infected.id)
|
||||||
total = self.count_neighboring_agents()
|
total = self.count_neighboring_agents()
|
||||||
prob_infect = self.env['prob_neighbor_spread'] * infected/total
|
prob_infect = self.env['prob_neighbor_spread'] * infected/total
|
||||||
self.debug('prob_infect', prob_infect)
|
self.debug('prob_infect', prob_infect)
|
||||||
if prob(prob_infect):
|
if prob(prob_infect):
|
||||||
self.set_state(self.infected.id)
|
self.set_state(self.infected)
|
||||||
|
|
||||||
|
|
||||||
class WiseViewer(HerdViewer):
|
class WiseViewer(HerdViewer):
|
||||||
@ -75,5 +82,5 @@ class WiseViewer(HerdViewer):
|
|||||||
1.0)
|
1.0)
|
||||||
prob_cure = self.env['prob_neighbor_cure'] * (cured/infected)
|
prob_cure = self.env['prob_neighbor_cure'] * (cured/infected)
|
||||||
if prob(prob_cure):
|
if prob(prob_cure):
|
||||||
return self.cure()
|
return self.cured
|
||||||
return self.set_state(super().infected)
|
return self.set_state(super().infected)
|
||||||
|
@ -18,7 +18,9 @@ class MyAgent(agents.FSM):
|
|||||||
@agents.default_state
|
@agents.default_state
|
||||||
@agents.state
|
@agents.state
|
||||||
def neutral(self):
|
def neutral(self):
|
||||||
self.info('I am running')
|
self.debug('I am running')
|
||||||
|
if agents.prob(0.2):
|
||||||
|
self.info('This runs 2/10 times on average')
|
||||||
|
|
||||||
|
|
||||||
s = Simulation(name='Programmatic',
|
s = Simulation(name='Programmatic',
|
||||||
@ -29,10 +31,10 @@ s = Simulation(name='Programmatic',
|
|||||||
dry_run=True)
|
dry_run=True)
|
||||||
|
|
||||||
|
|
||||||
|
# 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)
|
logging.basicConfig(level=logging.INFO)
|
||||||
envs = s.run()
|
envs = s.run()
|
||||||
|
|
||||||
s.dump_yaml()
|
# Uncomment this to output the simulation to a YAML file
|
||||||
|
# s.dump_yaml('simulation.yaml')
|
||||||
for env in envs:
|
|
||||||
env.dump_csv()
|
|
||||||
|
@ -12,8 +12,6 @@ class Genders(Enum):
|
|||||||
|
|
||||||
class RabbitModel(FSM):
|
class RabbitModel(FSM):
|
||||||
|
|
||||||
level = logging.INFO
|
|
||||||
|
|
||||||
defaults = {
|
defaults = {
|
||||||
'age': 0,
|
'age': 0,
|
||||||
'gender': Genders.male.value,
|
'gender': Genders.male.value,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
load_module: rabbit_agents
|
load_module: rabbit_agents
|
||||||
name: rabbits_example
|
name: rabbits_example
|
||||||
max_time: 150
|
max_time: 100
|
||||||
interval: 1
|
interval: 1
|
||||||
seed: MySeed
|
seed: MySeed
|
||||||
agent_type: RabbitModel
|
agent_type: RabbitModel
|
||||||
@ -10,7 +10,7 @@ environment_agents:
|
|||||||
environment_params:
|
environment_params:
|
||||||
prob_death: 0.001
|
prob_death: 0.001
|
||||||
default_state:
|
default_state:
|
||||||
mating_prob: 0.01
|
mating_prob: 0.1
|
||||||
topology:
|
topology:
|
||||||
nodes:
|
nodes:
|
||||||
- id: 1
|
- id: 1
|
||||||
|
Loading…
Reference in New Issue
Block a user