<jupyter_start><jupyter_text>&copy; Copyright 2019 - Present Firebolt, Inc. All Rights Reserved. Robot Algorithm - Search Lab Problem StatementA child is lost in a park. She wants to find her mother. Using ```Mesa```, write the algorithm that wild allow the child to find the mother. 1. Installing & Importing Modules<jupyter_code>!pip3 install -r ../requirements.txt # Install Mesa & other packages
from mesa import Model, Agent
from mesa.time import BaseScheduler
from mesa.space import MultiGrid
import random
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline<jupyter_output><empty_output><jupyter_text>2. Create the classes.<jupyter_code>class Mother(Agent):
    def __init__(self, unique_id):self.unique_id = unique_id
    def step(self, model):self.move(model)
    def move(self, model):
        grid = model.grid
        x, y = self.pos
        possible_steps = grid.get_neighborhood((x, y), moore=True, include_center=True)
        choice = random.choice(possible_steps)
        grid.move_agent(self, choice)
class Child(Agent):
    def __init__(self, unique_id, mother):
        self.unique_id = unique_id
        self.mother = mother
    def step(self, model):self.move(model) 
    def move(self, model):
        x, y = self.pos
        mX, mY = self.mother.pos
        dX = x-mX; dY = y-mY
        vX = 0; vY = 0;
        if abs(dX) > 0:vX = dX/abs(dX)
        if abs(dY) > 0:vY = dY/abs(dY)
        newX = round(x - vX); newY = round(y - vY)
        model.grid.move_agent(self, (newX, newY))<jupyter_output><empty_output><jupyter_text>3. Testing<jupyter_code>class Evaluator(Model):
    def __init__(self, width, height, torus):
        self.grid = MultiGrid(height, width, torus)
        self.schedule = BaseScheduler(self)
        self.create_agents()
        
    def create_agents(self):
        m = Mother(1)
        self.schedule.add(m)
        self.grid.place_agent(m, (5, 5))
        c = Child(2, m)
        self.schedule.add(c)
        self.grid.place_agent(c, (1, 0))
    def step(self):self.schedule.step()
    def run_model(self, steps):
        for i in range(steps):self.step()
def print_the_grid(model):
    follow_grid = np.zeros((follow_model.grid.width, follow_model.grid.height))
    for cell in follow_model.grid.coord_iter():
        cell_content, x, y = cell
        for i,a in enumerate(cell_content):
            follow_grid[y][x] += a.unique_id
    plt.imshow(follow_grid, interpolation='nearest')
    plt.grid(True)
    plt.show()
follow_model = FollowModel(width=10, height=10, torus=False)
print_the_grid(follow_model)
for i in range(10):
    follow_model.run_model(1)
    print_the_grid(follow_model)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11668524712002973, 'fraction_numerical': 0.00929022668153103, 'mean_word_length': 3.273015873015873, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '546569', 'license': 'MIT', 'n_tokens_mistral': 938, 'n_tokens_neox': 910, 'n_words': 224, 'path': 'research/Robot Algorithm - Search.ipynb', 'repo_name': 'firebolt-ai/robotos', 'size': '2691'}