mirror of
https://github.com/balkian/gists.git
synced 2025-08-23 15:12:21 +00:00
Move files
This commit is contained in:
39
Modelos Soil de prueba/coalition.py
Normal file
39
Modelos Soil de prueba/coalition.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from soil.agents import FSM, state, default_state
|
||||
from random import randint
|
||||
|
||||
MAX_WEALTH = 2000
|
||||
|
||||
|
||||
class CoalitionAgent(FSM):
|
||||
|
||||
defaults = {
|
||||
'wealth': -1,
|
||||
'wealth_threshold': 1000,
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(CoalitionAgent, self).__init__(*args, **kwargs)
|
||||
if self['wealth'] == -1:
|
||||
self['wealth'] = int(randint(0, self.env.get('max_wealth', MAX_WEALTH)))
|
||||
|
||||
|
||||
@default_state
|
||||
@state
|
||||
def looking_for_coalitions(self):
|
||||
for agent in self.get_agents(state_id=self.looking_for_coalitions.id):
|
||||
if agent['wealth'] > self['wealth_threshold']:
|
||||
self.join_coalition(agent)
|
||||
friends = list(friend.id for friend in self.get_neighboring_agents())
|
||||
self.info('List of friends: {}'.format(friends))
|
||||
return self.idle
|
||||
|
||||
@state
|
||||
def idle(self):
|
||||
# Do nothing
|
||||
pass
|
||||
|
||||
def join_coalition(self, other):
|
||||
# Adill.detect.badobjectsdd your methods here, like adding edges between users...
|
||||
# You'll probably want to check if you've already joined the user first
|
||||
self.info('Joining {}'.format(other.id))
|
||||
self.env.add_edge(self, other)
|
6
Modelos Soil de prueba/coalition.yml
Normal file
6
Modelos Soil de prueba/coalition.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
name: CoalitionExample
|
||||
agent_type: coalition.CoalitionAgent
|
||||
network_params:
|
||||
generator: empty_graph
|
||||
n: 100
|
17
Modelos Soil de prueba/prueba.py
Normal file
17
Modelos Soil de prueba/prueba.py
Normal file
@@ -0,0 +1,17 @@
|
||||
NEUTRAL = 0
|
||||
INFECTED = 1
|
||||
|
||||
class ControlModelM2(BaseBehaviour):
|
||||
NEUTRAL = 0
|
||||
INFECTED = 1
|
||||
def step(self, now):
|
||||
if self.state['id'] == NEUTRAL:
|
||||
self.neutral_behaviour()
|
||||
elif self.state['id'] == INFECTED:
|
||||
self.infected_behaviour()
|
||||
…
|
||||
def infected_behaviour(self):
|
||||
neutral_neighbors = self.get_neighboring_agents(state_id=INFECTED)
|
||||
for neighbor in neutral_neighbors:
|
||||
if random.random() < self.prob_infect:
|
||||
neighbor.state['id'] = INFECTED
|
Reference in New Issue
Block a user