Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
soil
soil
Commits
affeeb96
Commit
affeeb96
authored
Apr 04, 2022
by
J. Fernando Sánchez
Browse files
Update examples
parent
42ddc023
Pipeline
#3556
passed with stage
in 4 minutes and 5 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
docs/requirements.txt
View file @
affeeb96
ipython==7.
2
3
ipython==7.3
1.1
examples/newsspread/newsspread.py
View file @
affeeb96
...
...
@@ -17,7 +17,7 @@ class DumbViewer(FSM):
def
neutral
(
self
):
if
self
[
'has_tv'
]:
if
prob
(
self
.
env
[
'prob_tv_spread'
]):
self
.
set_state
(
self
.
infected
)
return
self
.
infected
@
state
def
infected
(
self
):
...
...
@@ -26,6 +26,12 @@ class DumbViewer(FSM):
neighbor
.
infect
()
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
)
...
...
@@ -35,12 +41,13 @@ class HerdViewer(DumbViewer):
'''
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
)
total
=
self
.
count_neighboring_agents
()
prob_infect
=
self
.
env
[
'prob_neighbor_spread'
]
*
infected
/
total
self
.
debug
(
'prob_infect'
,
prob_infect
)
if
prob
(
prob_infect
):
self
.
set_state
(
self
.
infected
.
id
)
self
.
set_state
(
self
.
infected
)
class
WiseViewer
(
HerdViewer
):
...
...
@@ -75,5 +82,5 @@ class WiseViewer(HerdViewer):
1.0
)
prob_cure
=
self
.
env
[
'prob_neighbor_cure'
]
*
(
cured
/
infected
)
if
prob
(
prob_cure
):
return
self
.
cure
()
return
self
.
cure
d
return
self
.
set_state
(
super
().
infected
)
examples/programmatic/programmatic.py
View file @
affeeb96
...
...
@@ -18,7 +18,9 @@ class MyAgent(agents.FSM):
@
agents
.
default_state
@
agents
.
state
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'
,
...
...
@@ -29,10 +31,10 @@ s = Simulation(name='Programmatic',
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
)
envs
=
s
.
run
()
s
.
dump_yaml
()
for
env
in
envs
:
env
.
dump_csv
()
# Uncomment this to output the simulation to a YAML file
# s.dump_yaml('simulation.yaml')
examples/rabbits/rabbit_agents.py
View file @
affeeb96
...
...
@@ -12,8 +12,6 @@ class Genders(Enum):
class
RabbitModel
(
FSM
):
level
=
logging
.
INFO
defaults
=
{
'age'
:
0
,
'gender'
:
Genders
.
male
.
value
,
...
...
examples/rabbits/rabbits.yml
View file @
affeeb96
---
load_module
:
rabbit_agents
name
:
rabbits_example
max_time
:
1
5
0
max_time
:
1
0
0
interval
:
1
seed
:
MySeed
agent_type
:
RabbitModel
...
...
@@ -10,7 +10,7 @@ environment_agents:
environment_params
:
prob_death
:
0.001
default_state
:
mating_prob
:
0.
0
1
mating_prob
:
0.1
topology
:
nodes
:
-
id
:
1
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment