@@ -362,6 +362,7 @@ public function resolveLoops_findLoops "author:Waurich TUD 2014-02
362362 input list< list< Integer >> partitionsIn;
363363 input BackendDAE . IncidenceMatrix mIn; // the whole system of simpleEquations
364364 input BackendDAE . IncidenceMatrixT mTIn;
365+ input Boolean findExactlyOneLoop= false ;
365366 output list< list< Integer >> loopsOut = {};
366367 output list< Integer > crossEqsOut = {};
367368 output list< Integer > crossVarsOut = {};
@@ -383,7 +384,10 @@ algorithm
383384 varCrossLst := List . fold2(partitionVars,gatherCrossNodes,mTIn,mIn,{});
384385
385386 // search the partitions for loops
386- loops := resolveLoops_findLoops2(partition,eqCrossLst,varCrossLst,mIn,mTIn);
387+ loops := resolveLoops_findLoops2(partition,eqCrossLst,varCrossLst,mIn,mTIn,findExactlyOneLoop);
388+ if if findExactlyOneLoop then (not listEmpty(loops) and not listEmpty(loopsOut)) else false then
389+ fail();
390+ end if ;
387391 loopsOut := listAppend(loops,loopsOut);
388392 if isPresent(crossEqsOut) then
389393 crossEqsOut := listAppend(eqCrossLst,crossEqsOut);
@@ -404,6 +408,7 @@ protected function resolveLoops_findLoops2 "author: Waurich TUD 2014-01
404408 input list< Integer > varCrossLstIn;
405409 input BackendDAE . IncidenceMatrix mIn; // the whole system of simpleEquations
406410 input BackendDAE . IncidenceMatrixT mTIn;
411+ input Boolean findExactlyOneLoop;
407412 output list< list< Integer >> loopsOut;
408413algorithm
409414 loopsOut := match(eqsIn,eqCrossLstIn,varCrossLstIn,mIn,mTIn)
@@ -439,6 +444,11 @@ algorithm
439444 simpleLoops = if isNoSingleLoop then simpleLoops else {subLoop};
440445 paths0 = listAppend(simpleLoops,connectedPaths);
441446 paths0 = sortPathsAsChain(paths0);
447+ if findExactlyOneLoop then
448+ if not listEmpty(paths0) then
449+ {_} = paths0;
450+ end if ;
451+ end if ;
442452
443453 // print("all paths to be resolved: \n"+stringDelimitList(List.map(paths0,HpcOmTaskGraph.intLstString)," / ")+"\n");
444454 then
@@ -461,8 +471,12 @@ algorithm
461471 closedPaths = List . map(closedPaths,List . unique);
462472 closedPaths = List . map1(closedPaths,getEqNodesForVarLoop,mTIn);// get the eqs for these varLoops
463473 // print("solve the smallest loops: \n"+stringDelimitList(List.map(closedPaths,HpcOmTaskGraph.intLstString)," / ")+"\n");
464- then
465- closedPaths;
474+ if findExactlyOneLoop then
475+ if not listEmpty(closedPaths) then
476+ {_} = closedPaths;
477+ end if ;
478+ end if ;
479+ then closedPaths;
466480 case (_,{},{},_,_)
467481 algorithm
468482 // no crossNodes
@@ -474,8 +488,7 @@ algorithm
474488 break ;
475489 end if ;
476490 end for ;
477- then
478- {subLoop};
491+ then {subLoop};
479492 case (_,_::_,_::_,_,_)
480493 algorithm
481494 // print("there are both varCrossNodes and eqNodes\n");
@@ -487,11 +500,10 @@ algorithm
487500 arrayUpdate(mTIn, i, List . sort(mTIn[i], intGt));
488501 end for ;
489502 eqCrossSet := AvlSetInt . addList(AvlSetInt . EMPTY (), eqCrossLstIn);
490- paths := getShortPathsBetweenEqCrossNodes(AvlSetInt . listKeysReverse(eqCrossSet), eqCrossSet, mIn, mTIn, {});
503+ paths := getShortPathsBetweenEqCrossNodes(AvlSetInt . listKeysReverse(eqCrossSet), eqCrossSet, mIn, mTIn, {}, findExactlyOneLoop );
491504 //
492505 // print("GOT SOME NEW LOOPS: \n"+stringDelimitList(List.map(paths,HpcOmTaskGraph.intLstString)," / ")+"\n");
493- then
494- paths;
506+ then paths;
495507 else
496508 equation
497509 Error . addInternalError("function resolveLoops_findLoops2 failed" , sourceInfo());
@@ -546,6 +558,7 @@ author: vwaurich TUD 12-2016"
546558 input BackendDAE . IncidenceMatrix mIn;
547559 input BackendDAE . IncidenceMatrixT mTIn;
548560 input list< list< Integer >> pathsIn;
561+ input Boolean findExactlyOneLoop;
549562 output list< list< Integer >> pathsOut;
550563algorithm
551564 pathsOut := match(eqCrossLstIn, mIn, mTIn, pathsIn)
@@ -567,12 +580,16 @@ algorithm
567580 // print("all sharedVars "+stringDelimitList(List.map(sharedVars, intString),",")+"\n");
568581 if hasSameIntSortedExcept(adjVars, arrayGet(mIn, adjEq), adjVar) then
569582 newPath := adjEq::{crossEq};
583+ // TODO: List.unionElt is slow
570584 paths := List . unionElt(newPath, paths);
571585 // print("found path "+stringDelimitList(List.map(newPath,intString)," ; ")+"\n");
586+ if if findExactlyOneLoop then (not listEmpty(pathsIn)) else false then
587+ fail();
588+ end if ;
572589 end if ;
573590 end for ;
574591 end for ;
575- paths := getShortPathsBetweenEqCrossNodes(rest, eqCrossSet, mIn, mTIn, listAppend(paths, pathsIn));
592+ paths := getShortPathsBetweenEqCrossNodes(rest, eqCrossSet, mIn, mTIn, listAppend(paths, pathsIn), findExactlyOneLoop );
576593 then paths;
577594 case ({},_,_,_)
578595 then pathsIn;
0 commit comments