A* cleanup
This commit is contained in:
parent
86c5ad6fd1
commit
c443087ab0
23
src/agent.py
23
src/agent.py
@ -153,9 +153,7 @@ class Agent:
|
||||
|
||||
def get_start_state(self):
|
||||
entities = self.simulation.state.entities
|
||||
for entity in entities:
|
||||
if entity.entity_type == 'truck':
|
||||
orientation = entity.orientation
|
||||
# orientation - self.orientation
|
||||
position = self.current_pos
|
||||
house_list = tuple(self.houses)
|
||||
start_state = (position, house_list)
|
||||
@ -169,14 +167,22 @@ class Agent:
|
||||
|
||||
def succesor(self, state):
|
||||
successors_pos = self.graph[state[0]]
|
||||
house_list = [state[1]]
|
||||
house_list = state[1]
|
||||
successors = ()
|
||||
for pos in successors_pos:
|
||||
if pos in house_list:
|
||||
house_list = list(house_list)
|
||||
house_list.remove(pos)
|
||||
successors += ((pos, tuple(house_list)),)
|
||||
house_list = tuple(house_list)
|
||||
|
||||
successors = list(successors)
|
||||
successors.append((pos, tuple(house_list)))
|
||||
successors = tuple(successors)
|
||||
else:
|
||||
successors += ((pos, tuple(house_list)),)
|
||||
successors = list(successors)
|
||||
successors.append((pos, tuple(house_list)))
|
||||
successors = tuple(successors)
|
||||
|
||||
return successors
|
||||
|
||||
|
||||
@ -204,10 +210,11 @@ class Agent:
|
||||
|
||||
explored.add(elem)
|
||||
|
||||
for succ in self.succesor(elem):
|
||||
succs = self.succesor(elem)
|
||||
for succ in succs:
|
||||
|
||||
node = (succ, elem)
|
||||
p = self.heuristic(succ[0], goaltest[0])
|
||||
p = self.heuristic(succ[0], goaltest[0]) + self.weight_cost(elem[0], succ[0])
|
||||
|
||||
if succ not in explored and not any(tup[1][0] == succ for tup in fringe):
|
||||
heapq.heappush(fringe, (p,node))
|
||||
|
Loading…
Reference in New Issue
Block a user