mirror of
https://github.com/balkian/gists.git
synced 2024-11-21 17:22:29 +00:00
Update example
This commit is contained in:
parent
c9c55ac60b
commit
1eef636a58
13
coalition.py
13
coalition.py
@ -1,9 +1,11 @@
|
||||
from soil.agents import FSM, state, default_state
|
||||
from random import randint
|
||||
|
||||
MAX_WEALTH = 10e6
|
||||
MAX_WEALTH = 2000
|
||||
|
||||
|
||||
class CoalitionAgent(FSM):
|
||||
|
||||
defaults = {
|
||||
'wealth': -1,
|
||||
'wealth_threshold': 1000,
|
||||
@ -12,15 +14,17 @@ class CoalitionAgent(FSM):
|
||||
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))
|
||||
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():
|
||||
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
|
||||
@ -29,6 +33,7 @@ class CoalitionAgent(FSM):
|
||||
pass
|
||||
|
||||
def join_coalition(self, other):
|
||||
# Add your methods here, like adding edges between users...
|
||||
# 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)
|
||||
|
@ -1,3 +1,4 @@
|
||||
---
|
||||
name: CoalitionExample
|
||||
agent_type: coalition.CoalitionAgent
|
||||
network_params:
|
||||
|
Loading…
Reference in New Issue
Block a user