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):
|
def get_start_state(self):
|
||||||
entities = self.simulation.state.entities
|
entities = self.simulation.state.entities
|
||||||
for entity in entities:
|
# orientation - self.orientation
|
||||||
if entity.entity_type == 'truck':
|
|
||||||
orientation = entity.orientation
|
|
||||||
position = self.current_pos
|
position = self.current_pos
|
||||||
house_list = tuple(self.houses)
|
house_list = tuple(self.houses)
|
||||||
start_state = (position, house_list)
|
start_state = (position, house_list)
|
||||||
@ -169,14 +167,22 @@ class Agent:
|
|||||||
|
|
||||||
def succesor(self, state):
|
def succesor(self, state):
|
||||||
successors_pos = self.graph[state[0]]
|
successors_pos = self.graph[state[0]]
|
||||||
house_list = [state[1]]
|
house_list = state[1]
|
||||||
successors = ()
|
successors = ()
|
||||||
for pos in successors_pos:
|
for pos in successors_pos:
|
||||||
if pos in house_list:
|
if pos in house_list:
|
||||||
|
house_list = list(house_list)
|
||||||
house_list.remove(pos)
|
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:
|
else:
|
||||||
successors += ((pos, tuple(house_list)),)
|
successors = list(successors)
|
||||||
|
successors.append((pos, tuple(house_list)))
|
||||||
|
successors = tuple(successors)
|
||||||
|
|
||||||
return successors
|
return successors
|
||||||
|
|
||||||
|
|
||||||
@ -204,10 +210,11 @@ class Agent:
|
|||||||
|
|
||||||
explored.add(elem)
|
explored.add(elem)
|
||||||
|
|
||||||
for succ in self.succesor(elem):
|
succs = self.succesor(elem)
|
||||||
|
for succ in succs:
|
||||||
|
|
||||||
node = (succ, elem)
|
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):
|
if succ not in explored and not any(tup[1][0] == succ for tup in fringe):
|
||||||
heapq.heappush(fringe, (p,node))
|
heapq.heappush(fringe, (p,node))
|
||||||
|
Loading…
Reference in New Issue
Block a user