Skip to content

Commit d114913

Browse files
author
Volker Waurich
committed
- dump graphML after resolvingLoops
- resolve paths which connect 2 simple loops - bugfix for sortPaths git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19232 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 55d0791 commit d114913

File tree

1 file changed

+87
-27
lines changed

1 file changed

+87
-27
lines changed

Compiler/BackEnd/BackendDAEOptimize.mo

Lines changed: 87 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7067,7 +7067,7 @@ protected
70677067
list<list<Integer>> partitions, loops;
70687068
BackendDAE.Variables vars,simpVars;
70697069
BackendDAE.EquationArray eqs,simpEqs;
7070-
BackendDAE.IncidenceMatrix m,mT,m_cut, mT_cut;
7070+
BackendDAE.IncidenceMatrix m,mT,m_cut, mT_cut, m_after, mT_after;
70717071
BackendDAE.Matching matching;
70727072
BackendDAE.StateSets stateSets;
70737073
list<DAE.ComponentRef> crefs;
@@ -7107,7 +7107,7 @@ algorithm
71077107
//partition graph
71087108
partitions := arrayList(partitionBipartiteGraph(m,mT));
71097109
partitions := List.filterOnTrue(partitions,List.hasSeveralElements);
7110-
//print("the partitions: \n"+&stringDelimitList(List.map(partitions,HpcOmTaskGraph.intLstString),"\n")+&"\n");
7110+
//print("the partitions: \n"+&stringDelimitList(List.map(partitions,HpcOmTaskGraph.intLstString),"\n")+&"\n");
71117111

71127112
// cut the deadends (vars and eqs outside of the loops)
71137113
m_cut := arrayCopy(m);
@@ -7120,6 +7120,16 @@ algorithm
71207120
eqs := BackendEquation.listEquation(eqLst);
71217121
//BackendDump.dumpEquationList(eqLst,"the complete DAE after resolving");
71227122

7123+
// get the graphML for the resolved System
7124+
simpEqLst := List.map1(eqMapping,List.getIndexFirst,eqLst);
7125+
simpEqs := BackendEquation.listEquation(simpEqLst);
7126+
numSimpEqs := listLength(simpEqLst);
7127+
numVars := listLength(simpVarLst);
7128+
m_after := arrayCreate(numSimpEqs, {});
7129+
mT_after := arrayCreate(numVars, {});
7130+
(m_after,mT_after) := BackendDAEUtil.incidenceMatrixDispatch(simpVars,simpEqs,{},mT, 0, numSimpEqs, intLt(0, numSimpEqs), BackendDAE.ABSOLUTE(), NONE());
7131+
HpcOmEqSystems.dumpEquationSystemGraphML1(simpVars,simpEqs,m_after,"rL_after");
7132+
71237133
eqSysOut := BackendDAE.EQSYSTEM(vars,eqs,NONE(),NONE(),BackendDAE.NO_MATCHING(),stateSets);
71247134
sharedOut := sharedIn;
71257135
end resolveLoops_main;
@@ -7239,6 +7249,7 @@ end resolveLoops_cutNodes;
72397249

72407250

72417251
protected function sortPathsAsChain "sorts the paths, so that the endNode of the next Path is an endNode of one of all already sorted path.
7252+
the contractedNodes represent the endNodes of the already sorted path
72427253
author: Waurich TUD 2014-01"
72437254
input list<list<Integer>> pathsIn;
72447255
input list<Integer> contractedNodes;
@@ -7257,6 +7268,7 @@ algorithm
72577268
sortedPaths;
72587269
case(path::rest,_,{})
72597270
equation
7271+
// the first node
72607272
startNode = List.first(path);
72617273
endNode = List.last(path);
72627274
contrNodes = listAppend({startNode,endNode},contractedNodes);
@@ -7276,10 +7288,15 @@ algorithm
72767288
sortedPaths = sortPathsAsChain(rest,contrNodes,sortedPaths);
72777289
then
72787290
sortedPaths;
7291+
else
7292+
equation
7293+
print("sorting failed\n");
7294+
then
7295+
fail();
72797296
end matchcontinue;
72807297
end sortPathsAsChain;
72817298

7282-
protected function endNodesInLst"checks if an endnode(first or last) of teh given path is member of the given list.
7299+
protected function endNodesInLst"checks if an endnode(first or last) of the given path is member of the given list.
72837300
author: Waurich TUD 2014-01"
72847301
input list<Integer> path;
72857302
input list<Integer> lstIn;
@@ -7295,7 +7312,6 @@ algorithm
72957312
inLst := b1 or b2;
72967313
end endNodesInLst;
72977314

7298-
72997315
protected function firstInListIsEqual"checks if the first element in a list is equal to the given value
73007316
author:Waurich TUD 2014-01"
73017317
input list<Integer> lstIn;
@@ -7341,34 +7357,44 @@ end connectPaths;
73417357
protected function connect2PathsToLoops"connects 2 paths to a closed loop
73427358
author:Waurich TUD 2014-01"
73437359
input list<list<Integer>> pathsIn;
7344-
input list<list<Integer>> loopsIn;
7360+
input list<list<Integer>> loopsIn; //empty input
7361+
input list<list<Integer>> restPathsIn; // empt input
73457362
output list<list<Integer>> pathsOut;
7363+
output list<list<Integer>> restPathsOut;
73467364
algorithm
7347-
pathsOut := matchcontinue(pathsIn,loopsIn)
7365+
(pathsOut,restPathsOut) := matchcontinue(pathsIn,loopsIn,restPathsIn)
73487366
local
73497367
Boolean closedALoop;
73507368
Integer startNode, endNode;
73517369
list<Integer> path;
7352-
list<list<Integer>> rest, endPaths, startPaths, loops;
7353-
case({path},_)
7370+
list<list<Integer>> rest, endPaths, startPaths, loops, restPaths;
7371+
case({},_,_)
7372+
equation
7373+
then
7374+
({},{});
7375+
case({path},_,_)
73547376
equation
7377+
// checks if the single path closes itself
73557378
startNode = List.first(path);
73567379
endNode = List.last(path);
73577380
closedALoop = intEq(startNode,endNode);
73587381
loops = Util.if_(closedALoop,path::loopsIn,loopsIn);
7382+
restPaths = Util.if_(closedALoop,restPathsIn,path::restPathsIn);
73597383
then
7360-
loops;
7361-
case(path::rest,_)
7384+
(loops,restPaths);
7385+
case(path::rest,_,_)
73627386
equation
7387+
// the loop closes itself
73637388
startNode = List.first(path);
73647389
endNode = List.last(path);
73657390
true = intEq(startNode,endNode);
73667391
loops = path::loopsIn;
7367-
loops = connect2PathsToLoops(rest,loops);
7392+
(loops,restPaths) = connect2PathsToLoops(rest,loops,restPathsIn);
73687393
then
7369-
loops;
7370-
case(path::rest,_)
7394+
(loops,restPaths);
7395+
case(path::rest,_,_)
73717396
equation
7397+
// check if there is another path that closes the Loop. if not: put the path to the restPaths
73727398
startNode = List.first(path);
73737399
endNode = List.last(path);
73747400
startPaths = List.filter1OnTrue(rest,firstInListIsEqual,startNode);
@@ -7378,10 +7404,11 @@ algorithm
73787404
endPaths = listAppend(startPaths,endPaths);
73797405
closedALoop = intGe(listLength(endPaths),1);
73807406
loops = Debug.bcallret2(closedALoop,connectPaths,path,endPaths,{});
7407+
restPaths = Util.if_(closedALoop,restPathsIn,path::restPathsIn);
73817408
loops = listAppend(loops,loopsIn);
7382-
loops = connect2PathsToLoops(rest,loops);
7409+
(loops,restPaths) = connect2PathsToLoops(rest,loops,restPaths);
73837410
then
7384-
loops;
7411+
(loops,restPaths);
73857412
else
73867413
equation
73877414
print("connect2PathsToLoops failed\n");
@@ -7488,17 +7515,17 @@ algorithm
74887515
Boolean isNoSingleLoop;
74897516
Integer replaceIdx,eqIdx,varIdx,parEqIdx,daeEqIdx;
74907517
list<Integer> varCrossLst, eqCrossLst, crossNodes, restNodes, adjCrossNodes, partition, partition2, replEqs, subLoop;
7491-
list<list<Integer>> paths, allPaths, simpleLoops, varEqsLst, crossEqLst, paths0, paths1, closedPaths;
7518+
list<list<Integer>> paths, allPaths, simpleLoops, varEqsLst, crossEqLst, paths0, paths1, closedPaths, loopConnectors, connectedPaths;
74927519
BackendDAE.Equation resolvedEq, startEq;
74937520
list<BackendDAE.Equation> eqLst;
74947521
case(_,_,eqIdx::eqCrossLst,{},_,_)
74957522
equation
74967523
//print("partition has only eqCrossNodes\n");
74977524
// get the paths between the crossEqNodes and order them according to their length
7498-
paths = getPathTillNextCrossEq(eqCrossLstIn,mIn,mTIn,eqCrossLstIn,{},{});
7499-
allPaths = List.sort(paths,List.listIsLonger);
7525+
allPaths = getPathTillNextCrossEq(eqCrossLstIn,mIn,mTIn,eqCrossLstIn,{},{});
7526+
allPaths = List.sort(allPaths,List.listIsLonger);
75007527
//print("all paths: \n"+&stringDelimitList(List.map(allPaths,HpcOmTaskGraph.intLstString)," / ")+&"\n");
7501-
paths1 = List.fold1(paths,getReverseDoubles,paths,{}); // all paths with just one direction
7528+
paths1 = List.fold1(allPaths,getReverseDoubles,allPaths,{}); // all paths with just one direction
75027529
//print("paths1: \n"+&stringDelimitList(List.map(paths1,HpcOmTaskGraph.intLstString)," / ")+&"\n");
75037530
paths0 = List.unique(paths1); // only the paths between the eqs without concerning the vars in between
75047531
//print("paths0: \n"+&stringDelimitList(List.map(paths0,HpcOmTaskGraph.intLstString)," / ")+&"\n");
@@ -7512,12 +7539,21 @@ algorithm
75127539
//print("the simpleLoop: \n"+&stringDelimitList(List.map(subLoop,intString)," / ")+&"\n");
75137540
//print("other paths: \n"+&stringDelimitList(List.map(paths,HpcOmTaskGraph.intLstString)," / ")+&"\n");
75147541
//print("paths0: \n"+&stringDelimitList(List.map(paths0,HpcOmTaskGraph.intLstString)," / ")+&"\n");
7515-
paths0 = List.sort(paths0,List.listIsLonger); // solve the small loops first
7516-
paths0 = sortPathsAsChain(paths0,{},{});
7542+
//paths0 = List.sort(paths0,List.listIsLonger); // solve the small loops first
7543+
7544+
paths0 = List.sort(paths,List.listIsLonger); // solve the small loops first
7545+
7546+
//paths0 = sortPathsAsChain(paths0,{},{});
75177547
//print("unconnected paths: \n"+&stringDelimitList(List.map(paths0,HpcOmTaskGraph.intLstString)," / ")+&"\n");
7518-
paths0 = connect2PathsToLoops(paths0,{});
7519-
//print("connected paths: "+&stringDelimitList(List.map(paths0,HpcOmTaskGraph.intLstString)," / ")+&"\n\n");
7520-
paths0 = listAppend(simpleLoops,paths0);
7548+
(connectedPaths,loopConnectors) = connect2PathsToLoops(paths0,{},{});
7549+
loopConnectors = List.filter1OnTrue(loopConnectors,connectsLoops,simpleLoops);
7550+
//print("possible loopConnectors: "+&stringDelimitList(List.map(loopConnectors,HpcOmTaskGraph.intLstString)," / ")+&"\n\n");
7551+
//print("connected paths: "+&stringDelimitList(List.map(connectedPaths,HpcOmTaskGraph.intLstString)," / ")+&"\n\n");
7552+
simpleLoops = listAppend(simpleLoops,loopConnectors);
7553+
paths0 = listAppend(simpleLoops,connectedPaths);
7554+
7555+
paths0 = sortPathsAsChain(paths0,{},{});
7556+
75217557
//print("all paths to be resolved: \n"+&stringDelimitList(List.map(paths0,HpcOmTaskGraph.intLstString)," / ")+&"\n");
75227558
then
75237559
paths0;
@@ -7568,6 +7604,30 @@ algorithm
75687604
end resolveLoops_findLoops2;
75697605

75707606

7607+
protected function connectsLoops"checks if the given path connects 2 closed simple Loops
7608+
author:Waurich TUD 2014-02"
7609+
input list<Integer> path;
7610+
input list<list<Integer>> allLoops;
7611+
output Boolean connected;
7612+
protected
7613+
Boolean b1, b2;
7614+
Integer startNode, endNode;
7615+
list<list<Integer>> loops1, loops2;
7616+
algorithm
7617+
startNode := List.first(path);
7618+
endNode := List.last(path);
7619+
// the startNode is connected to a loop
7620+
loops1 := List.filter1OnTrue(allLoops,firstInListIsEqual,startNode);
7621+
loops2 := List.filter1OnTrue(allLoops,lastInListIsEqual,startNode);
7622+
b1 := List.isNotEmpty(loops1) or List.isNotEmpty(loops2);
7623+
// the endNode is connected to a loop
7624+
loops1 := List.filter1OnTrue(allLoops,firstInListIsEqual,endNode);
7625+
loops2 := List.filter1OnTrue(allLoops,lastInListIsEqual,endNode);
7626+
b2 := List.isNotEmpty(loops1) or List.isNotEmpty(loops2);
7627+
connected := b1 and b2;
7628+
end connectsLoops;
7629+
7630+
75717631
protected function connectPathsToOneLoop "tries to connect various paths to one closed, simple loop
75727632
author:Waurich TUD 2014-02"
75737633
input list<list<Integer>> allPathsIn;
@@ -7652,11 +7712,11 @@ algorithm
76527712
//print("crossEqs: "+&stringDelimitList(List.map(crossEqs,intString),",")+&"\n");
76537713
//print("eqs: "+&stringDelimitList(List.map(eqs,intString),",")+&"\n");
76547714

7655-
// first try to replace a non cross node, otherweise an already replaced eq, or if none of them is available take a crossnode
7715+
// first try to replace a non cross node, otherwise an already replaced eq, or if none of them is available take a crossnode (THIS IS NOT YET CLEAR)
76567716
pos = Debug.bcallret1(List.isNotEmpty(crossEqs),List.first,crossEqs,-1);
7657-
pos = Debug.bcallret1(List.isNotEmpty(eqs),List.first,eqs,pos); // CHECK THIS
7658-
pos = Debug.bcallret1(List.isNotEmpty(replEqsIn),List.first,replEqsIn,pos);
76597717
//pos = Debug.bcallret1(List.isNotEmpty(eqs),List.first,eqs,pos); // CHECK THIS
7718+
pos = Debug.bcallret1(List.isNotEmpty(replEqsIn),List.first,replEqsIn,pos);
7719+
pos = Debug.bcallret1(List.isNotEmpty(eqs),List.first,eqs,pos); // CHECK THIS
76607720

76617721

76627722
eqs = List.deleteMember(loop1,pos);

0 commit comments

Comments
 (0)