Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 55cc39d

Browse files
MariannaSpyrakoudelaray
authored andcommitted
Hierarchical (#943)
* created notebooks for GraphPlan, Total Order Planner and Partial Order Planner * Added hierarchical search and tests * Created notebook planning_hierarchical_search.ipynb * Added making progress and tests, minor changes in decompose * image for planning_hierarchical_search.ipynb
1 parent 1c4d322 commit 55cc39d

9 files changed

+3601
-2475
lines changed

images/refinement.png

61.6 KB
Loading

planning.ipynb

Lines changed: 386 additions & 2427 deletions
Large diffs are not rendered by default.

planning.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,27 +1308,23 @@ def hierarchical_search(problem, hierarchy):
13081308
The problem is a real-world problem defined by the problem class, and the hierarchy is
13091309
a dictionary of HLA - refinements (see refinements generator for details)
13101310
"""
1311-
act = Node(problem.actions[0])
1311+
act = Node(problem.init, None, [problem.actions[0]])
13121312
frontier = deque()
13131313
frontier.append(act)
13141314
while True:
13151315
if not frontier:
13161316
return None
13171317
plan = frontier.popleft()
1318-
print(plan.state.name)
1319-
hla = plan.state # first_or_null(plan)
1320-
prefix = None
1321-
if plan.parent:
1322-
prefix = plan.parent.state.action # prefix, suffix = subseq(plan.state, hla)
1323-
outcome = Problem.result(problem, prefix)
1324-
if hla is None:
1318+
(hla, index) = Problem.find_hla(plan, hierarchy) # finds the first non primitive hla in plan actions
1319+
prefix = plan.action[:index]
1320+
outcome = Problem(Problem.result(problem.init, prefix), problem.goals , problem.actions )
1321+
suffix = plan.action[index+1:]
1322+
if not hla: # hla is None and plan is primitive
13251323
if outcome.goal_test():
1326-
return plan.path()
1324+
return plan.action
13271325
else:
1328-
print("else")
1329-
for sequence in Problem.refinements(hla, outcome, hierarchy):
1330-
print("...")
1331-
frontier.append(Node(plan.state, plan.parent, sequence))
1326+
for sequence in Problem.refinements(hla, outcome, hierarchy): # find refinements
1327+
frontier.append(Node(outcome.init, plan, prefix + sequence+ suffix))
13321328

13331329
def result(state, actions):
13341330
"""The outcome of applying an action to the current problem"""
@@ -1365,12 +1361,12 @@ def angelic_search(problem, hierarchy, initialPlan):
13651361
if Problem.is_primitive( plan, hierarchy ):
13661362
return ([x for x in plan.action])
13671363
guaranteed = problem.intersects_goal(pes_reachable_set)
1368-
if guaranteed and Problem.making_progress(plan, plan):
1364+
if guaranteed and Problem.making_progress(plan, initialPlan):
13691365
final_state = guaranteed[0] # any element of guaranteed
13701366
#print('decompose')
13711367
return Problem.decompose(hierarchy, problem, plan, final_state, pes_reachable_set)
13721368
(hla, index) = Problem.find_hla(plan, hierarchy) # there should be at least one HLA/Angelic_HLA, otherwise plan would be primitive.
1373-
prefix = plan.action[:index-1]
1369+
prefix = plan.action[:index]
13741370
suffix = plan.action[index+1:]
13751371
outcome = Problem(Problem.result(problem.init, prefix), problem.goals , problem.actions )
13761372
for sequence in Problem.refinements(hla, outcome, hierarchy): # find refinements
@@ -1450,30 +1446,33 @@ def find_hla(plan, hierarchy):
14501446

14511447
def making_progress(plan, initialPlan):
14521448
"""
1453-
Not correct
1449+
Prevents from infinite regression of refinements
14541450
1455-
Normally should from infinite regression of refinements
1456-
1457-
Only case covered: when plan contains one action (then there is no regression to be done)
1451+
(infinite regression of refinements happens when the algorithm finds a plan that
1452+
its pessimistic reachable set intersects the goal inside a call to decompose on the same plan, in the same circumstances)
14581453
"""
1459-
if (len(plan.action)==1):
1460-
return False
1454+
for i in range(len(initialPlan)):
1455+
if (plan == initialPlan[i]):
1456+
return False
14611457
return True
14621458

14631459
def decompose(hierarchy, s_0, plan, s_f, reachable_set):
14641460
solution = []
1461+
i = max(reachable_set.keys())
14651462
while plan.action_pes:
14661463
action = plan.action_pes.pop()
1467-
i = max(reachable_set.keys())
14681464
if (i==0):
14691465
return solution
14701466
s_i = Problem.find_previous_state(s_f, reachable_set,i, action)
14711467
problem = Problem(s_i, s_f , plan.action)
1472-
j=0
1473-
for x in Problem.angelic_search(problem, hierarchy, [Angelic_Node(s_i, Node(None), [action],[action])]):
1474-
solution.insert(j,x)
1475-
j+=1
1468+
angelic_call = Problem.angelic_search(problem, hierarchy, [Angelic_Node(s_i, Node(None), [action],[action])])
1469+
if angelic_call:
1470+
for x in angelic_call:
1471+
solution.insert(0,x)
1472+
else:
1473+
return None
14761474
s_f = s_i
1475+
i-=1
14771476
return solution
14781477

14791478

0 commit comments

Comments
 (0)