Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions examples/Schelling/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ def __init__(self, height, width, density, minority_pc, homophily):
# For testing purposes, agent's individual x and y
{"x": lambda a: a.pos[0], "y": lambda a: a.pos[1]})

self.running = True

# Set up agents
# We use a grid iterator that returns
# the coordinates of a cell as well as
Expand All @@ -79,12 +77,16 @@ def __init__(self, height, width, density, minority_pc, homophily):
self.grid.position_agent(agent, (x, y))
self.schedule.add(agent)

self.running = True
self.datacollector.collect(self)

def step(self):
'''
Run one step of the model. If All agents are happy, halt the model.
'''
self.happy = 0 # Reset counter of happy agents
self.schedule.step()
# collect data
self.datacollector.collect(self)

if self.happy == self.schedule.get_agent_count():
Expand Down
5 changes: 3 additions & 2 deletions examples/bank_reserves/bank_reserves/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,13 @@ def __init__(self, height=grid_h, width=grid_w, init_people=2, rich_threshold=10
self.schedule.add(p)

self.running = True
self.datacollector.collect(self)

def step(self):
# collect data
self.datacollector.collect(self)
# tell all the agents in the model to run their step function
self.schedule.step()
# collect data
self.datacollector.collect(self)

def run_model(self):
for i in range(self.run_time):
Expand Down
6 changes: 3 additions & 3 deletions examples/bank_reserves/bank_reserves/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
"""

# Green
RICH_COLOR = "46FF33"
RICH_COLOR = "#46FF33"
# Red
POOR_COLOR = "FF3C33"
POOR_COLOR = "#FF3C33"
# Blue
MID_COLOR = "3349FF"
MID_COLOR = "#3349FF"


def person_portrayal(agent):
Expand Down
7 changes: 5 additions & 2 deletions examples/boltzmann_wealth_model/wealth_model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class MoneyModel(Model):

def __init__(self, N, width, height):
self.num_agents = N
self.running = True
self.grid = MultiGrid(height, width, True)
self.schedule = RandomActivation(self)
self.datacollector = DataCollector(
Expand All @@ -40,9 +39,13 @@ def __init__(self, N, width, height):
y = random.randrange(self.grid.height)
self.grid.place_agent(a, (x, y))

def step(self):
self.running = True
self.datacollector.collect(self)

def step(self):
self.schedule.step()
# collect data
self.datacollector.collect(self)

def run_model(self, n):
for i in range(n):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def __init__(self, num_agents, num_nodes):
self.num_agents = num_agents
self.num_nodes = num_nodes if num_nodes >= self.num_agents else self.num_agents
self.G = nx.erdos_renyi_graph(n=self.num_nodes, p=0.5)
self.running = True
self.grid = NetworkGrid(self.G)
self.schedule = RandomActivation(self)
self.datacollector = DataCollector(
Expand All @@ -41,8 +40,12 @@ def __init__(self, num_agents, num_nodes):
# Add the agent to a random node
self.grid.place_agent(a, list_of_random_nodes[i])

self.running = True
self.datacollector.collect(self)

def step(self):
self.schedule.step()
# collect data
self.datacollector.collect(self)

def run_model(self, n):
Expand Down
1 change: 1 addition & 0 deletions examples/conways_game_of_life/game_of_life/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, height, width):
cell.state = cell.ALIVE
self.grid.place_agent(cell, (x, y))
self.schedule.add(cell)

self.running = True

def step(self):
Expand Down
11 changes: 7 additions & 4 deletions examples/epstein_civil_violence/civil_violence/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def __init__(self, height, width, citizen_density, cop_density,
self.active_threshold = active_threshold
self.arrest_prob_constant = arrest_prob_constant
self.movement = movement
self.running = True
self.max_iters = max_iters
self.iteration = 0
self.schedule = RandomActivation(self)
Expand All @@ -69,8 +68,8 @@ def __init__(self, height, width, citizen_density, cop_density,
"arrest_probability": lambda a: getattr(a, "arrest_probability",
None)
}
self.dc = DataCollector(model_reporters=model_reporters,
agent_reporters=agent_reporters)
self.datacollector = DataCollector(model_reporters=model_reporters,
agent_reporters=agent_reporters)
unique_id = 0
if self.cop_density + self.citizen_density > 1:
raise ValueError(
Expand All @@ -93,12 +92,16 @@ def __init__(self, height, width, citizen_density, cop_density,
self.grid[y][x] = citizen
self.schedule.add(citizen)

self.running = True
self.datacollector.collect(self)

def step(self):
"""
Advance the model by one step and collect data.
"""
self.schedule.step()
self.dc.collect(self)
# collect data
self.datacollector.collect(self)
self.iteration += 1
if self.iteration > self.max_iters:
self.running = False
Expand Down
3 changes: 3 additions & 0 deletions examples/forest_fire/forest_fire/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ def __init__(self, height, width, density):
new_tree.condition = "On Fire"
self.grid._place_agent((x, y), new_tree)
self.schedule.add(new_tree)

self.running = True
self.datacollector.collect(self)

def step(self):
"""
Advance the model by one step.
"""
self.schedule.step()
# collect data
self.datacollector.collect(self)

# Halt if no more fire
Expand Down
7 changes: 5 additions & 2 deletions examples/pd_grid/pd_grid/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def __init__(self, height, width, schedule_type, payoffs=None):
Determines the agent activation regime.
payoffs: (optional) Dictionary of (move, neighbor_move) payoffs.
'''
self.running = True
self.grid = SingleGrid(height, width, torus=True)
self.schedule_type = schedule_type
self.schedule = self.schedule_types[self.schedule_type](self)
Expand All @@ -48,9 +47,13 @@ def __init__(self, height, width, schedule_type, payoffs=None):
lambda m: len([a for a in m.schedule.agents if a.move == "C"])
})

def step(self):
self.running = True
self.datacollector.collect(self)

def step(self):
self.schedule.step()
# collect data
self.datacollector.collect(self)

def run(self, n):
''' Run the model for n steps. '''
Expand Down
2 changes: 1 addition & 1 deletion examples/shape_example/shape_model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ def __init__(self, unique_id, model, pos, heading=(1, 0)):

class ShapesModel(Model):
def __init__(self, N, width=20, height=10):
self.running = True
self.N = N # num of agents
self.headings = ((1, 0), (0, 1), (-1, 0), (0, -1)) # tuples are fast
self.grid = SingleGrid(width, height, torus=False)
self.schedule = RandomActivation(self)
self.make_walker_agents()
self.running = True

def make_walker_agents(self):
unique_id = 0
Expand Down
2 changes: 2 additions & 0 deletions examples/sugarscape_cg/sugarscape/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ def __init__(self, height=50, width=50,
self.schedule.add(ssa)

self.running = True
self.datacollector.collect(self)

def step(self):
self.schedule.step()
# collect data
self.datacollector.collect(self)
if self.verbose:
print([self.schedule.time,
Expand Down
5 changes: 4 additions & 1 deletion examples/virus_on_network/virus_on_network/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def __init__(self, num_nodes, avg_node_degree, initial_outbreak_size, virus_spre
self.virus_check_frequency = virus_check_frequency
self.recovery_chance = recovery_chance
self.gain_resistance_chance = gain_resistance_chance
self.running = True

self.datacollector = DataCollector({"Infected": number_infected,
"Susceptible": number_susceptible,
Expand All @@ -66,6 +65,9 @@ def __init__(self, num_nodes, avg_node_degree, initial_outbreak_size, virus_spre
for a in self.grid.get_cell_list_contents(infected_nodes):
a.state = State.INFECTED

self.running = True
self.datacollector.collect(self)

def resistant_susceptible_ratio(self):
try:
return number_state(self, State.RESISTANT) / number_state(self, State.SUSCEPTIBLE)
Expand All @@ -74,6 +76,7 @@ def resistant_susceptible_ratio(self):

def step(self):
self.schedule.step()
# collect data
self.datacollector.collect(self)

def run_model(self, n):
Expand Down
2 changes: 2 additions & 0 deletions examples/wolf_sheep/wolf_sheep/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ def __init__(self, height=20, width=20,
self.schedule.add(patch)

self.running = True
self.datacollector.collect(self)

def step(self):
self.schedule.step()
# collect data
self.datacollector.collect(self)
if self.verbose:
print([self.schedule.time,
Expand Down
21 changes: 11 additions & 10 deletions mesa/visualization/templates/js/ChartModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var ChartModule = function(series, canvas_width, canvas_height) {
responsive: true,
tooltips: {
mode: 'index',
intersect: false,
intersect: false
},
hover: {
mode: 'nearest',
Expand All @@ -53,13 +53,16 @@ var ChartModule = function(series, canvas_width, canvas_height) {
xAxes: [{
display: true,
scaleLabel: {
display: true,
display: true
},
ticks: {
maxTicksLimit: 11
}
}],
yAxes: [{
display: true,
scaleLabel: {
display: true,
display: true
}
}]
}
Expand All @@ -80,12 +83,10 @@ var ChartModule = function(series, canvas_width, canvas_height) {
};

this.reset = function() {
chart.destroy();
chartData.labels = [];
chart = new Chart(context, {
type: 'line',
data: chartData,
options: chartOptions
while (chart.data.labels.length) { chart.data.labels.pop(); }
chart.data.datasets.forEach(function(dataset) {
while (dataset.data.length) { dataset.data.pop(); }
});
chart.update();
};
};
};