예제 #1
0
goal = np.zeros((3, 3)).astype(int)
end_state = 'end.txt'
with open(end_state) as fil:
    # read the goal state
    row = 0  # the currebt row
    line = fil.readline()
    while line:
        for col, no in enumerate(line.split()):
            goal[row][col] = no
        line = fil.readline()
        row = row + 1

if len(sys.argv) < 2:
    print("Start File not enterd hence generation it from random")
    # raise Exception("Enter the start file atleast")
    state = generate_puzzle(goal, steps=50)
else:
    start_file = sys.argv[1]

    end_state = 'end.txt'

    if len(sys.argv) > 2:
        end_state = sys.argv[2]

    state = np.zeros((3, 3)).astype(int)
    goal = np.zeros((3, 3)).astype(int)

    with open(start_file) as fil:
        # read the goal state
        row = 0  # the currebt row
        line = fil.readline()
예제 #2
0
	for row in range(len(state)):
		for col in range(len(state[0])):
			goal_hash[goal[row][col]] = [row,col]
			state_hash[state[row][col]] = [row,col]

	print(goal_hash)

	open_list = dict()
	close_list = dict()
	all_states = [] # a list which will store all the states and we will use the index as a hash value for index of the lists
	iterations = 0 # the g(n) cost encountered till now
	depth = dict() # analogous to real cost
	parents = []
	parent = dict()
	# randomly procude the start state
	state = generate_puzzle(goal, steps = 200).astype(int)
	print("The start state : \n{}\nThe Goal state is : \n{}".format(state, goal))

	all_states.append(state)
	depth[0] = 0
	parent[0] = -1
	parents.append(-1)
	open_list[0] = 0 # cost initially
	success = False
	goal_index = 0
	while bool(open_list): # empty dictionaries evaluate to False
		# print(depth)
		sno = min(open_list, key=open_list.get)  # state no with the lowest cost
		current_state = all_states[sno] # get the current state

		del open_list[sno]
예제 #3
0
    end_state = sys.argv[2]

state = np.zeros((3, 3)).astype(int)
goal = np.zeros((3, 3)).astype(int)

with open(end_state) as fil:
    # read the goal state
    row = 0  # the currebt row
    line = fil.readline()
    while line:
        for col, no in enumerate(line.split()):
            goal[row][col] = no
        line = fil.readline()
        row = row + 1

state = generate_puzzle(goal, steps=100)
print(state)
searchObjecth4 = []
searchObjecth3 = []
while True:
    searchObjecth3 = run_experiment(start_state=state,
                                    goal_state=goal,
                                    h_function=h3)
    searchObjecth4 = run_experiment(start_state=state,
                                    goal_state=goal,
                                    h_function=h4)
    if searchObjecth3.depth[searchObjecth3.goal_no] < searchObjecth4.depth[
            searchObjecth4.goal_no]:
        break
    state = generate_puzzle(goal, steps=100)
print("Found")