How to use the mesa.visualization.TextVisualization.TextVisualization function in Mesa

To help you get started, we’ve selected a few Mesa examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github projectmesa / mesa / examples / wolf_sheep / wolf_sheep / test_random_walk.py View on Github external
self.agent_count = agent_count

        self.schedule = RandomActivation(self)
        # Create agents
        for i in range(self.agent_count):
            x = self.random.randrange(self.width)
            y = self.random.randrange(self.height)
            a = WalkerAgent((x, y), self, True)
            self.schedule.add(a)
            self.grid.place_agent(a, (x, y))

    def step(self):
        self.schedule.step()


class WalkerWorldViz(TextVisualization):
    '''
    ASCII Visualization for a WalkerWorld agent.
    Each cell is displayed as the number of agents currently in that cell.
    '''

    def __init__(self, model):
        '''
        Create a new visualization for a WalkerWorld instance.

        args:
            model: An instance of a WalkerWorld model.
        '''
        self.model = model
        grid_viz = TextGrid(self.model.grid, None)
        grid_viz.converter = lambda x: str(len(x))
        self.elements = [grid_viz]
github projectmesa / mesa / examples / Schelling / Schelling.py View on Github external
self.type = agent_type

    def step(self, model):
        similar = 0
        for neighbor in model.grid.neighbor_iter(self.pos):
            if neighbor.type == self.type:
                similar += 1

        # If unhappy, move:
        if similar < model.homophily:
            model.grid.move_to_empty(self)
        else:
            model.happy += 1


class SchellingTextVisualization(TextVisualization):
    '''
    ASCII visualization for schelling model
    '''

    def __init__(self, model):
        '''
        Create new Schelling ASCII visualization.
        '''
        self.model = model

        grid_viz = TextGrid(self.model.grid, self.ascii_agent)
        happy_viz = TextData(self.model, 'happy')
        self.elements = [grid_viz, happy_viz]

    @staticmethod
    def ascii_agent(a):
github projectmesa / mesa / examples / WolfSheep / WolfSheepVisualization.py View on Github external
'''
Visualization for the Wolf-Sheep Predation
'''

from WolfSheep import Wolf, Sheep
from mesa.visualization.TextVisualization import TextVisualization, TextGrid


class WolfSheepVisualization(TextVisualization):
    '''
    ASCII visualization of the WolfSheepPredation model.

    Each cell displays S if only sheep, W if only wolves, or X if both.
    (blank if none)
    '''

    def __init__(self, model):
        self.model = model
        grid_viz = TextGrid(self.model.grid, self.draw_cell)
        self.elements = [grid_viz]

    @staticmethod
    def draw_cell(cell):
        if len(cell) == 0:
            return " "
github projectmesa / mesa / examples / Schelling / server.py View on Github external
from mesa.visualization.ModularVisualization import ModularServer
from mesa.visualization.modules import CanvasGrid, ChartModule, TextElement
from mesa.visualization.UserParam import UserSettableParameter

from mesa.visualization.TextVisualization import (
    TextData, TextGrid, TextVisualization
)

from model import Schelling


class SchellingTextVisualization(TextVisualization):
    '''
    ASCII visualization for schelling model
    '''

    def __init__(self, model):
        '''
        Create new Schelling ASCII visualization.
        '''
        self.model = model

        grid_viz = TextGrid(self.model.grid, self.ascii_agent)
        happy_viz = TextData(self.model, 'happy')
        self.elements = [grid_viz, happy_viz]

    @staticmethod
    def ascii_agent(a):
github projectmesa / mesa / examples / schelling / run_ascii.py View on Github external
from mesa.visualization.TextVisualization import (
    TextData, TextGrid, TextVisualization
)

from model import Schelling


class SchellingTextVisualization(TextVisualization):
    '''
    ASCII visualization for schelling model
    '''

    def __init__(self, model):
        '''
        Create new Schelling ASCII visualization.
        '''
        self.model = model

        grid_viz = TextGrid(self.model.grid, self.print_ascii_agent)
        happy_viz = TextData(self.model, 'happy')
        self.elements = [grid_viz, happy_viz]

    @staticmethod
    def print_ascii_agent(a):