1
0
mirror of https://github.com/gsi-upm/soil synced 2025-08-23 19:52:19 +00:00

Partial MESA compatibility and several fixes

Documentation for the new APIs is still a work in progress :)
This commit is contained in:
J. Fernando Sánchez
2021-10-15 20:15:17 +02:00
parent af9a392a93
commit 6c4f44b4cb
23 changed files with 128 additions and 511 deletions

View File

@@ -13,7 +13,7 @@ network_agents:
- agent_type: CounterModel
weight: 1
state:
id: 0
state_id: 0
- agent_type: AggregatedCounter
weight: 0.2
environment_agents: []

View File

@@ -13,4 +13,4 @@ network_agents:
- agent_type: CounterModel
weight: 1
state:
id: 0
state_id: 0

View File

@@ -23,7 +23,6 @@ def network_portrayal(env):
}
for (agent_id) in env.G.nodes
]
# import pdb;pdb.set_trace()
portrayal["edges"] = [
{"id": edge_id, "source": source, "target": target, "color": "#000000"}
@@ -65,7 +64,7 @@ model_params = {
"N": UserSettableParameter(
"slider",
"N",
1,
5,
1,
10,
1,

View File

@@ -34,9 +34,7 @@ class MoneyAgent(MesaAgent):
self.pos,
moore=True,
include_center=False)
print(self.pos, possible_steps)
new_position = self.random.choice(possible_steps)
print(self.pos, new_position)
self.model.grid.move_agent(self, new_position)
def give_money(self):
@@ -74,21 +72,13 @@ class SocialMoneyAgent(NetworkAgent, MoneyAgent):
class MoneyEnv(Environment):
"""A model with some number of agents."""
def __init__(self, N, width, height, *args, network_params, **kwargs):
self.initialized = True
# import pdb;pdb.set_trace()
network_params['n'] = N
super().__init__(*args, network_params=network_params, **kwargs)
self.grid = MultiGrid(width, height, False)
# self.schedule = RandomActivation(self)
self.running = True
# Create agents
for agent in self.agents:
self.schedule.add(agent)
# a = MoneyAgent(i, self)
# self.schedule.add(a)
# Add the agent to a random grid cell
x = self.random.randrange(self.grid.width)
y = self.random.randrange(self.grid.height)
self.grid.place_agent(agent, (x, y))
@@ -97,10 +87,6 @@ class MoneyEnv(Environment):
model_reporters={"Gini": compute_gini},
agent_reporters={"Wealth": "wealth"})
def step(self):
super().step()
self.datacollector.collect(self)
self.schedule.step()
def graph_generator(n=5):
G = nx.Graph()

View File

@@ -68,12 +68,12 @@ network_agents:
- agent_type: HerdViewer
state:
has_tv: true
id: neutral
state_id: neutral
weight: 1
- agent_type: HerdViewer
state:
has_tv: true
id: neutral
state_id: neutral
weight: 1
network_params:
generator: barabasi_albert_graph
@@ -95,7 +95,7 @@ network_agents:
- agent_type: HerdViewer
state:
has_tv: true
id: neutral
state_id: neutral
weight: 1
- agent_type: WiseViewer
state:
@@ -121,7 +121,7 @@ network_agents:
- agent_type: WiseViewer
state:
has_tv: true
id: neutral
state_id: neutral
weight: 1
- agent_type: WiseViewer
state:

View File

@@ -34,8 +34,6 @@ class HerdViewer(DumbViewer):
A viewer whose probability of infection depends on the state of its neighbors.
'''
level = logging.DEBUG
def infect(self):
infected = self.count_neighboring_agents(state_id=self.infected.id)
total = self.count_neighboring_agents()

View File

@@ -1,7 +1,7 @@
---
load_module: rabbit_agents
name: rabbits_example
max_time: 200
max_time: 150
interval: 1
seed: MySeed
agent_type: RabbitModel

View File

@@ -16,7 +16,7 @@ template:
- agent_type: CounterModel
weight: "{{ x1 }}"
state:
id: 0
state_id: 0
- agent_type: AggregatedCounter
weight: "{{ 1 - x1 }}"
environment_params: