コード例 #1
0
        list1 = findChildren(parent, size)
        for i in range(len(list1)):
            copy1 = list1[i].copy()
            children.append(copy1)
        for child in children:
            # print(child)
            step = step + 1
            child_copy = child.copy()
            stack.append(child_copy)
            remove_from_stack = False
            break
        if remove_from_stack:
            stack.pop()


A = constructMatrix(4, 4, 1, 1, 2, 1, 3, 1, 1, 2)
Goal = constructGoalMatrix(4, 4, 1, 2, 2, 2, 3, 2)

import time

start_time = time.time()
dfsTreeSearch(A, 4, Goal)
print("--- %s seconds ---" % (time.time() - start_time))

# #######################################################
# A1 = constructMatrix(3, 3, 1, 1, 2, 1, 3, 1, 1, 2)
# Goal1 = constructGoalMatrix(3, 3, 3, 3, 2, 3, 1, 3)
#
# A2 = constructMatrix(3, 3, 1, 1, 2, 1, 3, 1, 3, 3)
# Goal2 = constructGoalMatrix(3, 3, 3, 3, 2, 3, 1, 3)
#
コード例 #2
0
            # Child is on the closed list
            whetherincloselist = findIncloseList(child, closelist)
            if whetherincloselist:
                continue
            # Create the f, g, and h values
            child.g = current_node.g + 10
            child.h = Manhattan(child.state, Goal, size)
            child.f = child.g + child.h
            whetherinopenlist = findIncloseList(child, openlist)
            # Child is already in the open list
            if whetherinopenlist:
                continue
            openlist.append(child)


A = constructMatrix(4, 4, 4, 1, 4, 2, 4, 3, 4, 4)
Goal = constructGoalMatrix(4, 4, 2, 2, 3, 2, 4, 2)
import time

start_time = time.time()
print(AstarSearch(A, 4, Goal))
print("--- %s seconds ---" % (time.time() - start_time))

# #######################################################
# A1 = constructMatrix(3, 3, 1, 1, 2, 1, 3, 1, 1, 2)
# Goal1 = constructGoalMatrix(3, 3, 3, 3, 2, 3, 1, 3)
#
# A2 = constructMatrix(3, 3, 1, 1, 2, 1, 3, 1, 3, 3)
# Goal2 = constructGoalMatrix(3, 3, 3, 3, 2, 3, 1, 3)
#
# A3 = constructMatrix(3, 3, 1, 1, 2, 1, 3, 1, 3, 3)
コード例 #3
0
        lengthlist = []
        lengthlist.append(length)
        lengthlist.sort()
        State = parentState.pop(0)
        statelist1, b, step, end = moveAgent(State.state, size, goal,
                                             searchedNodes, Start,
                                             State.parent)
        totalstep = totalstep + step
        print("Number of nodes expanded(enable duplicate): ", totalstep)
        if end:
            break
        for i in range(len(statelist1)):
            parentState.append(statelist1[i])
        searchedNodes.append(State)
        # b_copy = b.copy()
    return totalstep
    print("Space comlexity is : ", lengthlist[-1])


# A = constructMatrix(4, 4, 4, 1, 4, 2, 4, 3, 4, 4)
# Goal = constructGoalMatrix(4, 4, 2, 2, 3, 2, 4, 2)

A2 = constructMatrix(3, 3, 1, 1, 2, 1, 3, 1, 3, 3)
Goal2 = constructGoalMatrix(3, 3, 3, 3, 2, 3, 1, 3)

import time

start_time = time.time()
BFSTreesearch(A2, 3, Goal2)
print("--- %s seconds ---" % (time.time() - start_time))