Commit 64ac347a authored by Savva Golubitsky's avatar Savva Golubitsky

generation of simple graph, Bug spotted

parent 36839f25
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -60,10 +60,19 @@ class Edge(object):
def morph(self, data, dynamic_keys_mapping={}):
# print(self.pred_name, self.morph_name, self.order)
proxy_data = self._io_mapping.build_proxy_data(data, dynamic_keys_mapping)
#print(proxy_data)
# print(proxy_data)
self.preprocess(data)
self._morphism(proxy_data)
self.postprocess(data)
def __str__(self):
out = ""
if not (self.pred_module =="" or self.pred_name ==""):
out += "{}::{}(data);\n".format(self.pred_module, self.pred_name)
if not (self.morph_module =="" or self.morph_name ==""):
out += "{}::{}(data);\n".format(self.morph_module, self.morph_name)
return out
# class DummyEdge(Edge):
# def __init__(self):
......
......@@ -116,7 +116,15 @@ class Graph:
data['__WORKING_DIR__'] = data['__CURRENT_WORKING_DIR__']
def generate_cpp(self):
pass
cur_state = self.init_state
while True:
if len(cur_state.transfers)==1:
print(cur_state.transfers[0].edge)
cur_state = cur_state.transfers[0].output_state
if cur_state is None:
break
else:
break
......@@ -170,13 +178,9 @@ class State:
return # no need to go further if we already were there
if self._branching_states_history is None:
self._branching_states_history = branching_states_history
print(self.name,": \t", self.input_edges_number, len(self.transfers))
print(self._branching_states_history)
elif idle_run_type == IdleRunType.CLEANUP:
self.activated_input_edges_number = 0
# print('\tCLEANUP STATE {}, active: {}, branches_story: {}'.format(self.name, self.activated_input_edges_number, self._branching_states_history))
if self._branching_states_history is not None and self._is_looped_branch(branching_states_history):
# print('\tqwer')
self._branching_states_history = None
return
if self._branching_states_history is None:
......@@ -280,12 +284,6 @@ class State:
def _has_loop(self):
return self.looped_edges_number != 0
def generate_cpp(self):
ststr = "{}:\n\t".format(self.name)
if len(self.transfers)==1:
print("{}(data);\n{}(data);".format(t.edge.pred_name, t.edge.morph.name))
return
def transfer_to_termination(data):
return None
......
......@@ -85,12 +85,12 @@ class GraphFactory():
self.states[st1].connect_to(self.states[st2], edge=Edge(pred, entr, order=ordr))
print("{} -> {}".format(st1, st2))
def build(self):
def build(self, nsub):
print("BUILDING {}\nStates:".format(self.name))
for s in self.states:
print("\t"+ s)
if self.issub:
self.graph = Graph(self.states[self.name+"_"+"__BEGIN__"], self.states[self.name+"_"+"__END__"])
self.graph = Graph(self.states[self.name+str(nsub)+"_"+"__BEGIN__"], self.states[self.name+str(nsub)+"_"+"__END__"])
else:
self.graph = Graph(self.states["__BEGIN__"], self.states["__END__"])
self.graph.init_graph()
......@@ -108,7 +108,6 @@ class GraphFactory():
parsr = Parser(subgraph=True)
subgr = parsr.parse_file(self.entities[s].subgraph)
self.states[s].replace_with_graph(subgr)
self.graph.init_graph()
return self.graph
class Parser():
......@@ -117,11 +116,13 @@ class Parser():
'fact',
'issub'
)
subgr_count = 0
def __init__(self, tocpp=False, subgraph=False):
self.fact = GraphFactory(tocpp=tocpp)
self.fact.issub = subgraph
self.issub = subgraph
if subgraph:
Parser.subgr_count+=1
def _check_brackets(self, rawfile):
br = 0
......@@ -185,8 +186,7 @@ class Parser():
if r[0] in parm.__slots__:
setattr(parm, r[0], r[1])
else:
print("\tERROR:Unknown parameter: "+ r[0])
exit(-1)
raise Exception("\tERROR:Unknown parameter: "+ r[0])
return parm
def _param_from_entln(self, raw):
......@@ -207,9 +207,9 @@ class Parser():
right = spl[2].split(",")
if self.issub:
for i in range(len(left)):
left[i] = self.fact.name + "_" + left[i]
left[i] = self.fact.name + str(Parser.subgr_count) + "_" + left[i]
for i in range(len(right)):
right[i] = self.fact.name + "_" + right[i]
right[i] = self.fact.name + str(Parser.subgr_count) + "_" + right[i]
if (len(left)>1) and (len(right)>1):
raise Exception("ERROR: Ambigious multiple connection in line:\n\t{}".format(raw))
# many to one conection
......@@ -279,5 +279,5 @@ class Parser():
self.fact.entities[name] = parm
elif top_re.match(ln):
self._topology(ln)
return self.fact.build()
return self.fact.build(Parser.subgr_count)
......@@ -9,22 +9,40 @@ from comsdk.graph import *
from comsdk.edge import Edge
prsr = pars.Parser()
print(prsr.fact.tocpp)
graph = prsr.parse_file('./tests/adot/testparal.adot')
# s_1 = State('cycled_s_1')
# s_2 = State('cycled_s_2')
# s_3 = State('cycled_s_3')
# s_1.connect_to(s_2, edge=Edge(Func(),Func(func=increment_a_edge)))
# s_2.connect_to(s_3, edge=Edge(Func(func=positiveness_predicate), Func(func=increment_a_edge)))
# s_2.connect_to(s_1, edge=Edge(Func(func=positiveness_predicate), Func(func=increment_a_edge)))
#
# graph = Graph(s_1, s_2)
graph = prsr.parse_file('./tests/adot/testsimple.adot')
data = {"a":1, "b":1}
# graph.generate_cpp()
graph.run(data)
print(data)
print(graph.generate_cpp())
# root = State('root')
# br2 = State('br2')
# br3 = State('br3')
# br2_sibl1 = State('br3_sibl1')
# br2_sibl2 = State('br3_sibl2')
# br3_sibl1 = State('br3_sibl1')
# br3_sibl2 = State('br3_sibl2')
# end = State('end')
#
# root.connect_to(br2, edge=Edge(Func(func=positiveness_predicate), Func(func=increment_a_edge)))
# root.connect_to(br3, edge=Edge(Func(func=positiveness_predicate), Func(func=increment_a_edge)))
# br3.connect_to(br3_sibl1, edge=Edge(Func(func=positiveness_predicate), Func(func=increment_a_edge)))
# br3.connect_to(br3_sibl2, edge=Edge(Func(func=positiveness_predicate), Func(func=increment_a_edge)))
# br2.connect_to(br2_sibl1, edge=Edge(Func(func=positiveness_predicate), Func(func=increment_a_edge)))
# br2.connect_to(br2_sibl2, edge=Edge(Func(func=positiveness_predicate), Func(func=increment_a_edge)))
# br3_sibl1.connect_to(end, edge=Edge(Func(func=positiveness_predicate), Func(func=increment_a_edge)))
# br3_sibl2.connect_to(end, edge=Edge(Func(func=positiveness_predicate), Func(func=increment_a_edge)))
# br2_sibl1.connect_to(end, edge=Edge(Func(func=positiveness_predicate), Func(func=increment_a_edge)))
# br2_sibl2.connect_to(end, edge=Edge(Func(func=positiveness_predicate), Func(func=increment_a_edge)))
#
# graph = Graph(root, end)
# data = {"a":1, "b":1}
# graph.run(data)
#
# print(data)
No preview for this file type
digraph SIMPLEST {
digraph CYCLED {
FUNC [module=test_funcs.simplest, entry_func=decrement_a_edge]
PRED [module=test_funcs.simplest, entry_func=positiveness_predicate]
MORPH [predicate=PRED, function=FUNC]
......@@ -9,6 +9,6 @@ digraph SIMPLEST {
__BEGIN__ -> ST1
ST1 -> ST2 [morphism=MORPH]
ST2 -> ST1
ST2 -> ST1 [morphism=MORPH]
ST2 -> __END__
}
\ No newline at end of file
......@@ -6,11 +6,11 @@ digraph SIMPLEST {
INCR_B [predicate=PRED, function=FUNCB]
__BEGIN__ -> ST2
ST2 -> ST3_1, ST3_2 [morphism=(INCR_A, INCR_B)]
ST3_1 -> ST3_1_1, ST3_1_2 [morphism=(INCR_A, INCR_B)]
ST3_2 -> ST3_2_1, ST3_2_2 [morphism=(INCR_A, INCR_B)]
//ST3_1_1 -> ST3_1_1_1, ST3_1_1_2
ST3_1_1, ST3_1_2, ST3_2_1, ST3_2_2 -> ST_TERM [morphism=(INCR_A, INCR_B, INCR_A, INCR_B)]
ST_TERM -> __END__
}
\ No newline at end of file
__BEGIN__ -> ROOT
ROOT -> BR1, BR2, BR3 [morphism=(INCR_A, INCR_A, INCR_A)]
BR3 -> SIBL3_BR1, SIBL3_BR2 [morphism=(INCR_A, INCR_A)]
BR2 -> SIBL2_BR1, SIBL2_BR2 [morphism=(INCR_A, INCR_A)]
SIBL3_BR1 -> SIBL3_BR1_1, SIBL3_BR1_2 [morphism=(INCR_A, INCR_A)]
SIBL3_BR1_1, SIBL3_BR1_2 -> TERM [morphism=(INCR_A, INCR_A)]
BR1, SIBL2_BR1, SIBL2_BR2, TERM, SIBL3_BR2 -> __END__ [morphism=(INCR_A, INCR_A, INCR_A, INCR_A, INCR_A)]
}
\ No newline at end of file
digraph SIMPLE {
FUNC [module=test_funcs.simplest, entry_func=increment_a_edge]
PRED [module=test_funcs.simplest, entry_func=positiveness_predicate]
MORPH [predicate=PRED, function=FUNC]
__BEGIN__ -> ST1 [morphism = MORPH]
ST1 -> ST2 [morphism = MORPH]
ST2 -> ST3[morphism = MORPH]
ST3 -> ST4[morphism = MORPH]
ST4 -> __END__
}
\ No newline at end of file
digraph TEST_SUB {
FUNC [module=test_funcs.simplest, entry_func=decrement_a_edge]
FUNC [module=test_funcs.simplest, entry_func=increment_a_edge]
PRED [module=test_funcs.simplest, entry_func=positiveness_predicate]
MORPH [predicate=PRED, function=FUNC]
ST2 [subgraph = tests/adot/add.dot]
ST2 [subgraph = tests/adot/add.adot]
__BEGIN__ -> ST1
ST1 -> ST2 [morphism=MORPH]
ST2 -> __END
ST2 -> __END__
}
\ No newline at end of file
......@@ -230,24 +230,30 @@ class GraphGoodCheck(unittest.TestCase):
def _get_trivial_parallel_graph(self, initial_conditions):
'''
s_1 -> s_2 -> s_3 -> s_6
-> s_4 -> s_5 ->
s_1 -> s_2 -> s_3 ---------> s6s
-> s_4 -> s_4_1 -> s_5
-> s_4_2
p_12 = p_24 = p_13 = p_34 := a not 0
f_12 = f_24 := a + 1
f_13 = f_34 := b + 1
'''
s_1 = State('nonparallel_s_1', selection_policy=AllSelectionPolicy())
s_1 = State('nonparallel_s_1')
s_2 = State('parallel_s_2')
s_3 = State('parallel_s_3')
s_4 = State('parallel_s_4')
s_4_1 = State('parallel_s_4_1')
s_4_2 = State('parallel_s_4_2')
s_5 = State('parallel_s_5')
s_6 = State('nonparallel_s_6')
s_1.connect_to(s_2, edge=Edge(nonzero_predicate, increment_a_edge))
s_2.connect_to(s_3, edge=Edge(nonzero_predicate, increment_a_edge))
s_3.connect_to(s_6, edge=Edge(nonzero_predicate, increment_a_edge))
s_1.connect_to(s_4, edge=Edge(nonzero_predicate, increment_b_edge))
s_4.connect_to(s_5, edge=Edge(nonzero_predicate, increment_b_edge))
s_4.connect_to(s_4_1, edge=Edge(nonzero_predicate, increment_b_edge))
s_4.connect_to(s_4_2, edge=Edge(nonzero_predicate, increment_b_edge))
s_4_1.connect_to(s_5, edge=Edge(nonzero_predicate, increment_b_edge))
s_4_2.connect_to(s_6, edge=Edge(nonzero_predicate, increment_b_edge))
s_5.connect_to(s_6, edge=Edge(nonzero_predicate, increment_b_edge))
correct_outputs = []
for ic in initial_conditions:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment