예제 #1
0
 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]
예제 #2
0
    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]
예제 #3
0
파일: test.py 프로젝트: bangtree/mesa
class SandTable(Grid):

    def __init__(self, width, height):
        super().__init__(width, height, torus=False)
        self.viz = TextGrid(self, self.val_converter)
        self.spill_q = []       # agents who are currently 'spilling'
        self.avalanches = []    # [(step, cnt) ... ]

    def val_converter(self, agent):
        return '%1d ' % (agent._grains)

    def render(self):
        print(self.viz.render())

    def spilling(self, cell):
        self.spill_q.append(cell)

    def distribute(self, model):
        cnt = 0
        while self.spill_q:
            agent = self.spill_q.pop()
            x, y = agent.unique_id
            for n in model.grid.neighbor_iter(agent.unique_id, moore=False):
                n.add_a_grain()
            agent._grains -= 4
            if agent._grains < 0:
                print('grains < 0!', agent.unique_id, agent._grains)
                exit()
            agent._spilling = False
            cnt += 1
        self.avalanches.append((model.schedule.time, cnt))
예제 #4
0
    def __init__(self, model):
        '''
        Create new Schelling ASCII visualization
        '''
        super().__init__(model)

        grid_viz = TextGrid(self.model.grid, self.print_ascii_agent)
        happy_viz = TextData(self.model, 'happy')
        self.elements = [grid_viz, happy_viz]
    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]
    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]
예제 #7
0
    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, lambda x: str(len(x)))
        self.elements = [grid_viz]
예제 #8
0
파일: test.py 프로젝트: bangtree/mesa
 def __init__(self, width, height):
     super().__init__(width, height, torus=False)
     self.viz = TextGrid(self, self.val_converter)
     self.spill_q = []       # agents who are currently 'spilling'
     self.avalanches = []    # [(step, cnt) ... ]
예제 #9
0
 def __init__(self, model):
     self.model = model
     grid_viz = TextGrid(self.model.grid, self.draw_cell)
     self.elements = [grid_viz]