Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 84.6% 55 / 0 / 65
Functions: -% 0 / 1 / 1
Branches: 46.9% 15 / 0 / 32

OMCompiler/Compiler/Util/GraphML.mo
Line Branch Exec Source
1 /*
2 * This file is part of OpenModelica.
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
5 * c/o Linköpings universitet, Department of Computer and Information Science,
6 * SE-58183 Linköping, Sweden.
7 *
8 * All rights reserved.
9 *
10 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL
14 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the OSMC (Open Source Modelica Consortium)
17 * Public License (OSMC-PL) are obtained from OSMC, either from the above
18 * address, from the URLs:
19 * http://www.openmodelica.org or
20 * https://github.com/OpenModelica/ or
21 * http://www.ida.liu.se/projects/OpenModelica,
22 * and in the OpenModelica distribution.
23 *
24 * GNU AGPL version 3 is obtained from:
25 * https://www.gnu.org/licenses/licenses.html#GPL
26 *
27 * This program is distributed WITHOUT ANY WARRANTY; without
28 * even the implied warranty of MERCHANTABILITY or FITNESS
29 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
30 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
31 *
32 * See the full OSMC Public License conditions for more details.
33 *
34 */
35
36 encapsulated package GraphML
37 " file: GraphML
38 package: GraphML
39 description: GraphML contains functions to generate a gaphML file for yED. The implementation is based on the GraphML-Package of Jens Frenkel.
40
41
42 "
43
44 protected import List;
45 protected import GraphMLDumpTpl;
46 protected import Tpl;
47 protected import Util;
48
49 //TODO: Use HashTable for nodes to prevent duplicates
50
51 // -------------------------
52 // Constant types
53 // -------------------------
54
55 public constant String COLOR_BLACK = "000000";
56 public constant String COLOR_BLUE = "0000FF";
57 public constant String COLOR_GREEN = "339966";
58 public constant String COLOR_RED = "FF0000";
59 public constant String COLOR_DARKRED = "800000";
60 public constant String COLOR_WHITE = "FFFFFF";
61 public constant String COLOR_YELLOW = "FFFF00";
62 public constant String COLOR_GRAY = "C0C0C0";
63 public constant String COLOR_PURPLE = "993366";
64 public constant String COLOR_ORANGE = "FFCC00";
65 public constant String COLOR_ORANGE2 = "FF6600";
66 public constant String COLOR_DARKGRAY = "666666";
67 public constant String COLOR_RED2 = "F0988E";
68 public constant String COLOR_GREEN2 = "98B954";
69 public constant String COLOR_CYAN = "46BED8";
70 public constant String COLOR_PINK = "CF8CB7";
71 public constant String COLOR_GREEN3 = "008080";
72
73 public constant Real LINEWIDTH_STANDARD = 2.0;
74 public constant Real LINEWIDTH_BOLD = 4.0;
75
76 public constant Integer FONTSIZE_STANDARD = 12;
77 public constant Integer FONTSIZE_BIG = 20;
78 public constant Integer FONTSIZE_SMALL = 8;
79
80 public constant Real BORDERWIDTH_STANDARD = 1.0;
81 public constant Real BORDERWIDTH_BOLD = 4.0;
82
83 // -------------------------
84 // Data structures
85 // -------------------------
86
87 public uniontype GraphInfo
88 record GRAPHINFO
89 list<Graph> graphs;
90 Integer graphCount; //number of graphs in the graphs list
91 list<Node> nodes;
92 Integer nodeCount; //number of nodes in the nodes list
93 list<Edge> edges;
94 Integer edgeCount; //number of edges in the edge list
95 list<Attribute> attributes;
96 String graphNodeKey;
97 String graphEdgeKey;
98 end GRAPHINFO;
99 record GRAPHINFOARR //This structure is used by Susan
100 array<Graph> graphs;
101 array<Node> nodes;
102 list<Edge> edges;
103 array<Attribute> attributes;
104 String graphNodeKey;
105 String graphEdgeKey;
106 end GRAPHINFOARR;
107 end GraphInfo;
108
109 public uniontype Graph
110 record GRAPH
111 String id;
112 Boolean directed;
113 list<Integer> nodeIdc; //attention: reversed indices --> to get real idx for value i, calculate graph.nodeCount - i
114 list<tuple<Integer,String>> attValues; //values of custom attributes (see GRAPHINFO definition). <attributeIndex,attributeValue>
115 end GRAPH;
116 end Graph;
117
118 public uniontype Node
119 record NODE
120 String id;
121 String color;
122 Real border;
123 list<NodeLabel> nodeLabels;
124 ShapeType shapeType;
125 Option<String> optDesc;
126 list<tuple<Integer,String>> attValues; //values of custom attributes (see GRAPH definition). <attributeIndex,attributeValue>
127 end NODE;
128 record GROUPNODE
129 String id;
130 Integer internalGraphIdx;
131 Boolean isFolded;
132 String header;
133 end GROUPNODE;
134 end Node;
135
136 public uniontype Edge
137 record EDGE
138 String id;
139 String target;
140 String source;
141 String color;
142 LineType lineType;
143 Real lineWidth;
144 Boolean smooth;
145 list<EdgeLabel> edgeLabels;
146 tuple<ArrowType,ArrowType> arrows;
147 list<tuple<Integer,String>> attValues; //values of custom attributes (see GRAPH definition). <attributeIndex,attributeValue>
148 end EDGE;
149 end Edge;
150
151 public uniontype Attribute
152 record ATTRIBUTE
153 Integer attIdx;
154 String defaultValue;
155 String name;
156 AttributeType attType;
157 AttributeTarget attTarget;
158 end ATTRIBUTE;
159 end Attribute;
160
161 public uniontype NodeLabel
162 record NODELABEL_INTERNAL
163 String text;
164 Option<String> backgroundColor;
165 FontStyle fontStyle;
166 end NODELABEL_INTERNAL;
167 record NODELABEL_CORNER
168 String text;
169 Option<String> backgroundColor;
170 FontStyle fontStyle;
171 String position; //for example "se" for south east
172 end NODELABEL_CORNER;
173 end NodeLabel;
174
175 public uniontype EdgeLabel
176 record EDGELABEL
177 String text;
178 Option<String> backgroundColor;
179 Integer fontSize;
180 end EDGELABEL;
181 end EdgeLabel;
182
183 public uniontype FontStyle
184 record FONTPLAIN end FONTPLAIN;
185 record FONTBOLD end FONTBOLD;
186 record FONTITALIC end FONTITALIC;
187 record FONTBOLDITALIC end FONTBOLDITALIC;
188 end FontStyle;
189
190 public uniontype ShapeType
191 record RECTANGLE end RECTANGLE;
192 record ROUNDRECTANGLE end ROUNDRECTANGLE;
193 record ELLIPSE end ELLIPSE;
194 record PARALLELOGRAM end PARALLELOGRAM;
195 record HEXAGON end HEXAGON;
196 record TRIANGLE end TRIANGLE;
197 record OCTAGON end OCTAGON;
198 record DIAMOND end DIAMOND;
199 record TRAPEZOID end TRAPEZOID;
200 record TRAPEZOID2 end TRAPEZOID2;
201 end ShapeType;
202
203 public uniontype LineType
204 record LINE end LINE;
205 record DASHED end DASHED;
206 record DASHEDDOTTED end DASHEDDOTTED;
207 end LineType;
208
209 public uniontype ArrowType
210 record ARROWSTANDART end ARROWSTANDART;
211 record ARROWNONE end ARROWNONE;
212 record ARROWCONCAVE end ARROWCONCAVE;
213 end ArrowType;
214
215 public uniontype AttributeType
216 record TYPE_STRING end TYPE_STRING;
217 record TYPE_BOOLEAN end TYPE_BOOLEAN;
218 record TYPE_INTEGER end TYPE_INTEGER;
219 record TYPE_DOUBLE end TYPE_DOUBLE;
220 end AttributeType;
221
222 public uniontype AttributeTarget
223 record TARGET_NODE end TARGET_NODE;
224 record TARGET_EDGE end TARGET_EDGE;
225 record TARGET_GRAPH end TARGET_GRAPH;
226 end AttributeTarget;
227
228 // -------------------------
229 // Logic
230 // -------------------------
231
232 public function createGraphInfo "author: marcusw
233 Creates a new and empty graphInfo."
234 output GraphInfo oGraphInfo;
235 algorithm
236 oGraphInfo := GRAPHINFO({},0,{},0,{},0,{}, "gi1", "gi2");
237 end createGraphInfo;
238
239 public function addGraph "author: marcusw
240 Adds a new graph to the given graphInfo."
241 input String id; //graph id -> must be unique in the graphinfo!
242 input Boolean directed; //directed edges
243 input GraphInfo iGraphInfo;
244 output GraphInfo oGraphInfo;
245 output tuple<Graph,Integer> oGraph; //graph with graphIdx
246 protected
247 Graph tmpGraph;
248 list<Graph> graphs;
249 Integer graphCount; //number of graphs in the graphs list
250 list<Node> nodes;
251 Integer nodeCount; //number of nodes in the nodes list
252 list<Edge> edges;
253 Integer edgeCount; //number of edges in the edge list
254 list<Attribute> attributes;
255 String graphNodeKey;
256 String graphEdgeKey;
257 algorithm
258
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 105 times.
105 GRAPHINFO(graphs,graphCount,nodes,nodeCount,edges,edgeCount,attributes,graphNodeKey,graphEdgeKey) := iGraphInfo;
259 105 graphCount := graphCount + 1;
260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 105 times.
105 tmpGraph := GRAPH(id, directed, {}, {});
261 graphs := tmpGraph :: graphs;
262 105 oGraphInfo := GRAPHINFO(graphs,graphCount,nodes,nodeCount,edges,edgeCount,attributes,graphNodeKey,graphEdgeKey);
263 105 oGraph := (tmpGraph, graphCount);
264 end addGraph;
265
266 public function addNode "author: marcusw
267 Adds a new node to the given graph which is part of the given graphInfo."
268 input String id; //node id -> must be unique in the graphinfo!
269 input String backgroundColor;
270 input Real borderWidth;
271 input list<NodeLabel> nodeLabels; //a list of labels that should be displayed in or along the node
272 input ShapeType shapeType;
273 input Option<String> optDesc;
274 input list<tuple<Integer,String>> attValues; //a key-value list of additional values -> the keys have to be registered in the graphinfo-structure first
275
276 input Integer iGraphIdx; //the parent-graph of the new node -> with this additional information, nested graphs are supported now
277 input GraphInfo iGraphInfo;
278 output GraphInfo oGraphInfo;
279 output tuple<Node,Integer> oNode; //node with nodeIdx
280 protected
281 Node tmpNode;
282 //values of graphinfo
283 list<Graph> graphs;
284 Integer graphCount; //number of graphs in the graphs list
285 list<Node> nodes;
286 Integer nodeCount; //number of nodes in the nodes list
287 list<Edge> edges;
288 Integer edgeCount; //number of edges in the edge list
289 list<Attribute> attributes;
290 String graphNodeKey;
291 String graphEdgeKey;
292
293 //values of graph
294 Graph iGraph;
295 String gid;
296 Boolean directed;
297 list<Integer> nodeIdc;
298 list<tuple<Integer,String>> gAttValues;
299 algorithm
300
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8603 times.
8603 GRAPHINFO(graphs,graphCount,nodes,nodeCount,edges,edgeCount,attributes,graphNodeKey,graphEdgeKey) := iGraphInfo;
301 8603 iGraph := listGet(graphs,graphCount-iGraphIdx+1);
302 8603 GRAPH(gid,directed,nodeIdc,gAttValues) := iGraph;
303 8603 nodeCount := nodeCount + 1;
304 8603 tmpNode := NODE(id, backgroundColor,borderWidth, nodeLabels, shapeType, optDesc, attValues);
305 nodes := tmpNode :: nodes;
306 nodeIdc := nodeCount :: nodeIdc;
307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8603 times.
8603 iGraph := GRAPH(gid,directed,nodeIdc,gAttValues);
308 8603 graphs := List.set(graphs,graphCount-iGraphIdx+1,iGraph);
309 8603 oGraphInfo := GRAPHINFO(graphs,graphCount,nodes,nodeCount,edges,edgeCount,attributes,graphNodeKey,graphEdgeKey);
310 8603 oNode := (tmpNode, nodeCount);
311 end addNode;
312
313 public function addGroupNode "author: marcusw
314 Adds a new group node to the given graphInfo. The created node contains a new graph which is returned as second output-argument."
315 input String id; //node id -> must be unique in the graphinfo!
316 input Integer iGraphIdx;
317 input Boolean isFolded; //true if the group-node should be folded by default
318 input String iHeader; //header text which should be displayed on top of the group
319 input GraphInfo iGraphInfo;
320 output GraphInfo oGraphInfo;
321 output tuple<Node,Integer> oNode; //node with nodeIdx
322 output tuple<Graph,Integer> oGraph; //subgraph with graphIdx
323 protected
324 GraphInfo tmpGraphInfo;
325 Node tmpNode;
326 //values of graphinfo
327 list<Graph> graphs;
328 Integer graphCount; //number of graphs in the graphs list
329 list<Node> nodes;
330 Integer nodeCount; //number of nodes in the nodes list
331 list<Edge> edges;
332 Integer edgeCount; //number of edges in the edge list
333 list<Attribute> attributes;
334 String graphNodeKey;
335 String graphEdgeKey;
336
337 //values of graph
338 Graph iGraph, newGraph;
339 String gid;
340 Boolean directed;
341 Integer newGraphIdx;
342 list<Integer> nodeIdc;
343 list<tuple<Integer,String>> attValues; //values of custom attributes (see GRAPHINFO definition). <attributeIndex,attributeValue>
344 algorithm
345
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 GRAPHINFO(graphs,graphCount,nodes,nodeCount,edges,edgeCount,attributes,graphNodeKey,graphEdgeKey) := iGraphInfo;
346 48 iGraph := listGet(graphs,graphCount-iGraphIdx+1);
347 48 GRAPH(gid,directed,nodeIdc,attValues) := iGraph;
348 //Add new sub graph
349 48 (tmpGraphInfo,(newGraph,newGraphIdx)) := addGraph("g" + id, directed, iGraphInfo);
350
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 GRAPHINFO(graphs,graphCount,nodes,nodeCount,edges,edgeCount,attributes,graphNodeKey,graphEdgeKey) := tmpGraphInfo;
351 //Append node to graph
352 48 nodeCount := nodeCount + 1;
353
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 32 times.
64 tmpNode := GROUPNODE(id, newGraphIdx,isFolded,iHeader);
354 nodes := tmpNode :: nodes;
355 nodeIdc := nodeCount :: nodeIdc;
356
357
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 iGraph := GRAPH(gid,directed,nodeIdc,attValues);
358 48 graphs := List.set(graphs,graphCount-iGraphIdx+1,iGraph);
359 48 oGraphInfo := GRAPHINFO(graphs,graphCount,nodes,nodeCount,edges,edgeCount,attributes,graphNodeKey,graphEdgeKey);
360 48 oNode := (tmpNode, nodeCount);
361 48 oGraph := (newGraph,newGraphIdx);
362 end addGroupNode;
363
364 public function addEdge "author: marcusw
365 Adds a new edge to the graphInfo-structure. Edges are always added to the top-level graph."
366 input String id;
367 input String target;
368 input String source;
369 input String color;
370 input LineType lineType;
371 input Real lineWidth;
372 input Boolean smooth;
373 input list<EdgeLabel> labels;
374 input tuple<ArrowType,ArrowType> arrows;
375 input list<tuple<Integer,String>> attValues;
376
377 input GraphInfo iGraphInfo;
378 output GraphInfo oGraphInfo;
379 output tuple<Edge,Integer> oEdge; //edge with edgeIdx
380 protected
381 Edge tmpEdge;
382 //values of graphinfo
383 list<Graph> graphs;
384 Integer graphCount; //number of graphs in the graphs list
385 list<Node> nodes;
386 Integer nodeCount; //number of nodes in the nodes list
387 list<Edge> edges;
388 Integer edgeCount; //number of edges in the edge list
389 list<Attribute> attributes;
390 String graphNodeKey;
391 String graphEdgeKey;
392
393 algorithm
394
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14426 times.
14426 GRAPHINFO(graphs,graphCount,nodes,nodeCount,edges,edgeCount,attributes,graphNodeKey,graphEdgeKey) := iGraphInfo;
395 14426 edgeCount := edgeCount + 1;
396
1/2
✓ Branch 0 taken 14426 times.
✗ Branch 1 not taken.
28852 tmpEdge := EDGE(id, target, source, color, lineType, lineWidth, smooth, labels, arrows, attValues);
397 edges := tmpEdge :: edges;
398 14426 oGraphInfo := GRAPHINFO(graphs,graphCount,nodes,nodeCount,edges,edgeCount,attributes,graphNodeKey,graphEdgeKey);
399 14426 oEdge := (tmpEdge, edgeCount);
400 end addEdge;
401
402 public function addAttribute "author: marcusw
403 Adds a new attribute to the given graphInfo.
404 These attributes can be used by graphs, nodes and edges to display some additional informations."
405 input String defaultValue;
406 input String name;
407 input AttributeType attType;
408 input AttributeTarget attTarget;
409
410 input GraphInfo iGraphInfo;
411 output GraphInfo oGraphInfo;
412 output tuple<Attribute,Integer> oAttribute; //attribute with attributeIdx
413 protected
414 Attribute tmpAttribute;
415 Integer attIdx;
416 //values of graphinfo
417 list<Graph> graphs;
418 Integer graphCount; //number of graphs in the graphs list
419 list<Node> nodes;
420 Integer nodeCount; //number of nodes in the nodes list
421 list<Edge> edges;
422 Integer edgeCount; //number of edges in the edge list
423 list<Attribute> attributes;
424 String graphNodeKey;
425 String graphEdgeKey;
426 algorithm
427
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1067 times.
1067 GRAPHINFO(graphs,graphCount,nodes,nodeCount,edges,edgeCount,attributes,graphNodeKey,graphEdgeKey) := iGraphInfo;
428 1067 attIdx := listLength(attributes)+1;
429 1067 tmpAttribute := ATTRIBUTE(attIdx,defaultValue,name,attType,attTarget);
430 attributes := tmpAttribute :: attributes;
431 1067 oGraphInfo := GRAPHINFO(graphs,graphCount,nodes,nodeCount,edges,edgeCount,attributes,graphNodeKey,graphEdgeKey);
432 1067 oAttribute := (tmpAttribute,attIdx);
433 end addAttribute;
434
435 public function addGraphAttributeValue "author: marcusw
436 Adds a new value for a given attribute to the graph."
437 input tuple<Integer,String> iValue; //attributeIdx, attributeValue
438 input Integer iGraphIdx;
439 input GraphInfo iGraphInfo;
440 output GraphInfo oGraphInfo;
441 protected
442 //values of graphinfo
443 list<Graph> graphs;
444 Integer graphCount; //number of graphs in the graphs list
445 list<Node> nodes;
446 Integer nodeCount; //number of nodes in the nodes list
447 list<Edge> edges;
448 Integer edgeCount; //number of edges in the edge list
449 list<Attribute> attributes;
450 String graphNodeKey;
451 String graphEdgeKey;
452 //values of graph
453 Graph iGraph;
454 String gid;
455 Boolean directed;
456 list<Integer> nodeIdc;
457 list<tuple<Integer,String>> attValues; //values of custom attributes (see GRAPHINFO definition). <attributeIndex,attributeValue>
458 algorithm
459
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 GRAPHINFO(graphs,graphCount,nodes,nodeCount,edges,edgeCount,attributes,graphNodeKey,graphEdgeKey) := iGraphInfo;
460 56 iGraph := listGet(graphs,graphCount-iGraphIdx+1);
461 56 GRAPH(gid,directed,nodeIdc,attValues) := iGraph;
462
463 //Append attribute to graph
464 attValues := iValue :: attValues;
465
466
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 iGraph := GRAPH(gid,directed,nodeIdc,attValues);
467 56 graphs := List.set(graphs,graphCount-iGraphIdx+1,iGraph);
468 56 oGraphInfo := GRAPHINFO(graphs,graphCount,nodes,nodeCount,edges,edgeCount,attributes,graphNodeKey,graphEdgeKey);
469 end addGraphAttributeValue;
470
471 // -------------------------
472 // Helper
473 // -------------------------
474 public function getMainGraph "author: marcusw
475 This function will return the top-level graph (usually with index 1) if there is one in the graphInfo-structure.
476 Otherwise it will return NONE()."
477 input GraphInfo iGraphInfo;
478 output Option<tuple<Integer,Graph>> oGraph;
479 protected
480 list<Graph> graphs;
481 Graph firstGraph;
482 algorithm
483 oGraph := match iGraphInfo
484 case GRAPHINFO(graphCount=0)
485 then NONE();
486 case GRAPHINFO(graphs=graphs)
487 algorithm
488 ✗ firstGraph := listHead(graphs);
489 ✗ then SOME((1,firstGraph));
490 end match;
491 end getMainGraph;
492
493 public function getAttributeByNameAndTarget
494 input String iAttributeName;
495 input AttributeTarget iAttributeTarget;
496 input GraphInfo iGraphInfo;
497 output Option<tuple<Attribute,Integer>> oAttribute; //SOME(<%attIdx,attribute%>) if the attribute was found in graphInfo
498 protected
499 list<Attribute> attributes;
500 Option<tuple<Attribute,Integer>> tmpRes;
501 algorithm
502 oAttribute := match iGraphInfo
503 case GRAPHINFO(attributes=attributes)
504 algorithm
505 16 tmpRes := getAttributeByNameAndTargetTail(attributes, iAttributeName, iAttributeTarget);
506 then tmpRes;
507 case GRAPHINFO(attributes=attributes)
508 algorithm
509 ✗ tmpRes := getAttributeByNameAndTargetTail(attributes, iAttributeName, iAttributeTarget);
510 then tmpRes;
511 end match;
512 end getAttributeByNameAndTarget;
513
514 protected function getAttributeByNameAndTargetTail
515 input list<Attribute> iList;
516 input String iAttributeName;
517 input AttributeTarget iAttributeTarget;
518 output Option<tuple<Attribute,Integer>> oAttribute;
519 protected
520 list<Attribute> rest;
521 Integer attIdx;
522 String name;
523 Attribute head;
524 AttributeTarget attTarget;
525 Option<tuple<Attribute,Integer>> tmpAttribute;
526 algorithm
527 oAttribute := match iList
528 case (head as ATTRIBUTE(attIdx=attIdx,name=name,attTarget=attTarget))::rest guard stringEq(name, iAttributeName) and compareAttributeTargets(iAttributeTarget,attTarget)
529 16 then SOME((head,attIdx));
530 case head::rest
531 algorithm
532 176 tmpAttribute := getAttributeByNameAndTargetTail(rest,iAttributeName,iAttributeTarget);
533 then tmpAttribute;
534 else
535 then NONE();
536 end match;
537 end getAttributeByNameAndTargetTail;
538
539 protected function compareAttributeTargets
540 input AttributeTarget iTarget1;
541 input AttributeTarget iTarget2;
542 output Boolean oEqual;
543 protected
544 Integer tarInt1, tarInt2;
545 algorithm
546 16 tarInt1 := compareAttributeTarget0(iTarget1);
547 16 tarInt2 := compareAttributeTarget0(iTarget2);
548 16 oEqual := intEq(tarInt1,tarInt2);
549 end compareAttributeTargets;
550
551 protected function compareAttributeTarget0
552 input AttributeTarget iTarget;
553 output Integer oCodec;
554 algorithm
555 oCodec := match iTarget
556 case TARGET_NODE() then 0;
557 case TARGET_EDGE() then 1;
558 case TARGET_GRAPH() then 1;
559 end match;
560 end compareAttributeTarget0;
561
562 // -------------------------
563 // Dump
564 // -------------------------
565
566
567 public function dumpGraph "author: marcusw
568 Dumps the graph into a *.graphml-file."
569 input GraphInfo iGraphInfo;
570 input String iFileName;
571 protected
572 GraphInfo iGraphInfoArr;
573 algorithm
574 57 iGraphInfoArr := convertToGraphInfoArr(iGraphInfo);
575 57 Tpl.tplNoret2(GraphMLDumpTpl.dumpGraphInfo, iGraphInfoArr, iFileName);
576 end dumpGraph;
577
578 protected function convertToGraphInfoArr "author: marcusw
579 Converts the given GRAPHINFO-object into a GRAPHINFOARR-object."
580 input GraphInfo iGraphInfo;
581 output GraphInfo oGraphInfo;
582 protected
583 //values of graphinfo
584 list<Graph> graphs;
585 array<Graph> graphsArr;
586 Integer graphCount; //number of graphs in the graphs list
587 list<Node> nodes;
588 array<Node> nodesArr;
589 Integer nodeCount; //number of nodes in the nodes list
590 list<Edge> edges;
591 Integer edgeCount; //number of edges in the edge list
592 list<Attribute> attributes;
593 array<Attribute> attributesArr;
594 String graphNodeKey;
595 String graphEdgeKey;
596 algorithm
597
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
57 GRAPHINFO(graphs,graphCount,nodes,nodeCount,edges,edgeCount,attributes,graphNodeKey,graphEdgeKey) := iGraphInfo;
598 57 graphsArr := listArray(graphs);
599 57 nodesArr := listArray(nodes);
600 57 attributesArr := List.listArrayReverse(attributes);
601 57 oGraphInfo := GRAPHINFOARR(graphsArr,nodesArr,edges,attributesArr,graphNodeKey,graphEdgeKey);
602 end convertToGraphInfoArr;
603
604 // -------------------------
605 // debug prints
606 // -------------------------
607 public function printGraphInfo
608 input GraphInfo iGraphInfo;
609 protected
610 list<Graph> graphs;
611 Integer graphCount; //number of graphs in the graphs list
612 list<Node> nodes;
613 Integer nodeCount; //number of nodes in the nodes list
614 //number of edges in the edge list
615 list<Attribute> attributes;
616 String graphNodeKey;
617 String graphEdgeKey;
618 algorithm
619 ✗ GRAPHINFO(graphs=graphs,graphCount=graphCount,nodes=nodes,nodeCount=nodeCount,attributes=attributes,graphNodeKey=graphNodeKey,graphEdgeKey=graphEdgeKey) := iGraphInfo;
620 ✗ List.map_0(nodes,printNode);
621 ✗ print("nodeCount: "+intString(nodeCount)+"\n");
622 ✗ print("graphCount: "+intString(graphCount)+"\n");
623 end printGraphInfo;
624
625 protected function printNode
626 input Node node;
627 protected
628 String id,atts;
629 Option<String> optDesc;
630 list<tuple<Integer,String>> attValues; //values of custom attributes (see GRAPH definition). <attributeIndex,attributeValue>
631 algorithm
632 ✗ NODE(id=id,optDesc=optDesc,attValues=attValues) := node;
633 ✗ atts := stringDelimitList(List.map(attValues,Util.tuple22)," | ");
634 ✗ print("node: "+id+" desc: "+Util.getOption(optDesc)+"\n\tatts: "+atts+"\n");
635 end printNode;
636
637 annotation(__OpenModelica_Interface="codegen_graphml");
638 end GraphML;
639