Commit 36bd8c81 authored by Savva Golubitsky's avatar Savva Golubitsky

some code refactor

parent fddbce4c
......@@ -46,7 +46,6 @@ class Edge(object):
self.preprocess = lambda pd: None
self.postprocess = lambda pd: None
self.order = int(0 if order is None else order)
print("Edge:", comment)
self.comment = comment
def predicate(self, data, dynamic_keys_mapping={}):
......
......@@ -59,9 +59,7 @@ class GraphFactory():
return Func(), Func(), comment
pred_f, func_f = Func(), Func()
morph = self.entities[morphname]
print("MORPH:", morph)
for m in morph.__slots__:
print(m, getattr(morph,m))
if getattr(morph,m) is not None:
if m!="predicate" and m!="function" and m!="comment":
raise Exception("ERROR: Morphisms could not have any params exept comment, predicate and function!\n{}".format(morphname))
......@@ -117,9 +115,6 @@ class GraphFactory():
self.states[s].replace_with_graph(subgr)
self.graph = Graph(self.graph.init_state, self.graph.term_state)
for e in self.entities:
if self.entities[e].comment != "":
print("ECOMM:", self.entities[e])
return self.graph
......@@ -191,7 +186,6 @@ class Parser():
m = [m for m in re.finditer(r'\".*\"', props)][0]
comment = props[m.span()[0]+1:m.span()[1]-1]
props=props[:m.span()[0]]+props[m.span()[1]:]
print(props)
props = props.replace("(","")
props = props.replace(")","")
rs =props.split(r",") #.split(r", ")
......@@ -331,7 +325,6 @@ def print_graph(cur_state, entities, bushes):
if len(cur_b.branches)>1 or len(cur_b.incomes)>1:
body+="{}:\n".format(cur_state.name)
if len(cur_b.incomes)!=0:
print("//"+cur_b.state.comment.replace('\0', ' ')+"\n")
if cur_b.state.comment!="":
body+="//"+cur_b.state.comment.replace('\0', ' ')+"\n"
stri = "false "
......@@ -348,37 +341,19 @@ def print_graph(cur_state, entities, bushes):
body+="else {\n\tfor (int seli = 0;"+" seli < {};".format(len(cur_state.transfers))+" seli++)\n"+"\t\tSEL_{}[seli]=true;".format(cur_state.name)+"\n}\n"
for i, br in enumerate(cur_b.branches):
body+="if (SEL_{}[{}])".format(cur_state.name, i)+"{\n"
if br[len(br)-1].out not in tocheck:
tocheck.append(br[len(br)-1].out)
if br[len(br)-1].out in checked or br[len(br)-1].out is cur_state:
for b in br:
if b.morph.name != "":
if b.pred not in toloadpred:
toloadpred.append(b.pred)
if b.morph not in toloadmorph:
toloadmorph.append(b.morph)
print("//"+b.comment)
if b.comment!="":
body+="//{}\n".format(b.comment)
body+="\tcheck_pred({}(data), \"{}\");//{}\n\t{}(data);//{}\n".format(b.pred,b.pred, b.pred.comment, b.morph, b.morph.comment)
body+="\tgoto {};\n".format(br[len(br)-1].out.name)+"}\n"
else:
for b in br:
if b.morph.name != "":
if b.pred not in toloadpred:
toloadpred.append(b.pred)
if b.morph not in toloadmorph:
toloadmorph.append(b.morph)
print("//"+b.comment)
if b.comment!="":
body+="//{}\n".format(b.comment)
body+="\tcheck_pred({}(data), \"{}\");//{}\n\t{}(data);//{}\n".format(b.pred,b.pred, b.pred.comment, b.morph, b.morph.comment)
body+="}\n"
if br[len(br)-1].output_state not in tocheck:
tocheck.append(br[len(br)-1].output_state)
if br[len(br)-1].output_state in checked or br[len(br)-1].output_state is cur_state:
stri, toloadpred, toloadmorph = cur_b.cpp_branch(i, toloadpred, toloadmorph)
body+=stri+"\tgoto {};\n".format(br[len(br)-1].output_state.name)+"}\n"
else:
stri, toloadpred, toloadmorph = cur_b.cpp_branch(i, toloadpred, toloadmorph)
body+=stri+"}\n"
tocheck.remove(cur_state)
checked.append(cur_state)
return unique(toloadpred), unique(toloadmorph), unique(toloadsel), checked, body
return _unique(toloadpred), _unique(toloadmorph), _unique(toloadsel), checked, body
def unique(lst):
def _unique(lst):
for i, el in enumerate(lst):
for el2 in lst[i+1:]:
if el2.module == el.module and el2.name == el.name:
......@@ -389,34 +364,13 @@ def send_token(cur_state, bushes, checked):
cur_b = bushes[cur_state]
if cur_state in checked:
return
# print(cur_b.state.name,len(cur_b.incomes), len(cur_b.outstates), cur_b.state.input_edges_number, cur_b.state.looped_edges_number)
if len(cur_b.outstates)==0:
return
if len(cur_b.incomes) == cur_b.state.input_edges_number - cur_b.state.looped_edges_number:
checked.append(cur_state)
for i,br in enumerate(cur_b.branches):
bushes[br[len(br)-1].out].incomes.append({"st":cur_state, "i":i})
# print(bushes[br[len(br)-1].out].incomes)
send_token(br[len(br)-1].out,bushes, checked)
class _Tr():
slots=(
'pred',
'morph',
'comment',
'out'
)
def __init__(self, transf):
self.pred = transf.edge.pred_f
self.morph = transf.edge.morph_f
self.comment = transf.edge.comment
print("TR:", transf.edge.comment)
self.out = transf.output_state
def __str__(self):
return "{}\n{}\n".format(self.pred, self.morph)
bushes[br[len(br)-1].output_state].incomes.append({"st":cur_state, "i":i})
send_token(br[len(br)-1].output_state,bushes, checked)
class _Bush():
__slots__=(
......@@ -439,20 +393,38 @@ class _Bush():
def grow_bush(self):
for t in self.state.transfers:
branch = [_Tr(t)]
branch = [t]
self._gen_branch(t.output_state, branch)
def _gen_branch(self, cur_state, branch):
# print("generating", cur_state.name)
while len(cur_state.transfers)==1 and cur_state.input_edges_number==1:
if cur_state._proxy_state is not None:
cur_state=cur_state._proxy_state
tr = cur_state.transfers[0]
branch.append(_Tr(tr))
# print("BR:", cur_state.name)
branch.append(tr)
cur_state = tr.output_state
self.branches.append(branch)
if cur_state not in self.outstates:
self.outstates.append(cur_state)
def cpp_branch(self, i, toloadpred, toloadmorph):
res = ""
for tr in self.branches[i]:
edge = tr.edge
if edge.comment!="":
res+="\t//{}\n".format(edge.comment)
if edge.pred_f.name != "":
if edge.pred_f not in toloadpred:
toloadpred.append(edge.pred_f)
res+="\tcheck_pred({}(data), \"{}\");".format(edge.pred_f, edge.pred_f)
res+="//{}\n".format(edge.pred_f.comment) if edge.pred_f.comment != "" else "\n"
if edge.morph_f.name != "":
if edge.morph_f not in toloadmorph:
toloadmorph.append(edge.morph_f)
res+="\t{}(data);".format(edge.morph_f)
res+="//{}\n".format(edge.morph_f.comment) if edge.morph_f.comment != "" else "\n"
return res, toloadpred, toloadmorph
......@@ -57,13 +57,13 @@ int main(int argc, char const *argv[])
std::fill_n(SEL___END__, 0, false);
if (SEL___BEGIN__[0]){
check_pred(test_funcs.simplest_positiveness_predicate(data), "test_funcs.simplest_positiveness_predicate");//
test_funcs.simplest_increment_a_edge(data);//
check_pred(libcomsdk_pass_predicate(data), "libcomsdk_pass_predicate");//
check_pred(test_funcs.simplest_positiveness_predicate(data), "test_funcs.simplest_positiveness_predicate");
test_funcs.simplest_increment_a_edge(data);
check_pred(libcomsdk_pass_predicate(data), "libcomsdk_pass_predicate");
libgcdfes_pso_swarm_init(data);//Инициализация метода роя частиц.
check_pred(libcomsdk_pass_predicate(data), "libcomsdk_pass_predicate");//
check_pred(libcomsdk_pass_predicate(data), "libcomsdk_pass_predicate");
libgcdfes_pso_swarm_init(data);//Инициализация роя частиц.
check_pred(libcomsdk_pass_predicate(data), "libcomsdk_pass_predicate");//
check_pred(libcomsdk_pass_predicate(data), "libcomsdk_pass_predicate");
libgcdfes_pso_agent_init(data);//Инициализация отдельной частицы в рамках метода роя частиц.
}
gcdhom_inverted_model_pso1_S_4:
......@@ -75,9 +75,9 @@ if (!(false || SEL___BEGIN__[0] || SEL_gcdhom_inverted_model_pso1_S_6[0] || SEL_
SEL_gcdhom_inverted_model_pso1_S_4[seli]=true;
}
if (SEL_gcdhom_inverted_model_pso1_S_4[0]){
check_pred(libcomsdk_pass_predicate(data), "libcomsdk_pass_predicate");//
check_pred(libcomsdk_pass_predicate(data), "libcomsdk_pass_predicate");
libgcdfes_pso_task_data_reinit(data);//Реинициализация постановки задачи анализа эффективных характеристик КМ методом асимптотического осреднения.
check_pred(libcomsdk_pass_predicate(data), "libcomsdk_pass_predicate");//
check_pred(libcomsdk_pass_predicate(data), "libcomsdk_pass_predicate");
libgcdfes_pso_hom_agent_postproc(data);//Постпроцессинг после решения отдельной задачи методом асимптотического осреднения.
}
gcdhom_inverted_model_pso1_S_6:
......@@ -89,12 +89,12 @@ if (!(false || SEL_gcdhom_inverted_model_pso1_S_4[0] )){
SEL_gcdhom_inverted_model_pso1_S_6[seli]=true;
}
if (SEL_gcdhom_inverted_model_pso1_S_6[0]){
check_pred(libcomsdk_pass_predicate(data), "libcomsdk_pass_predicate");//
check_pred(libcomsdk_pass_predicate(data), "libcomsdk_pass_predicate");
libgcdfes_pso_agent_reinit(data);//Реинициализация отдельной частицы (смещение частицы) в рое в рамках метода роя частиц.
goto gcdhom_inverted_model_pso1_S_4;
}
if (SEL_gcdhom_inverted_model_pso1_S_6[1]){
check_pred(libcomsdk_pass_predicate(data), "libcomsdk_pass_predicate");//
check_pred(libcomsdk_pass_predicate(data), "libcomsdk_pass_predicate");
libgcdfes_pso_swarm_analysing(data);//Анализ всего роя частиц в рамках метода роя частиц.
}
gcdhom_inverted_model_pso1_S_7:
......@@ -106,14 +106,14 @@ if (!(false || SEL_gcdhom_inverted_model_pso1_S_6[1] )){
SEL_gcdhom_inverted_model_pso1_S_7[seli]=true;
}
if (SEL_gcdhom_inverted_model_pso1_S_7[0]){
check_pred(libcomsdk_pass_predicate(data), "libcomsdk_pass_predicate");//
check_pred(libcomsdk_pass_predicate(data), "libcomsdk_pass_predicate");
libgcdfes_pso_swarm_reinit(data);//Реинициализация всего роя частиц в рамках метода роя частиц.
goto gcdhom_inverted_model_pso1_S_4;
}
if (SEL_gcdhom_inverted_model_pso1_S_7[1]){
//ПАСС, морфизм.
check_pred(libcomsdk_pass_predicate(data), "libcomsdk_pass_predicate");//
libcomsdk_pass_processor(data);//
//ПАСС, морфизм.
check_pred(libcomsdk_pass_predicate(data), "libcomsdk_pass_predicate");
libcomsdk_pass_processor(data);
}
if (!(false || SEL_gcdhom_inverted_model_pso1_S_7[1] )){
for (int seli = 0; seli < 0; seli++)
......
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