-
Notifications
You must be signed in to change notification settings - Fork 6
Full state space enumeration #189
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
Draft
haz
wants to merge
29
commits into
AI-Planning:main
Choose a base branch
from
seeratparmar:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 19 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
ed5e025
Create graph_enum.py
seeratparmar 3fc82bb
Delete graph_enum.py
seeratparmar 164a10e
Create graph_enum.py
seeratparmar d7e7d23
Update graph_enum.py
seeratparmar fd837a3
Update graph_enum.py
seeratparmar 5eabf87
Update graph_enum.py
seeratparmar e762a10
excess code removed
seeratparmar f6fb872
Update graph_enumuation.py
seeratparmar f1a5f83
Update graph_enumuation.py
seeratparmar 0fe2977
Update dot
seeratparmar 492e4c3
Update graph_enumeration
seeratparmar b08346a
Update graph_enumeration
seeratparmar 625e452
Update graph_enumeration.py
seeratparmar e4b3d2d
Update graph_enumeration.py
seeratparmar 754f258
Delete k1.dot
haz d17b95e
Update graph_enum
seeratparmar 2f99bda
Merge branch 'main' of https://github.com/seeratparmar/macq
seeratparmar 0b544c2
Update graph_enumeration.py
seeratparmar 75914c3
Update graph_enumeration.py
seeratparmar e1139be
Update macq/generate/pddl/vanilla_sampling.py
haz d2b3ffb
Adding access to the new enumerator on import paths.
haz 5664b67
Store the computed graph for future access
haz ef17664
create bglearner
seeratparmar e5d004d
Update bglearner.py
seeratparmar 51f1c3b
Update bglearner.py
seeratparmar d1a25c8
Update bglearner.py
seeratparmar 0aad8fc
Update bglearner.py
seeratparmar b967d62
Update bglearner.py
seeratparmar db6a096
Update bglearner.py
seeratparmar 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
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 |
---|---|---|
|
@@ -16,4 +16,5 @@ test_model.json | |
results.txt | ||
html/ | ||
|
||
*.dot | ||
*.DS_Store |
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 |
---|---|---|
@@ -0,0 +1,120 @@ | ||
from tarski.search.operations import progress | ||
import networkx as nx | ||
from macq.generate.pddl import Generator | ||
import math | ||
from macq.trace import ( | ||
State, | ||
Trace, | ||
Action, | ||
TraceList, | ||
Step, | ||
) | ||
|
||
|
||
class StateEnumerator(Generator): | ||
|
||
"""State Enumerator - inherits the base Generator class and its attributes. | ||
|
||
A trace generator that generates traces of length 2 from a graph where nodes are the states and the edges represent the applicable actions | ||
|
||
Attributes: | ||
num_nodes (int): | ||
The number of nodes to be generated in the state space. | ||
traces (TraceList): | ||
The list of traces generated. | ||
dom (str): | ||
Describes the problem domain | ||
prob (str): | ||
Describes the problem | ||
""" | ||
def __init__( | ||
self, | ||
dom: str = None, | ||
prob: str = None, | ||
problem_id: int = None, | ||
num_nodes: int = math.inf, | ||
|
||
): | ||
super().__init__( | ||
dom=dom, | ||
prob=prob, | ||
problem_id=problem_id, | ||
) | ||
|
||
self.num_nodes = num_nodes | ||
if num_nodes > 0: | ||
self.traces = self.generate_traces() | ||
else: | ||
self.traces = None | ||
|
||
|
||
|
||
def generate_traces(self): | ||
"""Generates n traces of length 2 using the graph generated | ||
where n= num_nodes or for all the possible states if num_nodes is not defined | ||
|
||
Returns: | ||
A TraceList object with the list of traces generated. | ||
""" | ||
traces = TraceList() | ||
|
||
graph= self.generate_graph() | ||
|
||
#act is a dictionary with key='label' of the form {'label': action} | ||
for cur_state, next_state, act in graph.edges(data=True): | ||
trace = Trace() | ||
|
||
macq_action = self.tarski_act_to_macq(act['label']) | ||
macq_cur_state = self.tarski_state_to_macq(cur_state) | ||
macq_next_state = self.tarski_state_to_macq(next_state) | ||
step = Step(macq_cur_state, macq_action,1) | ||
trace.append(step) | ||
|
||
step = Step(state=macq_next_state, action=None, index=2) | ||
trace.append(step) | ||
traces.append(trace) | ||
|
||
self.traces = traces | ||
return traces | ||
|
||
def generate_graph(self): | ||
"""Generates a networkx strictly directed graph for the given problem by expanding the tree using bfs. | ||
|
||
Queue[]= Keeps track of all the nodes to be explored | ||
Visited{node: Bool}= Keeps track of the explored nodes | ||
|
||
Returns: | ||
A networkx graph with nodes representing states and edges describing the reachable states and action. | ||
|
||
""" | ||
G=nx.DiGraph() | ||
state = self.problem.init #initial state/ root node | ||
G.add_node(state) | ||
Visited={ } | ||
Queue= [state] | ||
|
||
Visited[state]=True | ||
while Queue: | ||
cur_node = Queue.pop(0) | ||
app_act = list(self.instance.applicable(cur_node)) | ||
for act in app_act: | ||
|
||
#creating new node if it doesn't exist in Visited as all the nodes are added to Visited with bool T/F | ||
next_state = progress(cur_node, act) | ||
if next_state not in Visited: | ||
if self.num_nodes>1: | ||
G.add_node(next_state) | ||
Visited[next_state]=False | ||
self.num_nodes-= 1 | ||
else: | ||
return G | ||
G.add_edge(cur_node,next_state, label= act) | ||
|
||
#adding node to queue if it hasn't been explored | ||
for node in G.neighbors(cur_node): | ||
if (Visited[node]==False): | ||
Queue.append(node) | ||
Visited[node]=True | ||
return G | ||
|
||
|
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
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.
Uh oh!
There was an error while loading. Please reload this page.