diff --git a/examples/schelling/model.py b/examples/schelling/model.py index f424e7e3853..52cfafa2c57 100644 --- a/examples/schelling/model.py +++ b/examples/schelling/model.py @@ -1,10 +1,7 @@ -from mesa import Model, Agent -from mesa.time import RandomActivation -from mesa.space import SingleGrid -from mesa.datacollection import DataCollector +import mesa -class SchellingAgent(Agent): +class SchellingAgent(mesa.Agent): """ Schelling segregation agent """ @@ -35,7 +32,7 @@ def step(self): self.model.happy += 1 -class Schelling(Model): +class Schelling(mesa.Model): """ Model class for the Schelling segregation model. """ @@ -49,11 +46,11 @@ def __init__(self, width=20, height=20, density=0.8, minority_pc=0.2, homophily= self.minority_pc = minority_pc self.homophily = homophily - self.schedule = RandomActivation(self) - self.grid = SingleGrid(width, height, torus=True) + self.schedule = mesa.time.RandomActivation(self) + self.grid = mesa.space.SingleGrid(width, height, torus=True) self.happy = 0 - self.datacollector = DataCollector( + self.datacollector = mesa.DataCollector( {"happy": "happy"}, # Model-level count of happy agents # For testing purposes, agent's individual x and y {"x": lambda a: a.pos[0], "y": lambda a: a.pos[1]}, diff --git a/examples/schelling/run_ascii.py b/examples/schelling/run_ascii.py index a2c84d929b3..8d70c39756e 100644 --- a/examples/schelling/run_ascii.py +++ b/examples/schelling/run_ascii.py @@ -1,9 +1,9 @@ -from mesa.visualization.TextVisualization import TextData, TextGrid, TextVisualization +import mesa from model import Schelling -class SchellingTextVisualization(TextVisualization): +class SchellingTextVisualization(mesa.visualization.TextVisualization): """ ASCII visualization for schelling model """ @@ -14,8 +14,8 @@ def __init__(self, model): """ self.model = model - grid_viz = TextGrid(self.model.grid, self.print_ascii_agent) - happy_viz = TextData(self.model, "happy") + grid_viz = mesa.visualization.TextGrid(self.model.grid, self.print_ascii_agent) + happy_viz = mesa.visualization.TextData(self.model, "happy") self.elements = [grid_viz, happy_viz] @staticmethod diff --git a/examples/schelling/server.py b/examples/schelling/server.py index 15538ea9637..3f4d09dbf90 100644 --- a/examples/schelling/server.py +++ b/examples/schelling/server.py @@ -1,11 +1,9 @@ -from mesa.visualization.ModularVisualization import ModularServer -from mesa.visualization.modules import CanvasGrid, ChartModule, TextElement -from mesa.visualization.UserParam import UserSettableParameter +import mesa from model import Schelling -class HappyElement(TextElement): +class HappyElement(mesa.visualization.TextElement): """ Display a text count of how many happy agents there are. """ @@ -35,19 +33,23 @@ def schelling_draw(agent): happy_element = HappyElement() -canvas_element = CanvasGrid(schelling_draw, 20, 20, 500, 500) -happy_chart = ChartModule([{"Label": "happy", "Color": "Black"}]) +canvas_element = mesa.visualization.CanvasGrid(schelling_draw, 20, 20, 500, 500) +happy_chart = mesa.visualization.ChartModule([{"Label": "happy", "Color": "Black"}]) model_params = { "height": 20, "width": 20, - "density": UserSettableParameter("slider", "Agent density", 0.8, 0.1, 1.0, 0.1), - "minority_pc": UserSettableParameter( + "density": mesa.visualization.UserSettableParameter( + "slider", "Agent density", 0.8, 0.1, 1.0, 0.1 + ), + "minority_pc": mesa.visualization.UserSettableParameter( "slider", "Fraction minority", 0.2, 0.00, 1.0, 0.05 ), - "homophily": UserSettableParameter("slider", "Homophily", 3, 0, 8, 1), + "homophily": mesa.visualization.UserSettableParameter( + "slider", "Homophily", 3, 0, 8, 1 + ), } -server = ModularServer( +server = mesa.visualization.ModularServer( Schelling, [canvas_element, happy_element, happy_chart], "Schelling", model_params )