-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Hierarchical #943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Hierarchical #943
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a0cbf28
created notebooks for GraphPlan, Total Order Planner and Partial Orde…
MariannaSpyrakou a1f091c
Added hierarchical search and tests
MariannaSpyrakou 24125e2
Created notebook planning_hierarchical_search.ipynb
MariannaSpyrakou 89b4589
Added making progress and tests, minor changes in decompose
MariannaSpyrakou 44d6503
image for planning_hierarchical_search.ipynb
MariannaSpyrakou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1308,27 +1308,23 @@ def hierarchical_search(problem, hierarchy): | |
The problem is a real-world problem defined by the problem class, and the hierarchy is | ||
a dictionary of HLA - refinements (see refinements generator for details) | ||
""" | ||
act = Node(problem.actions[0]) | ||
act = Node(problem.init, None, [problem.actions[0]]) | ||
frontier = deque() | ||
frontier.append(act) | ||
while True: | ||
if not frontier: | ||
return None | ||
plan = frontier.popleft() | ||
print(plan.state.name) | ||
hla = plan.state # first_or_null(plan) | ||
prefix = None | ||
if plan.parent: | ||
prefix = plan.parent.state.action # prefix, suffix = subseq(plan.state, hla) | ||
outcome = Problem.result(problem, prefix) | ||
if hla is None: | ||
(hla, index) = Problem.find_hla(plan, hierarchy) # finds the first non primitive hla in plan actions | ||
prefix = plan.action[:index] | ||
outcome = Problem(Problem.result(problem.init, prefix), problem.goals , problem.actions ) | ||
suffix = plan.action[index+1:] | ||
if not hla: # hla is None and plan is primitive | ||
if outcome.goal_test(): | ||
return plan.path() | ||
return plan.action | ||
else: | ||
print("else") | ||
for sequence in Problem.refinements(hla, outcome, hierarchy): | ||
print("...") | ||
frontier.append(Node(plan.state, plan.parent, sequence)) | ||
for sequence in Problem.refinements(hla, outcome, hierarchy): # find refinements | ||
frontier.append(Node(outcome.init, plan, prefix + sequence+ suffix)) | ||
|
||
def result(state, actions): | ||
"""The outcome of applying an action to the current problem""" | ||
|
@@ -1365,12 +1361,12 @@ def angelic_search(problem, hierarchy, initialPlan): | |
if Problem.is_primitive( plan, hierarchy ): | ||
return ([x for x in plan.action]) | ||
guaranteed = problem.intersects_goal(pes_reachable_set) | ||
if guaranteed and Problem.making_progress(plan, plan): | ||
if guaranteed and Problem.making_progress(plan, initialPlan): | ||
final_state = guaranteed[0] # any element of guaranteed | ||
#print('decompose') | ||
return Problem.decompose(hierarchy, problem, plan, final_state, pes_reachable_set) | ||
(hla, index) = Problem.find_hla(plan, hierarchy) # there should be at least one HLA/Angelic_HLA, otherwise plan would be primitive. | ||
prefix = plan.action[:index-1] | ||
prefix = plan.action[:index] | ||
suffix = plan.action[index+1:] | ||
outcome = Problem(Problem.result(problem.init, prefix), problem.goals , problem.actions ) | ||
for sequence in Problem.refinements(hla, outcome, hierarchy): # find refinements | ||
|
@@ -1450,30 +1446,33 @@ def find_hla(plan, hierarchy): | |
|
||
def making_progress(plan, initialPlan): | ||
""" | ||
Not correct | ||
Prevents from infinite regression of refinements | ||
|
||
Normally should from infinite regression of refinements | ||
|
||
Only case covered: when plan contains one action (then there is no regression to be done) | ||
(infinite regression of refinements happens when the algorithm finds a plan that | ||
its pessimistic reachable set intersects the goal inside a call to decompose on the same plan, in the same circumstances) | ||
""" | ||
if (len(plan.action)==1): | ||
return False | ||
for i in range(len(initialPlan)): | ||
if (plan == initialPlan[i]): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is better than the previous version, but I'm not sure if this is sufficient. |
||
return False | ||
return True | ||
|
||
def decompose(hierarchy, s_0, plan, s_f, reachable_set): | ||
solution = [] | ||
i = max(reachable_set.keys()) | ||
while plan.action_pes: | ||
action = plan.action_pes.pop() | ||
i = max(reachable_set.keys()) | ||
if (i==0): | ||
return solution | ||
s_i = Problem.find_previous_state(s_f, reachable_set,i, action) | ||
problem = Problem(s_i, s_f , plan.action) | ||
j=0 | ||
for x in Problem.angelic_search(problem, hierarchy, [Angelic_Node(s_i, Node(None), [action],[action])]): | ||
solution.insert(j,x) | ||
j+=1 | ||
angelic_call = Problem.angelic_search(problem, hierarchy, [Angelic_Node(s_i, Node(None), [action],[action])]) | ||
if angelic_call: | ||
for x in angelic_call: | ||
solution.insert(0,x) | ||
else: | ||
return None | ||
s_f = s_i | ||
i-=1 | ||
return solution | ||
|
||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!