mirror of
https://github.com/balkian/gists.git
synced 2024-12-22 14:28:12 +00:00
This commit is contained in:
commit
c9c55ac60b
34
coalition.py
Normal file
34
coalition.py
Normal file
@ -0,0 +1,34 @@
|
||||
from soil.agents import FSM, state, default_state
|
||||
from random import randint
|
||||
|
||||
MAX_WEALTH = 10e6
|
||||
|
||||
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'] = randint(0, self.env.get('max_wealth', MAX_WEALTH))
|
||||
|
||||
|
||||
@default_state
|
||||
@state
|
||||
def looking_for_coalitions(self):
|
||||
for agent in self.get_agents():
|
||||
if agent['wealth'] > self['wealth_threshold']:
|
||||
self.join_coalition(agent)
|
||||
return self.idle
|
||||
|
||||
@state
|
||||
def idle(self):
|
||||
# Do nothing
|
||||
pass
|
||||
|
||||
def join_coalition(self, other):
|
||||
# Add your methods here, like adding edges between users...
|
||||
# You'll probably want to check if you've already joined the user first
|
||||
self.env.add_edge(self, other)
|
5
coalition.yml
Normal file
5
coalition.yml
Normal file
@ -0,0 +1,5 @@
|
||||
name: CoalitionExample
|
||||
agent_type: coalition.CoalitionAgent
|
||||
network_params:
|
||||
generator: empty_graph
|
||||
n: 100
|
Loading…
Reference in New Issue
Block a user