Skip to content
Snippets Groups Projects
helpers.py 1.33 KiB
Newer Older
  • Learn to ignore specific revisions
  • import math
    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.patches as patches
    import random
    
    
    """
    Helper Functions
    """
    def create_random_starts_and_goals(env, num_agents):
        """
        Given some map file, create a set of starts and goals for the specified 
        number of agents. This function will create a file folowing the agent file format.
        """
    
        starts = []
        goals = []
    
        for i in range(num_agents):
            # generate a random start
    
    rachelmoan's avatar
    rachelmoan committed
            x = random.uniform(env.boundary[0][0], env.boundary[0][1])
            y = random.uniform(env.boundary[1][0], env.boundary[1][1])
    
        
            while [x,y] in starts:
    
    rachelmoan's avatar
    rachelmoan committed
                x = random.uniform(env.boundary[0][0], env.boundary[0][1])
                y = random.uniform(env.boundary[1][0], env.boundary[1][1])
    
    rachelmoan's avatar
    rachelmoan committed
            starts.append([x,y,0])
    
    
            # generate a random goal
    
    rachelmoan's avatar
    rachelmoan committed
            x = random.uniform(env.boundary[0][0], env.boundary[0][1])
            y = random.uniform(env.boundary[1][0], env.boundary[1][1])
    
        
            while [x,y] in goals:
    
    rachelmoan's avatar
    rachelmoan committed
                x = random.uniform(env.boundary[0][0], env.boundary[0][1])
                y = random.uniform(env.boundary[1][0], env.boundary[1][1])
    
    
            goals.append([x,y])
    
        return starts,goals
    
    def read_agents_from_file(fname):
        pass
    
    def generate_random_agents(num_agents):
        pass
    
    def read_environment_from_file(fname):
        pass