mirror of
https://github.com/gsi-upm/soil
synced 2025-08-24 12:02:20 +00:00
WIP soil
* Pandas integration * Improved environment * Logging and data dumps * Tests * Added Finite State Machine models * Rewritten ipython notebook and documentation
This commit is contained in:
17
examples/custom-agents/UnnamedSimulation.dumped.yml
Normal file
17
examples/custom-agents/UnnamedSimulation.dumped.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
default_state: {}
|
||||
environment_agents: []
|
||||
environment_params: {prob_neighbor_spread: 0.0, prob_tv_spread: 0.01}
|
||||
interval: 1
|
||||
max_time: 20
|
||||
name: Sim_prob_0
|
||||
network_agents:
|
||||
- agent_type: NewsSpread
|
||||
state: {has_tv: false}
|
||||
weight: 1
|
||||
- agent_type: NewsSpread
|
||||
state: {has_tv: true}
|
||||
weight: 2
|
||||
network_params: {generator: erdos_renyi_graph, n: 500, p: 0.1}
|
||||
num_trials: 1
|
||||
states:
|
||||
- {has_tv: true}
|
20
examples/custom-agents/agent.py
Normal file
20
examples/custom-agents/agent.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import soil
|
||||
import random
|
||||
|
||||
class NewsSpread(soil.agents.FSM):
|
||||
@soil.agents.default_state
|
||||
@soil.agents.state
|
||||
def neutral(self):
|
||||
r = random.random()
|
||||
if self['has_tv'] and r < self.env['prob_tv_spread']:
|
||||
return self.infected
|
||||
return
|
||||
|
||||
@soil.agents.state
|
||||
def infected(self):
|
||||
prob_infect = self.env['prob_neighbor_spread']
|
||||
for neighbor in self.get_neighboring_agents(state_id=self.neutral.id):
|
||||
r = random.random()
|
||||
if r < prob_infect:
|
||||
neighbor.state['id'] = self.infected.id
|
||||
return
|
Reference in New Issue
Block a user