mirror of
https://github.com/balkian/gists.git
synced 2024-11-22 01:32: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 soil.agents import FSM, state, default_state
|
||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
MAX_WEALTH = 10e6
|
MAX_WEALTH = 2000
|
||||||
|
|
||||||
|
|
||||||
class CoalitionAgent(FSM):
|
class CoalitionAgent(FSM):
|
||||||
|
|
||||||
defaults = {
|
defaults = {
|
||||||
'wealth': -1,
|
'wealth': -1,
|
||||||
'wealth_threshold': 1000,
|
'wealth_threshold': 1000,
|
||||||
@ -12,15 +14,17 @@ class CoalitionAgent(FSM):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(CoalitionAgent, self).__init__(*args, **kwargs)
|
super(CoalitionAgent, self).__init__(*args, **kwargs)
|
||||||
if self['wealth'] == -1:
|
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
|
@default_state
|
||||||
@state
|
@state
|
||||||
def looking_for_coalitions(self):
|
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']:
|
if agent['wealth'] > self['wealth_threshold']:
|
||||||
self.join_coalition(agent)
|
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
|
return self.idle
|
||||||
|
|
||||||
@state
|
@state
|
||||||
@ -29,6 +33,7 @@ class CoalitionAgent(FSM):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def join_coalition(self, other):
|
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
|
# 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)
|
self.env.add_edge(self, other)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
---
|
||||||
name: CoalitionExample
|
name: CoalitionExample
|
||||||
agent_type: coalition.CoalitionAgent
|
agent_type: coalition.CoalitionAgent
|
||||||
network_params:
|
network_params:
|
||||||
|
Loading…
Reference in New Issue
Block a user