def init_agent(self, starting_patch):
        pass

    def __init__(self):
        super().__init__()
        self.label = str(self.id)


class Sierpinski_Extended(World):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def setup(self):
        Agent.id = 0

    def step(self):
        pass


# ############################################## Define GUI ############################################## #

import PySimpleGUI as sg
# create the board

if __name__ == "__main__":
    from core.agent import PyLogo

    PyLogo(Sierpinski_Extended,
           'Sierpinski Extended',
           agent_class=Sierpinski_Agent)
Пример #2
0
                pad=((0, 10), (20, 0)),
                tooltip='Influence radius'),
        sg.Slider(range=(0, 20),
                  default_value=10,
                  orientation='horizontal',
                  key='Influence radius',
                  size=(15, 20),
                  tooltip='Influence radius')
    ],
    [
        sg.Text('Speed factor',
                pad=((0, 10), (20, 0)),
                tooltip='Relative speed'),
        sg.Slider(range=(0, 200),
                  default_value=100,
                  orientation='horizontal',
                  key='Speed factor',
                  size=(15, 20),
                  tooltip='Relative speed')
    ]
]

if __name__ == "__main__":
    PyLogo(Starburst_World,
           'Starburst',
           gui_left_upper,
           agent_class=Starburst_Agent,
           bounce=(True, False),
           patch_size=9,
           board_rows_cols=(71, 71))
Пример #3
0
        return False


# ############################################## Define GUI ############################################## #
import PySimpleGUI as sg

gui_left_upper = [
    [
        sg.Text('nbr of agents'),
        sg.Slider(key='nbr_agents',
                  range=(1, 100),
                  default_value=18,
                  size=(8, 20),
                  orientation='horizontal',
                  pad=((0, 0), (0, 20)))
    ],
    [
        sg.Text('Figure to trace'),
        sg.Combo(['breathe', 'clockwise', 'counter-clockwise', 'twitchy'],
                 key='figure',
                 default_value='clockwise')
    ]
]

if __name__ == "__main__":
    from core.agent import PyLogo
    PyLogo(Synchronized_Agent_World,
           'Synchronized agents',
           gui_left_upper,
           bounce=None)
Пример #4
0
            Velocity((1, 1))
        ])
        for (agent, vel) in zip(self.agents, initial_velocities):
            agent.set_velocity(vel)

    def step(self):
        """
        Update the world by moving the agents.
        """
        for agent in self.agents:
            agent.move_by_velocity()
            if self.the_world().ticks > 125 and random() < 0.01:
                agent.set_velocity(Velocity((uniform(-2, 2), uniform(-2, 2))))


# ############################################## Define GUI ############################################## #
import PySimpleGUI as sg
gui_elements = [[
    sg.Text('nbr agents', pad=((0, 5), (20, 0))),
    sg.Slider(key='nbr_agents',
              range=(1, 101),
              resolution=25,
              default_value=25,
              orientation='horizontal',
              size=(10, 20))
]]

if __name__ == "__main__":
    from core.agent import PyLogo
    PyLogo(Starburst_World, 'Starburst', gui_elements)
Пример #5
0
        # Treat random graphs as a separate case.
        if graph_type == RANDOM:
            link_prob = gui_get(LINK_PROB)
            # A generator for the links
            link_generator = (Link(ring_node_list[i], ring_node_list[j])
                              for i in range(nbr_nodes - 1)
                              for j in range(i + 1, nbr_nodes)
                              if randint(1, 100) <= link_prob)
            # Run the generator to generate the links
            for _ in link_generator:
                pass
            return

        if graph_type in [RING, STAR, WHEEL]:
            Graph_Algorithms_World.build_ring_star_or_wheel_graph(
                graph_type, ring_node_list)

        # Preferential attachment and small worlds are TBD.


if __name__ == '__main__':
    from core.agent import PyLogo
    PyLogo(Graph_Algorithms_World,
           'Network test',
           gui_left_upper=graph_left_upper,
           gui_right_upper=graph_right_upper,
           agent_class=Graph_Node,
           clear=True,
           bounce=True,
           auto_setup=True)
Пример #6
0
        'length 250. (The cut cord is not shown.) The cords are in yellow to indicate\n'
        'that they are slack. Each cord\'s actual length is 275. If "Pause after cut"\n'
        'is checked, the weights do not drop until the "go" button is clicked.\n\n'
        'Cutting the cord converts the system from a single support line for the\n'
        'weights to two parallel support lines. (There are still exactly two springs.)\n\n'
        'When "go" is clicked, the weight drops by 25 units before being caught by\n'
        'two new cords. It then bounces up! In the end, the weight is at 475 rather\n'
        'than 500, where it was before the cord was cut. So even though the cords\n'
        'add 25 units, the weight ends up 25 units higher!\n\n'
        'Cutting the cord is equivalent to removing(!) the extra road in the Braess \n'
        'road paradox. It splits the weight (the "traffic") between the two sides.\n\n'
        'For a physical demo, see https://youtu.be/ekd2MeDBV8s.',
        pad=(None, (0, 10)))
],
                     [
                         sg.Button(Braess_World.CUT_CORD),
                         sg.Checkbox('Pause after cut?',
                                     default=True,
                                     key='Pause?'),
                         sg.Checkbox('Cut in slow motion?',
                                     default=True,
                                     key='Slow?')
                     ]]

if __name__ == '__main__':
    from core.agent import PyLogo
    PyLogo(Braess_World,
           "Braess' spring paradox",
           gui_left_upper=braess_left_upper,
           agent_class=Braess_Node)
Пример #7
0
                  pad=((0, 5), (10, 0)),
                  orientation='horizontal',
                  size=(10, 20))
    ],
    HOR_SEP(pad=((30, 0), (0, 0))),
    [sg.Text('Average = '),
     sg.Text('         0', key=AVERAGE)],
    [sg.Text('Fastest Top Time = '),
     sg.Text('         0', key=FASTEST_TOP)],
    [
        sg.Text('Fastest Middle Time = '),
        sg.Text('         0', key=FASTEST_MIDDLE)
    ],
    [
        sg.Text('Fastest Bottom Time = '),
        sg.Text('         0', key=FASTEST_BOTTOM)
    ]
]

if __name__ == "__main__":
    from core.agent import PyLogo

    PyLogo(Commuter_World,
           'Paradox',
           gui_left_upper,
           agent_class=Commuter,
           patch_class=Road_Patch,
           bounce=True,
           patch_size=9,
           board_rows_cols=(71, 71))
Пример #8
0
            # self.agent_class(scale=1)
            Agent(scale=1)

        initial_velocities = cycle([Velocity((-1, -1)), Velocity((-1, 1)),
                                    Velocity((0, 0)),
                                    Velocity((1, -1)), Velocity((1, 1))])
        for (agent, vel) in zip(World.agents, initial_velocities):
            agent.set_velocity(vel)

    def step(self):
        """
        Update the world by moving the agents.
        """
        for agent in World.agents:
            agent.move_by_velocity()
            if World.ticks > 125 and random() < 0.01:
                agent.set_velocity(Velocity((uniform(-2, 2), uniform(-2, 2))))


# ############################################## Define GUI ############################################## #
import PySimpleGUI as sg
gui_left_upper = [ [sg.Text('nbr agents', pad=((0, 5), (20, 0))),
                    sg.Slider(key='nbr_agents', range=(1, 101), resolution=25, default_value=25,
                              orientation='horizontal', size=(10, 20))] ]


if __name__ == "__main__":
    from core.agent import PyLogo
    PyLogo(Starburst_World, 'Starburst', gui_left_upper, bounce=True,
           patch_size=9, board_rows_cols=(71, 71))
Пример #9
0
                      [
                          sg.Text('Min pheromone level',
                                  pad=((0, 5), (10, 0))),
                          sg.Slider(key='Min_pheromone',
                                    range=(0, 75),
                                    default_value=30,
                                    orientation='horizontal',
                                    size=(10, 20))
                      ],
                      [
                          sg.Text('Min display level', pad=((0, 5), (10, 0))),
                          sg.Slider(key='Min_display_level',
                                    range=(30, 95),
                                    default_value=35,
                                    orientation='horizontal',
                                    size=(10, 20))
                      ],
                      [
                          sg.Frame('Path controls',
                                   path_controls,
                                   pad=(None, (10, 0)))
                      ]]

if __name__ == "__main__":
    from core.agent import PyLogo
    PyLogo(ACO_World,
           'ACO for TSP',
           aco_gui_left_upper,
           agent_class=ACO_Agent,
           bounce=True)
Пример #10
0
    ],
    HOR_SEP(30, pad=(None, None)),
    [
        sg.Button(button_text='Lattice2D', key='Lattice2D'),
        sg.CB('Wrap?', size=(10, 1), key='wrap')
    ],
    [
        sg.Text('num-rows'),
        sg.Slider(key='num-rows',
                  range=(0, 20),
                  default_value=8,
                  orientation='horizontal')
    ],
    [
        sg.Text('num-cols'),
        sg.Slider(key='num-cols',
                  range=(0, 20),
                  default_value=8,
                  orientation='horizontal')
    ],
]

if __name__ == "__main__":
    from core.agent import PyLogo
    # Runs PyLogo using the NW_World and NW_Node
    PyLogo(NW_World,
           'Networking',
           gui_left_upper=nw_left_upper,
           agent_class=NW_Node,
           bounce=True)
Пример #11
0
        sg.Slider(key='density',
                  range=(0, 80),
                  resolution=5,
                  size=(10, 20),
                  default_value=35,
                  orientation='horizontal',
                  pad=((0, 0), (0, 20)),
                  tooltip='The ratio of alive cells to all cells')
    ],
    [
        sg.Button(Life_World.SELECT_FOREGROUND_TEXT),
        Life_World.fg_color_chooser
    ],
    [
        sg.Button(Life_World.SELECT_BACKGROUND_TEXT),
        Life_World.bg_color_chooser
    ],
    HOR_SEP(),
    [sg.Text('Cells can be toggled when\nthe system is stopped.')],
]

if __name__ == "__main__":
    from core.agent import PyLogo

    PyLogo(Life_World,
           'Game of Life',
           gui_elements,
           patch_class=Life_Patch,
           bounce=None,
           fps=10)
Пример #12
0
                        Loop_Individual.add_gene_to_chromosome(ind.fitness, gene, ind.chromosome)


# ############################################## Define GUI ############################################## #
import PySimpleGUI as sg
loop_gui_left_upper = gui_left_upper + [
                      [sg.Text('Prob replace elt', pad=((0, 5), (20, 0))),
                       sg.Slider(key='replace_gene', range=(0, 100), default_value=95,
                                 orientation='horizontal', size=(10, 20))
                       ],

                      [sg.Text('fitness_target', pad=(None, (20, 0))),
                       sg.Combo(key='fitness_target', default_value=1500, pad=((10, 0), (20, 0)), enable_events=True,
                                values=[0, 100, 500, 700, 900, 1200, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000])
                       ],

                      [sg.Text('Cycle length', pad=(None, (20, 0))),
                       sg.Slider(key='cycle_length', range=(2, 20), default_value=10, pad=((10, 0), (0, 0)),
                                 orientation='horizontal', size=(10, 20), enable_events=True)
                       ],

                      [sg.Checkbox('Show pixel positions', key='show_positions', default=False, pad=((0, 0), (10, 0)))]

    ]


if __name__ == "__main__":
    from core.agent import PyLogo
    # gui_left_upper is from core.ga
    PyLogo(Loop_World, 'Loops', loop_gui_left_upper, agent_class=Loop_Agent)
Пример #13
0
    ],
    [
        sg.Text(
            'max-align-turn',
            pad=((0, 5),
                 (20,
                  0)),
            tooltip=
            'The most degrees (in angles) an agent can turn when aligning with flockmates'
        ),
        sg.Slider(
            key='max-align-turn',
            range=(0, 20),
            resolution=0.5,
            default_value=5,
            orientation='horizontal',
            size=(10, 20),
            tooltip=
            'The most degrees (in angles) an agent can turn when aligning with flockmates'
        )
    ],
]

if __name__ == "__main__":
    from core.agent import PyLogo
    PyLogo(Flocking_World,
           'Flocking',
           gui_elements,
           agent_class=Flocking_Agent,
           bounce=None)
Пример #14
0
],
                 [
                     sg.Checkbox('Show labels',
                                 key='show_labels',
                                 default=True,
                                 pad=((0, 0), (10, 0))),
                     sg.Checkbox('Show lengths',
                                 key='show_lengths',
                                 default=False,
                                 pad=((20, 0), (10, 0)))
                 ]]

# gui_left_upper is from core.ga
tsp_gui_left_upper = gui_left_upper + [[
    sg.Text('Nbr points', pad=((0, 5), (10, 0))),
    sg.Slider(key='nbr_points',
              range=(5, 200),
              default_value=15,
              orientation='horizontal',
              size=(10, 20))
], [sg.Frame('Path controls', path_controls, pad=(None, (10, 0)))]]

if __name__ == "__main__":
    from core.agent import PyLogo
    PyLogo(TSP_World,
           'TSP',
           tsp_gui_left_upper,
           gui_right_upper=tsp_right_upper,
           agent_class=TSP_Agent,
           bounce=True)
Пример #15
0
    def step(self):
        # Count the live neighbors in the current state.
        for patch in self.patches:
            patch.count_live_neighbors()

        # Determine and set whether each patch is_alive in the next state.
        for patch in self.patches:
            is_alive = patch.live_neighbors == 3 or patch.is_alive(
            ) and patch.live_neighbors == 2
            patch.set_alive_or_dead(is_alive)


# ############################################## Define GUI ############################################## #
import PySimpleGUI as sg

gol_left_upper = [[sg.Text('Initial density'),
                   sg.Slider(key='density', range=(0, 80), resolution=5, size=(10, 20),
                             default_value=35, orientation='horizontal', pad=((0, 0), (0, 20)),
                             tooltip='The ratio of alive cells to all cells')]] \
                  + \
                  on_off_left_upper

if __name__ == "__main__":
    from core.agent import PyLogo
    PyLogo(Life_World,
           'Game of Life',
           gol_left_upper,
           patch_class=Life_Patch,
           fps=10)
                  default_value=0,
                  enable_events=True,
                  orientation='horizontal',
                  size=(10, 20),
                  tooltip='Set the randomness of being optimal.')
    ],
    [
        sg.Text('Smoothing ', pad=((0, 5), (20, 0))),
        sg.Slider(
            key='Smoothing',
            range=(1, 20),
            resolution=0.5,
            default_value=10,
            enable_events=True,
            orientation='horizontal',
            size=(10, 20),
            tooltip=
            'Set the smoothing rate. Higher means put more weight in history.')
    ]
]

if __name__ == '__main__':
    from core.agent import PyLogo

    gb = global_vars()
    PyLogo(Braess_World,
           "Braess' Road",
           gui_left_upper=braess_left_upper,
           agent_class=Commuter,
           patch_class=Braess_Patch)
Пример #17
0
                         ],

                        [sg.Text('Prob reverse subseq', pad=((0, 5), (20, 0))),
                         sg.Slider(key='reverse_subseq', range=(0, 100), default_value=5,
                                   orientation='horizontal', size=(10, 20))
                         ],

                        [sg.Combo(values=['Diversity', 'Equality', 'Segregation'], key='div_or_seg',
                                  default_value='Segregation', pad=(None, (10, 0)))
                         ],

                        [sg.Text('Fitness target', pad=((0, 5), (20, 0))),
                         sg.Slider(key='fitness_target', default_value=0, enable_events=True,
                                   orientation='horizontal', size=(10, 20), range=(0, 10))
                         ],

                        [sg.Text('Chromosome length', pad=(None, (20, 0))),
                         sg.Slider(key='chrom_length', range=(5, board_size), enable_events=True, size=(10, 20),
                                   pad=((10, 0), (0, 0)), orientation='horizontal', default_value=board_size)
                         ],

                        ]

if __name__ == "__main__":
    from core.agent import PyLogo
    PyLogo(Segregation_World,
           'GA Segregation',
           seg_gui_left_upper,
           patch_size=patch_size,
           board_rows_cols=(board_size, board_size))
Пример #18
0
            # Adds itself to self.agents and to its patch's list of Agents.
            agent = self.agent_class(color=Color('red'))
            agent.set_velocity(Velocity((uniform(-2, 2), uniform(-2, 2))))

        for patch in self.patches:
            patch.update_collision_color(World.agents)

    def step(self):
        """
        Update the world by moving the agent and indicating the patches that intersect the agent
        """
        for agent in World.agents:
            agent.move_by_velocity()
            if random() < 0.01:
                agent.set_velocity(Velocity((randint(-2, 2), randint(-2, 2))))

        for patch in self.patches:
            patch.update_collision_color(World.agents)


# ############################################## Define GUI ############################################## #
import PySimpleGUI as sg
gui_left_upper = [[sg.Text('nbr agents', pad=((0, 5), (20, 0))),
                   sg.Slider(key='nbr_agents', range=(1, 10), default_value=3, orientation='horizontal',
                             size=(10, 20))],
                  ]

if __name__ == "__main__":
    from core.agent import PyLogo
    PyLogo(CollisionTest_World, 'Collision test', gui_left_upper, patch_class=CollisionTest_Patch, bounce=False)
Пример #19
0
                    diagonal_patch = self.patches_array[x][y]
                    top_patch = self.patches_array[x - 1][y]
                    left_patch = self.patches_array[x][y + 1]
                    diagonal_patch.set_color(Color('Orange'))
                    top_patch.set_color(Color('Grey'))
                    left_patch.set_color(Color('Grey'))
                    if i == 43:
                        self.patches_array[x - 1][y + 1].set_color(Color('Orange'))
                # set the last patch


# ############################################## Define GUI ############################################## #
import PySimpleGUI as sg

MIDDLE_ON = 'middle_on'

# switches = [sg.CB(n + '\n 1', key=n, pad=((30, 0), (0, 0)), enable_events=True)
#                                              for n in reversed(CA_World.bin_0_to_7)]
gui_left_upper = [[sg.Text('Middle On?', pad=((0, 5), (20, 0))), sg.CB('True', key=MIDDLE_ON, pad=((0, 5), (20, 0)))]]

gui_left_upperw = [[sg.Text('Middle on', pad=((0, 5), (20, 0))),
                    sg.Slider(key='nbr_agents', range=(1, 101), resolution=25, default_value=25,
                              orientation='horizontal', size=(10, 20))]]

if __name__ == "__main__":
    from core.agent import PyLogo

    # PyLogo(Braess_Road_World, 'Braess Road Paradox', gui_left_upper, bounce=True, patch_size=9, board_rows_cols=(71, 71))
    PyLogo(world_class=Braess_Road_World, caption='Braess Road Paradox', agent_class=Commuter,
           gui_left_upper=gui_left_upper, patch_class=Braess_Road_Patch)
Пример #20
0
        ),
        sg.Slider(
            key='max-align-turn',
            range=(0, 20),
            resolution=0.5,
            default_value=5,
            orientation='horizontal',
            size=(10, 20),
            tooltip=
            'The most (in degrees) an agent can turn to align with its flockmates'
        )
    ],
    HOR_SEP(30, pad=((0, 0), (0, 0))),
    [
        sg.Checkbox('Show links between flockmates?',
                    key='Show flockmate links?',
                    default=True,
                    tooltip='Show links between flockmates')
    ]
]

if __name__ == "__main__":
    from core.agent import PyLogo
    PyLogo(Flocking_World,
           'Flocking',
           gui_left_upper,
           agent_class=Flocking_Agent,
           patch_size=9,
           board_rows_cols=(65, 71),
           bounce=True)
Пример #21
0
        if World.ticks == 0:
            print()
        print(f'\t{World.ticks:2}. agents: {len(World.agents)};  %-similar: {percent_similar}%;  ', end='')

        self.unhappy_agents = [agent for agent in World.agents if not agent.is_happy]
        unhappy_count = len(self.unhappy_agents)
        percent_unhappy = round(100 * unhappy_count / len(World.agents), 2)
        print(f'nbr-unhappy: {unhappy_count:3};  %-unhappy: {percent_unhappy}.')
        World.done = unhappy_count == 0


# ############################################## Define GUI ############################################## #
import PySimpleGUI as sg
gui_left_upper = [[sg.Text('density'),
                   sg.Slider(key='density', range=(50, 95), resolution=5, size=(10, 20),
                             default_value=90, orientation='horizontal', pad=((0, 0), (0, 20)),
                             tooltip='The ratio of households to housing units')],

                  [sg.Text('% similar wanted',
                           tooltip='The percentage of similar people among the occupied 8 neighbors required ' 
                                   'to make someone happy.'),
                  sg.Combo(key='% similar wanted', values=[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
                           default_value=100,
                           tooltip='The percentage of similar people among the occupied 8 neighbors required ' 
                                   'to make someone happy.')],
                  ]

if __name__ == "__main__":
    from core.agent import PyLogo
    PyLogo(SegregationWorld, "Schelling's segregation model", gui_left_upper, bounce=None)
Пример #22
0
    sg.Text('Rule number', pad=((250, 0), (20, 10))),
    sg.Slider(key='Rule_nbr',
              range=(0, 255),
              orientation='horizontal',
              enable_events=True,
              pad=((10, 20), (0, 10))),
    sg.Text('00000000 (binary)',
            key='bin_string',
            enable_events=True,
            pad=((0, 0), (10, 0)))
], switches]

if __name__ == "__main__":
    """
    Run the CA program. PyLogo is defined at the bottom of core.agent.py.
    """
    from core.agent import PyLogo

    # Note that we are using OnOffPatch as the Patch class. We could define CA_Patch(OnOffPatch),
    # but since it doesn't add anything to OnOffPatch, there is no need for it.
    PyLogo(CA_World,
           '1D CA',
           patch_class=OnOffPatch,
           gui_left_upper=ca_left_upper,
           gui_right_upper=ca_right_upper,
           auto_setup=False,
           fps=10,
           patch_size=3,
           board_rows_cols=(CA_World.ca_display_size,
                            CA_World.ca_display_size))
Пример #23
0
                          tooltip='Nbr of nodes created by setup')
            ],
            # The "pad" on the next line is for the Col widget.
        ],
        pad=((0, 0), (5, 0))),
    sg.Col([[
        sg.Text('Node shape'),
        sg.Combo(KNOWN_FIGURES,
                 key=SHAPE,
                 default_value=NETLOGO_FIGURE,
                 tooltip='Node shape')
    ],
            [
                sg.Text('Node color'),
                sg.Combo([RANDOM] + [color[0] for color in PYGAME_COLORS],
                         key=COLOR,
                         default_value=RANDOM,
                         tooltip='Node color')
            ]])
]]

if __name__ == '__main__':
    from core.agent import PyLogo
    PyLogo(Graph_World,
           'Force test',
           gui_left_upper=network_left_upper,
           gui_right_upper=network_right_upper,
           agent_class=Graph_Node,
           clear=True,
           bounce=True)
Пример #24
0
    [
        sg.Text(STRATEGIES_PER_AGENT,
                tooltip='The number of strategies generated for each agent'),
        sg.Slider(key=STRATEGIES_PER_AGENT,
                  range=(1, 200),
                  default_value=100,
                  size=(10, 20),
                  orientation='horizontal',
                  tooltip='The number of strategies generated for each agent')
    ],
    [
        sg.Text(STEPS_TO_WIN, tooltip='The number of steps required to win'),
        sg.Slider(key=STEPS_TO_WIN,
                  range=(1, 500),
                  default_value=50,
                  resolution=25,
                  size=(10, 20),
                  orientation='horizontal',
                  tooltip='The number of steps required to win')
    ],
]

if __name__ == "__main__":
    from core.agent import PyLogo

    PyLogo(Minority_Game_World,
           'Minority game',
           gui_left_upper,
           agent_class=Minority_Game_Agent,
           fps=6)
Пример #25
0
                                    orientation='horizontal', size=(10, 20))
                          ],

                        [sg.Text('Prob exchange two unsatisfied genes', pad=((0, 5), (20, 0))),
                         sg.Slider(key='exchange_unsatisfied_genes', range=(0, 100), default_value=25,
                                   orientation='horizontal', size=(10, 20))
                         ],

                        [sg.Text('Prob reverse subseq', pad=((0, 5), (20, 0))),
                         sg.Slider(key='reverse_subseq', range=(0, 100), default_value=5,
                                   orientation='horizontal', size=(10, 20))
                         ],

                        [sg.Text('Fitness target', pad=((0, 5), (20, 0))),
                         sg.Slider(key='fitness_target', default_value=0, enable_events=True,
                                   orientation='horizontal', size=(10, 20), range=(0, 10))
                         ],

                        [sg.Text('Chromosome length', pad=(None, (20, 0))),
                         sg.Slider(key='chrom_length', range=(4, 140), enable_events=True, size=(10, 20),
                                   pad=((10, 0), (0, 0)), orientation='horizontal', default_value=50,
                                   resolution=2)
                         ],

                        ]


if __name__ == "__main__":
    from core.agent import PyLogo
    PyLogo(Parentheses_World, 'GA Parentheses', paren_gui_left_upper, patch_size=10, board_rows_cols=(10, 10))
Пример #26
0
                  orientation='horizontal',
                  size=(10, 20),
                  enable_events=True)
    ],
    [
        sg.Checkbox('Move points',
                    key='move_points',
                    pad=(None, (20, 0)),
                    default=False),
        sg.Checkbox('Show lengths',
                    key='show_lengths',
                    pad=((20, 0), (20, 0)),
                    default=False),
    ],
    [
        sg.Checkbox('Show pixel positions',
                    key='show_positions',
                    default=False,
                    pad=((0, 0), (10, 0)))
    ]
]

if __name__ == "__main__":
    from core.agent import PyLogo
    # gui_left_upper is from core.ga
    PyLogo(Cycle_World,
           'Closed paths',
           cycle_gui_left_upper,
           agent_class=Cycle_Agent,
           bounce=True)
Пример #27
0
    def setup(self):
        self.get_colors()
        for patch in self.patches:
            is_on = randint(0, 100) < 10
            patch.set_on_off(is_on)

    def step(self):
        self.get_colors()

        # Run this only if we're running this on its own.
        if isinstance(self, OnOffWorld):
            for patch in self.patches:
                is_on = patch.is_on and randint(
                    0, 100) < 90 or not patch.is_on and randint(0, 100) < 1
                patch.set_on_off(is_on)


# ############################################## Define GUI ############################################## #
on_off_left_upper = [[
    sg.Button(OnOffWorld.SELECT_ON_TEXT), OnOffWorld.on_color_chooser
], [sg.Button(OnOffWorld.SELECT_OFF_TEXT), OnOffWorld.off_color_chooser]]

if __name__ == "__main__":
    from core.agent import PyLogo
    PyLogo(OnOffWorld,
           'On-Off World',
           on_off_left_upper,
           patch_class=OnOffPatch,
           fps=10)
Пример #28
0
import PySimpleGUI as sg

gui_left_upper = [
    [
        sg.Combo(KNOWN_FIGURES,
                 key='shape',
                 default_value='netlogo_figure',
                 pad=((0, 9), (0, 0)),
                 tooltip='Shape of element'),
        sg.Slider(key='nbr_agents',
                  range=(1, 100),
                  default_value=18,
                  size=(10, 20),
                  orientation='horizontal',
                  pad=((0, 0), (0, 20)),
                  tooltip='Number of elements'),
    ],
    # sg.Slider(range=(3, 10), key='sides', default_value=5, size=(8, 20),
    #           orientation='horizontal', pad=((0, 0), (0, 20)))],
    [
        sg.Text('Figure to trace'),
        sg.Combo(['breathe', 'clockwise', 'counter-clockwise', 'twitchy'],
                 key='figure',
                 default_value='clockwise')
    ]
]

if __name__ == "__main__":
    from core.agent import PyLogo
    PyLogo(Synchronized_Agent_World, 'Synchronized agents', gui_left_upper)
Пример #29
0
        """
        for agent in self.agents:
            agent.move_by_velocity()
            if random() < 0.01:
                agent.set_velocity(Velocity((randint(-2, 2), randint(-2, 2))))

        for patch in self.patches:
            patch.update_collision_color(self.agents)


# ############################################## Define GUI ############################################## #
import PySimpleGUI as sg
gui_elements = [
    [
        sg.Text('nbr agents', pad=((0, 5), (20, 0))),
        sg.Slider(key='nbr_agents',
                  range=(1, 10),
                  default_value=3,
                  orientation='horizontal',
                  size=(10, 20))
    ],
]

if __name__ == "__main__":
    from core.agent import PyLogo
    PyLogo(CollisionTest_World,
           'Collision test',
           gui_elements,
           patch_class=CollisionTest_Patch,
           bounce=False)