Ejemplo n.º 1
0
def main():

    # Usability
    fname = input("File Name -> ")
    heurT = input("Heuristic Type (A or B) -> ")

    # Initialize from file and create a search manager object.
    rootNode, goalMap = InitFromFile(fname, heurT)
    search = AStar.AStarSearch(rootNode, goalMap)
    print("Initial Heuristic:", rootNode.heu)

    # Some terminal output for verbose operation
    print("--- GOAL ---")
    print(goalMap)
    print()
    print(rootNode)

    result = search.doSearch()
    output = GenerateOutput(rootNode, search, result)
    print("\n", "********************************", "\n")
    print(output)
    print("\n", "********************************", "\n")

    #Write results to file if output name is specified.
    fname = ""
    fname = input("Output File Name (or ENTER to skip) -> ")
    if (fname != ""):
        writeout = open(fname, "w+")
        writeout.write(output)
        writeout.close()
        print("Saved.")
    else:
        print("Not saved.")
Ejemplo n.º 2
0
 def __init__(self,
              controller,
              width=20,
              height=20,
              obstacle_map=[(3, 3)],
              start=(1, 1),
              end=(5, 5),
              behind=(0, 0)):
     super().init(controller)
     """
     width and height in matrix size (width(cm) / spacing(cm))
     obstacle_map is location of obstacles in matrix coordinates
     behind is matrix location behind robot
     """
     self.graph = alg.AStarGraph(obstacles=obstacle_map,
                                 width=width,
                                 height=height)
     self.result, self.cost = alg.AStarSearch(navPoints=[start, end],
                                              behind=behind,
                                              graph=self.graph)
     print("init pathingstate")