Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit b636b01

Browse files
vwaurichOpenModelica-Hudson
authored andcommitted
fix bipartiteGraphML generation for algorithms
Belonging to [master]: - #2055
1 parent 3e982aa commit b636b01

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

Compiler/BackEnd/BackendDump.mo

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3932,21 +3932,20 @@ protected
39323932
BackendDAE.AdjacencyMatrixEnhanced me,meT;
39333933
BackendDAE.IncidenceMatrix m;
39343934
Option<BackendDAE.IncidenceMatrix> mO;
3935-
list<BackendDAE.Equation> eqLst;
39363935
list<BackendDAE.Var> varLst;
39373936
list<tuple<Boolean,String>> varAtts,eqAtts;
39383937
algorithm
39393938
BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqs, m=mO) := syst;
39403939
varLst := BackendVariable.varList(vars);
3941-
eqLst := BackendEquation.equationList(eqs);
39423940
varAtts := List.threadMap(List.fill(false,listLength(varLst)),List.fill("",listLength(varLst)),Util.makeTuple);
3943-
eqAtts := List.threadMap(List.fill(false,listLength(eqLst)),List.fill("",listLength(eqLst)),Util.makeTuple);
3941+
eqAtts := List.threadMap(List.fill(false,BackendEquation.equationArraySize(eqs)),List.fill("",BackendEquation.equationArraySize(eqs)),Util.makeTuple);
3942+
39443943
if Util.isSome(mO) then
39453944
dumpBipartiteGraphStrongComponent2(vars,eqs,Util.getOption(mO),varAtts,eqAtts,"BipartiteGraph_"+fileName);
39463945
else
39473946
// build the incidence matrix
39483947
(_,m,_,_,_) := BackendDAEUtil.getIncidenceMatrixScalar(syst, BackendDAE.SOLVABLE(), SOME(BackendDAEUtil.getFunctions(shared)));
3949-
dumpBipartiteGraphStrongComponent2(vars,eqs,m,varAtts,eqAtts,"BipartiteGraph_"+fileName);
3948+
dumpBipartiteGraphStrongComponent2(vars,eqs,m,varAtts,eqAtts,"BipartiteGraph2_"+fileName);
39503949
end if;
39513950
end dumpBipartiteGraphEqSystem;
39523951

@@ -4056,7 +4055,7 @@ protected
40564055
GraphML.GraphInfo graphInfo;
40574056
Integer graphIdx;
40584057
algorithm
4059-
numEqs := BackendEquation.getNumberOfEquations(eqsIn);
4058+
numEqs := BackendEquation.equationArraySize(eqsIn);
40604059
numVars := BackendVariable.varsSize(varsIn);
40614060
varRange := List.intRange(numVars);
40624061
eqRange := List.intRange(numEqs);
@@ -4065,12 +4064,63 @@ algorithm
40654064
(graphInfo,(_,typeAttIdx)) := GraphML.addAttribute("", "type", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo);
40664065
(graphInfo,(_,nameAttIdx)) := GraphML.addAttribute("", "name", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo);
40674066
(graphInfo,(_,idxAttIdx)) := GraphML.addAttribute("", "systIdx", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo);
4068-
((graphInfo,graphIdx)) := List.fold3(eqRange,addEqNodeToGraph,eqsIn,eqAtts,{nameAttIdx,typeAttIdx,idxAttIdx}, (graphInfo,graphIdx));
4067+
(graphInfo,graphIdx) := addEqNodesToGraph(eqsIn,eqAtts,{nameAttIdx,typeAttIdx,idxAttIdx},(graphInfo,graphIdx));
40694068
((graphInfo,graphIdx)) := List.fold3(varRange,addVarNodeToGraph,varsIn,varAtts,{nameAttIdx,typeAttIdx,idxAttIdx}, (graphInfo,graphIdx));
40704069
graphInfo := List.fold1(eqRange,addEdgeToGraph,mIn,graphInfo);
40714070
GraphML.dumpGraph(graphInfo,name+".graphml");
40724071
end dumpBipartiteGraphStrongComponent2;
40734072

4073+
protected function addEqNodesToGraph
4074+
input BackendDAE.EquationArray eqs;
4075+
input list<tuple<Boolean,String>> attsIn; // <isResEq,"daeIdx">
4076+
input list<Integer> attributeIdcs;//<name,type>
4077+
input tuple<GraphML.GraphInfo,Integer> graphInfoIn;
4078+
output tuple<GraphML.GraphInfo,Integer> graphInfoOut;
4079+
protected
4080+
BackendDAE.Equation eq;
4081+
Boolean isResEq;
4082+
Integer nameAttrIdx,typeAttrIdx,idxAttrIdx, graphIdx, size, numEqs, e, eAbs, nextE;
4083+
String eqString, eqNodeId, idxString, typeStr, daeIdxStr;
4084+
list<String> eqChars;
4085+
GraphML.GraphInfo graphInfo;
4086+
GraphML.NodeLabel nodeLabel;
4087+
algorithm
4088+
nameAttrIdx := listGet(attributeIdcs,1);
4089+
typeAttrIdx := listGet(attributeIdcs,2); // if its a residual or not
4090+
idxAttrIdx := listGet(attributeIdcs,3);
4091+
(graphInfo,graphIdx) := graphInfoIn;
4092+
numEqs := BackendEquation.getNumberOfEquations(eqs);
4093+
e := 1;
4094+
eAbs := 1;
4095+
size := 1;
4096+
while e<=numEqs loop
4097+
//print("check e "+intString(e)+"\n");
4098+
eq := BackendEquation.get(eqs,e);
4099+
size := BackendEquation.equationSize(eq);
4100+
//print("size e "+intString(size)+"\n");
4101+
nextE := eAbs+size;
4102+
while nextE>eAbs loop
4103+
//print("add e "+intString(nextE-size)+"\n");
4104+
nameAttrIdx := listGet(attributeIdcs,1);
4105+
typeAttrIdx := listGet(attributeIdcs,2); // if its a residual or not
4106+
idxAttrIdx := listGet(attributeIdcs,3);
4107+
isResEq := Util.tuple21(listGet(attsIn,e));
4108+
daeIdxStr := Util.tuple22(listGet(attsIn,e));
4109+
typeStr := if isResEq then "residualEq" else "otherEq";
4110+
{eq} := BackendEquation.getList({e}, eqs);
4111+
eqString := BackendDump.equationString(eq);
4112+
eqNodeId := getEqNodeIdx(eAbs);
4113+
idxString := intString(eAbs);
4114+
nodeLabel := GraphML.NODELABEL_INTERNAL(idxString,NONE(),GraphML.FONTPLAIN());
4115+
(graphInfo,(_,_)) := GraphML.addNode(eqNodeId,GraphML.COLOR_GREEN2,GraphML.BORDERWIDTH_STANDARD,{nodeLabel},GraphML.RECTANGLE(),SOME(eqString),{(nameAttrIdx,eqString),(typeAttrIdx,typeStr),(idxAttrIdx,daeIdxStr)},graphIdx,graphInfo);
4116+
eAbs := eAbs+1;
4117+
size := size-1;
4118+
end while;
4119+
e := e+1;
4120+
end while;
4121+
graphInfoOut := (graphInfo,graphIdx);
4122+
end addEqNodesToGraph;
4123+
40744124
public function dumpDAGStrongComponent"dumps a directed acyclic graph for the matched strongly connected component"
40754125
input HpcOmTaskGraph.TaskGraph graphIn;
40764126
input HpcOmTaskGraph.TaskGraphMeta metaIn;

Compiler/BackEnd/Matching.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5595,6 +5595,7 @@ algorithm
55955595
BackendDAEEXT.getAssignment(ass1,ass2);
55965596
unmatched1 = getUnassigned(ne, ass1, {});
55975597
//BackendDump.dumpEqSystem(isyst, "EQSYS");
5598+
if Flags.isSet(Flags.BLT_DUMP) and Flags.isSet(Flags.GRAPHML) then BackendDump.dumpBipartiteGraphEqSystem(isyst, ishared, "BeforMatching_"+intString(arrayLength(m))); end if;
55985599
if Flags.isSet(Flags.BLT_DUMP) then print("unmatched equations: "+stringDelimitList(List.map(unmatched1,intString),", ")+"\n\n"); end if;
55995600

56005601
// remove some edges which do not have to be traversed when finding the MSSS

0 commit comments

Comments
 (0)