예제 #1
0
파일: model.py 프로젝트: draco1703/Python
def available_algorithms(choice):
    solutions = {"1": "Recursive"}
    #solutions = {"1": {"name": "Recursive", "algorithm": search}}
    if choice not in solutions.keys():
        raise exc.InvalidInputException("Invalid input - Please try again")
    else:
        return solutions[choice]
예제 #2
0
파일: model.py 프로젝트: draco1703/Python
 def load_maze_data(self, filename):
     if(self.validate_csv_file(filename)):
         mazes = []
         try:
             with open(filename, "r") as f:
                 reader = csv.reader(f, delimiter=(','))
                 for row in reader:
                     maze = Maze(int(row[0]), int(row[0]))
                     maze.moves.append(int(row[1]))
                     maze.generation_times.append(float(row[2]))
                     maze.solution_times.append(float(row[3]))
                     mazes.append(maze)
             return mazes
         except:
             raise exc.InvalidInputException("Unable to read the file - maze data format")
     else:
         raise exc.InvalidInputException("Unable to read the file - wrong extention type")
예제 #3
0
파일: model.py 프로젝트: draco1703/Python
 def solve_multiple_mazes(self, solution_algorithm, path_to_file, repetitions):
     if(self.validate_csv_file(path_to_file)):
         mazes = self.read_multiple_mazes(path_to_file)
         sol_alg = self.select_sol_algorithm(solution_algorithm)
         Thread(target=self.sol_maze, args=(sol_alg, self.queue, mazes, repetitions)).start()
         solved_mazes = self.queue.get() 
         return solved_mazes
     else:
         raise exc.InvalidInputException("Unable to read the file - wrong extention type or maze format")
예제 #4
0
파일: model.py 프로젝트: draco1703/Python
 def solve_single_maze(self, solution_algorithm, path_to_file, repetitions):
     if(self.validate_csv_file(path_to_file) and self.validate_input_range(repetitions, self.MIN_REPETITIONS, self.MAX_REPETITIONS)):
         maze = self.read_maze(path_to_file)
         sol_alg = self.select_sol_algorithm(solution_algorithm)
         Thread(target=self.sol_maze, args=(sol_alg, self.queue, maze, repetitions)).start()
         #moves = self.queue.get()
         return maze
     else:
         raise exc.InvalidInputException("Unable to read the file - wrong extention type or maze format")
예제 #5
0
파일: model.py 프로젝트: draco1703/Python
 def generate_single_maze(self, generation_algorithm, size):
     if(self.validate_input_range(size, self.MIN_SIZE, self.MAX_SIZE)):
         size = int(size)
         gen_alg = self.select_gen_algorithm(generation_algorithm)
         Thread(target=self.gen_maze, args=(gen_alg, self.queue, size)).start()
         maze = self.queue.get()
         self.save_maze("maze.csv", maze)
         return maze
     else:
         raise exc.InvalidInputException("Invalid input - maze size must be a number between {} and {}".format(self.MIN_SIZE, self.MAX_SIZE))
예제 #6
0
파일: model.py 프로젝트: draco1703/Python
 def generate_and_solve_multiple(self, repetitions, save):
     if(self.validate_input_range(repetitions, self.MIN_REPETITIONS, self.MAX_REPETITIONS)):
         sol_list = [self.search]
         gen_list = [self.depth_first_generation]
         p = ProducerThread(self.queue, repetitions, gen_list)
         c = ConsumerThread(self.queue, repetitions, sol_list)
         p.start()
         c.start()
         p.join()
         c.join()
         if(save == True):
             grids = []
             for maze in p.maze_list:
                 grids.append(maze.grid)
             self.save_maze_data("maze_data.csv", p.maze_list)
             self.save_multiple_mazes("producerconsumer.csv", grids)
         return p.maze_list
     else:
         raise exc.InvalidInputException("Repetitions must be a number between {} and {}".format(self.MIN_REPETITIONS, self.MAX_REPETITIONS))
예제 #7
0
파일: model.py 프로젝트: draco1703/Python
 def select_sol_algorithm(self, name):
     solution_algorithms = {"Recursive": self.search} # Make option for all algorithms?
     if(name in solution_algorithms):
         return solution_algorithms[name]
     else:
         raise exc.InvalidInputException("Solution algorithm not found")
예제 #8
0
파일: model.py 프로젝트: draco1703/Python
 def select_gen_algorithm(self, name):
     generation_algorithms = {"DFS": self.depth_first_generation}
     if(name in generation_algorithms):
         return generation_algorithms[name]
     else:
         raise exc.InvalidInputException("Generation algorithm not found")