Skip to content

Commit

Permalink
- get thick lines in graphML output for solvable edges and thin lines…
Browse files Browse the repository at this point in the history
… for nonsolvable edges

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@22449 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Volker Waurich committed Sep 26, 2014
1 parent fc23d16 commit ea005e7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 23 deletions.
62 changes: 62 additions & 0 deletions Compiler/BackEnd/HpcOmEqSystems.mo
Expand Up @@ -60,6 +60,7 @@ protected import HpcOmSimCodeMain;
protected import HpcOmScheduler;
protected import List;
protected import Matching;
protected import Tearing;
protected import Util;

//--------------------------------------------------//
Expand Down Expand Up @@ -1872,6 +1873,34 @@ algorithm
GraphML.dumpGraph(graphInfo,name+&".graphml");
end dumpEquationSystemBipartiteGraph2;

public function dumpEquationSystemBipartiteGraphSolve2
input BackendDAE.Variables varsIn;
input BackendDAE.EquationArray eqsIn;
input BackendDAE.AdjacencyMatrixEnhanced meIn;
input list<tuple<Boolean,String>> varAtts; //<isTornVar,daeIdx>
input list<tuple<Boolean,String>> eqAtts; //<isResEq,daeIdx>
input String name;
protected
Integer nameAttIdx,typeAttIdx,idxAttIdx, numVars,numEqs;
list<Integer> varRange,eqRange;
GraphML.GraphInfo graphInfo;
Integer graphIdx;
algorithm
numEqs := BackendDAEUtil.equationArraySize(eqsIn);
numVars := BackendVariable.varsSize(varsIn);
varRange := List.intRange(numVars);
eqRange := List.intRange(numEqs);
graphInfo := GraphML.createGraphInfo();
(graphInfo,(_,graphIdx)) := GraphML.addGraph("EqSystemGraph", true, graphInfo);
(graphInfo,(_,typeAttIdx)) := GraphML.addAttribute("", "type", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo);
(graphInfo,(_,nameAttIdx)) := GraphML.addAttribute("", "name", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo);
(graphInfo,(_,idxAttIdx)) := GraphML.addAttribute("", "systIdx", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo);
((graphInfo,graphIdx)) := List.fold3(eqRange,addEqNodeToGraph,eqsIn,eqAtts,{nameAttIdx,typeAttIdx,idxAttIdx}, (graphInfo,graphIdx));
((graphInfo,graphIdx)) := List.fold3(varRange,addVarNodeToGraph,varsIn,varAtts,{nameAttIdx,typeAttIdx,idxAttIdx}, (graphInfo,graphIdx));
graphInfo := List.fold1(eqRange,addSolvEdgeToGraph,meIn,graphInfo);
GraphML.dumpGraph(graphInfo,name+&".graphml");
end dumpEquationSystemBipartiteGraphSolve2;

protected function addVarNodeToGraph "adds a node for a variable to the graph.
author:Waurich TUD 2013-12"
input Integer indx;
Expand Down Expand Up @@ -1965,6 +1994,39 @@ algorithm
(graphInfoOut,_) := GraphML.addEdge("Edge_"+&intString(varIdx)+&"_"+&intString(eqIdx),varNodeId,eqNodeId,GraphML.COLOR_BLACK,GraphML.LINE(),GraphML.LINEWIDTH_STANDARD,false,{},(GraphML.ARROWNONE(),GraphML.ARROWNONE()),{}, graphInfoIn);
end addEdgeToGraph2;

protected function addSolvEdgeToGraph "adds an edge with solvability information to the graph by traversing the enhanced adjacency matrix.
author:Waurich TUD 2013-12"
input Integer eqIdx;
input BackendDAE.AdjacencyMatrixEnhanced me;
input GraphML.GraphInfo graphInfoIn;
output GraphML.GraphInfo graphInfoOut;
protected
BackendDAE.AdjacencyMatrixElementEnhanced row;
algorithm
row := arrayGet(me,eqIdx);
graphInfoOut := List.fold1(row,addSolvEdgeToGraph2,eqIdx,graphInfoIn);
end addSolvEdgeToGraph;

protected function addSolvEdgeToGraph2 "helper for addSolvEdgeToGraph.
author:Waurich TUD 2013-12"
input BackendDAE.AdjacencyMatrixElementEnhancedEntry var;
input Integer eqIdx;
input GraphML.GraphInfo graphInfoIn;
output GraphML.GraphInfo graphInfoOut;
protected
Boolean solvable;
String eqNodeId, varNodeId;
Real lineWidth;
Integer varIdx;
algorithm
(varIdx,_) := var;
solvable := Tearing.unsolvable({var});
eqNodeId := getEqNodeIdx(eqIdx);
varNodeId := getVarNodeIdx(varIdx);
lineWidth := Util.if_(solvable,GraphML.LINEWIDTH_BOLD,GraphML.LINEWIDTH_STANDARD);
(graphInfoOut,_) := GraphML.addEdge("Edge_"+&intString(varIdx)+&"_"+&intString(eqIdx),varNodeId,eqNodeId,GraphML.COLOR_BLACK,GraphML.LINE(),lineWidth,false,{},(GraphML.ARROWNONE(),GraphML.ARROWNONE()),{}, graphInfoIn);
end addSolvEdgeToGraph2;

protected function genSystemVarIdcs
input list<Integer> idcsIn;
input Integer idx;
Expand Down
34 changes: 11 additions & 23 deletions Compiler/BackEnd/Tearing.mo
Expand Up @@ -459,7 +459,7 @@ algorithm
end getUnsolvableVars;


protected function unsolvable
public function unsolvable
" author: Frenkel TUD 2012-08"
input BackendDAE.AdjacencyMatrixElementEnhanced elem;
output Boolean b;
Expand Down Expand Up @@ -3480,7 +3480,7 @@ protected
BackendDAE.Variables vars,daeVars;
BackendDAE.EqSystem subSys;
BackendDAE.IncidenceMatrix m, m2;
BackendDAE.AdjacencyMatrixEnhanced me, meT;
BackendDAE.AdjacencyMatrixEnhanced me,me2, meT;
DAE.FunctionTree funcs;
BackendDAE.StateSets stateSets;
BackendDAE.BaseClockPartitionKind partitionKind;
Expand All @@ -3490,12 +3490,12 @@ algorithm
//prepare everything
size := listLength(varIdcs);
BackendDAE.EQSYSTEM(orderedVars=daeVars,orderedEqs=daeEqs,matching=BackendDAE.MATCHING(ass1=ass1Sys,ass2=ass2Sys),stateSets=stateSets,partitionKind=partitionKind) := dae;
funcs := BackendDAEUtil.getFunctions(shared);
eqLst := BackendEquation.getEqns(eqIdcs,daeEqs);
eqs := BackendEquation.listEquation(eqLst);
varLst := List.map1r(varIdcs, BackendVariable.getVarAt, daeVars);
vars := BackendVariable.listVar1(varLst);
subSys := BackendDAE.EQSYSTEM(vars,eqs,NONE(),NONE(),BackendDAE.NO_MATCHING(),{},BackendDAE.UNKNOWN_PARTITION());
funcs := BackendDAEUtil.getFunctions(shared);
(me,meT,mapEqnIncRow,mapIncRowEqn) := BackendDAEUtil.getAdjacencyMatrixEnhancedScalar(subSys,shared);
ass1 := arrayCreate(size,-1);
ass2 := arrayCreate(size,-1);
Expand All @@ -3506,8 +3506,7 @@ algorithm
BackendDump.dumpAdjacencyMatrixTEnhanced(meT);
varAtts := List.threadMap(List.fill(false,listLength(varLst)),List.map(eqIdcs,intString),Util.makeTuple);
eqAtts := List.threadMap(List.fill(false,listLength(eqLst)),List.map(varIdcs,intString),Util.makeTuple);
(_,m,_,_,_) := BackendDAEUtil.getIncidenceMatrixScalar(subSys, BackendDAE.NORMAL(), SOME(funcs));
HpcOmEqSystems.dumpEquationSystemBipartiteGraph2(vars,eqs,m,varAtts,eqAtts,"shuffle_pre");
HpcOmEqSystems.dumpEquationSystemBipartiteGraphSolve2(vars,eqs,me,varAtts,eqAtts,"shuffle_pre");

// get all unsolvable variables
unsolvables := getUnsolvableVars(1,size,meT,{});
Expand All @@ -3519,15 +3518,16 @@ algorithm
print("ass1!: "+&stringDelimitList(List.map(arrayList(ass1_),intString),", ")+&"\n");
print("ass2!: "+&stringDelimitList(List.map(arrayList(ass2_),intString),", ")+&"\n");
BackendDump.dumpEquationArray(replEqs,"replEqs");
BackendDump.dumpIncidenceMatrix(m);

subSys := BackendDAE.EQSYSTEM(vars,replEqs,NONE(),NONE(),BackendDAE.NO_MATCHING(),{},BackendDAE.UNKNOWN_PARTITION());
(_,m2,_,_,_) := BackendDAEUtil.getIncidenceMatrixScalar(subSys, BackendDAE.NORMAL(), SOME(funcs));
BackendDump.dumpIncidenceMatrix(m2);
m2 := Util.arrayMap1(m2,deleteInRow,tvars);
List.map2_0(resEqs,Util.arrayUpdateIndexFirst,{},m2);
BackendDump.dumpIncidenceMatrix(m2);

(me2,_,_,_) := BackendDAEUtil.getAdjacencyMatrixEnhancedScalar(subSys,shared);
HpcOmEqSystems.dumpEquationSystemBipartiteGraphSolve2(vars,replEqs,me2,varAtts,eqAtts,"shuffle_post");

otherEqnVarTpl := getOrderForOtherEquations(ass2_,m2,size-listLength(resEqs),{});

//the new global matching (update indeces for torn system and update matching assignments)
Expand All @@ -3553,7 +3553,7 @@ algorithm
daeOut := BackendDAE.EQSYSTEM(daeVars,daeEqs,NONE(),NONE(),BackendDAE.MATCHING(ass1Sys,ass2Sys,{}),stateSets,partitionKind);
(daeOut,_,_,_,_) := BackendDAEUtil.getIncidenceMatrixScalar(daeOut, BackendDAE.NORMAL(), SOME(funcs));

outRunMatching := true;
outRunMatching := true;
end shuffleTearing;

protected function deleteInRow"deletes the deletes in the row.
Expand Down Expand Up @@ -3639,9 +3639,7 @@ algorithm
BackendDAE.IncidenceMatrix m;
BackendDAE.EqSystem subSys;
BackendDAE.EquationArray eqsReplaced,eqs;
BackendDAE.Variables updatedVars;
BackendDAE.AdjacencyMatrixEnhanced me_;
BackendDAE.AdjacencyMatrixEnhanced meT_;
BackendDAE.AdjacencyMatrixEnhanced me_,meT_,meSub;
BackendDAE.AdjacencyMatrixElementEnhanced vareqns;
DAE.FunctionTree funcs;
case({},_,_,_,_,_,_,_,_,_,_,_,_,_)
Expand All @@ -3655,18 +3653,8 @@ algorithm
// tvar selection
tvar = omcTearingSelectTearingVar(varsIn,ass1,ass2,me,meT,{},{},{});
print("selected tvar: "+&intString(tvar)+&"\n");
//bipartite graph
BackendDump.dumpVariables(varsIn,"varsIn");
updatedVars = BackendVariable.listVar(listReverse(listDelete(BackendVariable.varList(varsIn),tvar-1)));
BackendDump.dumpVariables(updatedVars,"updatedVars");
subSys = BackendDAE.EQSYSTEM(updatedVars,eqsIn,NONE(),NONE(),BackendDAE.NO_MATCHING(),{},BackendDAE.UNKNOWN_PARTITION());
(_,m,_,_,_) = BackendDAEUtil.getIncidenceMatrixScalar(subSys, BackendDAE.NORMAL(), SOME(funcs));
updVarIdcs = listDelete(List.intRange(size),tvar-1);
varAtts = List.threadMap(List.fill(false,size-1),List.map(updVarIdcs,intString),Util.makeTuple);
eqAtts = List.threadMap(List.fill(false,size),List.map(List.intRange(size),intString),Util.makeTuple);
HpcOmEqSystems.dumpEquationSystemBipartiteGraph2(updatedVars,eqsIn,m,varAtts,eqAtts,"shuffle_removed_"+&intString(tvar));

// cheap matching

// cheap matching
_ = arrayUpdate(ass1,tvar,size*2);
print("ass1: "+&stringDelimitList(List.map(arrayList(ass1),intString),", ")+&"\n");
vareqns = List.removeOnTrue(ass2, isAssignedSaveEnhanced, meT[tvar]);
Expand Down

0 comments on commit ea005e7

Please sign in to comment.