예제 #1
0
def testSix():
    runs = 10
    for p in np.arange(0, 0.41, 0.05):
        count = {}
        count[h.returnZero.__name__] = 0
        count[h.Manhattan.__name__] = 0
        count[h.Euc.__name__] = 0
        numSolved = 0
        while (numSolved < 3 * runs):
            dimm = 100
            start = (0, 0)
            goal = (dimm - 1, dimm - 1)
            grid = gd.generateFireGrid(dimm, p)
            solved, _ = BDBFS(grid, start, goal)
            for heuristic in [h.returnZero, h.Manhattan, h.Euc]:
                if (solved):
                    solved, solvedPath, testingData = aStar(
                        grid, start, goal, heuristic, True)
                    if (heuristic == h.returnZero):
                        solved, solvedPath, testingData = BFS(
                            grid, start, goal)
                    numSolved += 1
                    closedLen, *_ = testingData
                    count[heuristic.__name__] += closedLen
        print(
            math.ceil(p * 100) / 100, " : ",
            math.floor(count[h.returnZero.__name__] / runs),
            math.floor(count[h.Manhattan.__name__] / runs),
            math.floor(count[h.Euc.__name__] / runs))
예제 #2
0
def testTwo():
    heuristic = h.Manhattan
    p = 0.3
    dimm = 50
    start = (0, 0)
    goal = (dimm - 1, dimm - 1)
    grid = gd.generateFireGrid(dimm, p)
    solved1, solvedPathaStar1, testingDataaStar1 = aStar(grid,
                                                         start,
                                                         goal,
                                                         heuristic,
                                                         tieSort=False)
    solved2, solvedPathaStar2, testingDataaStar2 = aStar(grid,
                                                         start,
                                                         goal,
                                                         heuristic,
                                                         tieSort=True)
    assert (solved1 == solved2)
    if (solved1):
        (_, t1, _) = testingDataaStar1
        (_, t2, _) = testingDataaStar2
        print(len(t1), " : ", len(t2))
    else:
        print(len(testingDataaStar1), ":", len(testingDataaStar2))
        print("unsolved")
    print(str(grid))
예제 #3
0
def testFour():
    start = (0, 0)
    p = 0.3
    dimm = 5
    goal = (dimm - 1, dimm - 1)
    heuristic = h.Manhattan
    grid = gd.generateFireGrid(dimm, 0)
    previousFireGrids = dict()
    solved, solvedPath, testingData = aStar(grid, start, goal, heuristic, True,
                                            True, 0.5, 0.3)
    print(generateFireGrids(previousFireGrids, grid, len(solvedPath) - 1, 0.3))
    print(solvedPath)
    print(fireEval(grid, solvedPath, 0.3))
예제 #4
0
def testFive():
    for q in np.arange(0, 1.04, 0.05):
        runs = 100
        success = 0
        tries = 0
        while (tries < runs):
            #thresh = 0.5
            start = (0, 0)
            dimm = 30
            bottomLeft = (dimm - 1, 0)
            upperRight = (0, dimm - 1)
            p = 0.2
            goal = (dimm - 1, dimm - 1)
            heuristic = h.Manhattan
            grid = gd.generateFireGrid(dimm, p)
            #print(grid)
            previousFireGrids = dict()
            #solvedStrong, solvedPath, testingData = aStar(grid, start, goal, heuristic, False, True, thresh, q)
            solved, _ = BDBFS(grid, start, goal)
            fireHasPath, _ = BDBFS(grid, bottomLeft, upperRight)
            if (solved and fireHasPath):
                listings = [i for i in np.arange(0, 1.05, 0.05)]
                for i in listings:
                    _, solvedPath, testData = aStar(grid, start, goal,
                                                    h.Manhattan, False, True,
                                                    i, q, previousFireGrids)
                    if (solvedPath):
                        _, _, _, previousFireGrids = testData
                        #print(listings)
                        tries += 1
                        fireSolved, _ = fireEval(grid, solvedPath, q)
                        if (fireSolved):
                            success += 1
                        break
                        #print(grid)
                        #print(solvedPath)

        print("for", q, ":", success / tries, " : ", success, "/", tries)
예제 #5
0
def testThree():
    p = 0.3
    dimm = 10
    grid = gd.generateFireGrid(dimm, 0)
    previousFireGrids = dict()
    print(generateFireGrids(previousFireGrids, grid, 1, 0.3))