Skip to content
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

Full state space enumeration #189

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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 Jul 24, 2022
3fc82bb
Delete graph_enum.py
seeratparmar Jul 24, 2022
164a10e
Create graph_enum.py
seeratparmar Jul 26, 2022
d7e7d23
Update graph_enum.py
seeratparmar Jul 26, 2022
fd837a3
Update graph_enum.py
seeratparmar Jul 26, 2022
5eabf87
Update graph_enum.py
seeratparmar Jul 26, 2022
e762a10
excess code removed
seeratparmar Jul 26, 2022
f6fb872
Update graph_enumuation.py
seeratparmar Jul 26, 2022
f1a5f83
Update graph_enumuation.py
seeratparmar Jul 26, 2022
0fe2977
Update dot
seeratparmar Jul 27, 2022
492e4c3
Update graph_enumeration
seeratparmar Jul 27, 2022
b08346a
Update graph_enumeration
seeratparmar Aug 4, 2022
625e452
Update graph_enumeration.py
seeratparmar Aug 4, 2022
e4b3d2d
Update graph_enumeration.py
seeratparmar Aug 4, 2022
754f258
Delete k1.dot
haz Aug 5, 2022
d17b95e
Update graph_enum
seeratparmar Aug 8, 2022
2f99bda
Merge branch 'main' of https://github.com/seeratparmar/macq
seeratparmar Aug 8, 2022
0b544c2
Update graph_enumeration.py
seeratparmar Aug 8, 2022
75914c3
Update graph_enumeration.py
seeratparmar Aug 8, 2022
e1139be
Update macq/generate/pddl/vanilla_sampling.py
haz Aug 9, 2022
d2b3ffb
Adding access to the new enumerator on import paths.
haz Aug 9, 2022
5664b67
Store the computed graph for future access
haz Aug 9, 2022
ef17664
create bglearner
seeratparmar Aug 18, 2022
e5d004d
Update bglearner.py
seeratparmar Sep 5, 2022
51f1c3b
Update bglearner.py
seeratparmar Sep 7, 2022
d1a25c8
Update bglearner.py
seeratparmar Sep 7, 2022
0aad8fc
Update bglearner.py
seeratparmar Sep 8, 2022
b967d62
Update bglearner.py
seeratparmar Sep 8, 2022
db6a096
Update bglearner.py
seeratparmar Sep 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ test_model.json
results.txt
html/

*.dot
*.DS_Store
120 changes: 120 additions & 0 deletions macq/generate/pddl/graph_enumeration.py
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


1 change: 1 addition & 0 deletions macq/generate/pddl/vanilla_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def __init__(
random.seed(seed)
self.max_time = max_time
self.plan_len = set_plan_length(plan_len)

haz marked this conversation as resolved.
Show resolved Hide resolved
self.num_traces = set_num_traces(num_traces)
if self.num_traces > 0:
self.traces = self.generate_traces()
Expand Down