OMSimulatorLib
The OMSimulator project is a FMI-based co-simulation environment that supports ordinary (i.e., non-delayed) and TLM connections.
DirectedGraph.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenModelica.
3  *
4  * Copyright (c) 1998-CurrentYear, 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 GPL VERSION 3 LICENSE OR
11  * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
12  * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13  * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
14  * ACCORDING TO RECIPIENTS CHOICE.
15  *
16  * The OpenModelica software and the Open Source Modelica
17  * Consortium (OSMC) Public License (OSMC-PL) are obtained
18  * from OSMC, either from the above address,
19  * from the URLs: http://www.ida.liu.se/projects/OpenModelica or
20  * http://www.openmodelica.org, and in the OpenModelica distribution.
21  * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
22  *
23  * This program is distributed WITHOUT ANY WARRANTY; without
24  * even the implied warranty of MERCHANTABILITY or FITNESS
25  * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
26  * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
27  *
28  * See the full OSMC Public License conditions for more details.
29  *
30  */
31 
32 #ifndef _OMS_DIRECTED_GRAPH_H_
33 #define _OMS_DIRECTED_GRAPH_H_
34 
35 #include "ComRef.h"
36 #include "Connector.h"
37 #include "Variable.h"
38 
39 #include <deque>
40 #include <fmilib.h>
41 #include <map>
42 #include <set>
43 #include <stack>
44 #include <string>
45 #include <vector>
46 
47 namespace oms
48 {
54  struct scc_t
55  {
56  std::vector< std::pair<int, int> > connections;
57  bool thisIsALoop; // needed because a SSC with just one connection can be a loop! fmu.y -> fmu.u
58  unsigned int size;
60  std::set<oms::ComRef> component_names;
61  double factor;
63  };
64 
66  {
67  public:
68  DirectedGraph();
69  ~DirectedGraph();
70 
71  void clear();
72 
73  int addNode(const Connector& var);
74  void addEdge(const Connector& var1, const Connector& var2);
75 
76  void dotExport(const std::string& filename);
77 
78  void includeGraph(const DirectedGraph& graph, const ComRef& prefix);
79 
80  const std::vector< scc_t >& getSortedConnections();
81 
82  const std::vector<Connector>& getNodes() const {return nodes;}
83  const scc_t& getEdges() const {return edges;}
84 
85  void setUnits(Connector* conA, Connector* conB, bool suppressUnitConversion);
86  void dumpNodes() const;
87 
88  private:
89  std::deque< std::vector<int> > getSCCs();
90  void calculateSortedConnections();
91  void strongconnect(int v, std::vector< std::vector<int> > G, int& index, int *d, int *low, std::stack<int>& S, bool *stacked, std::deque< std::vector<int> >& components);
92 
93  static int getEdgeIndex(const scc_t& edges, int from, int to);
94 
95  private:
96  std::vector<Connector> nodes;
98 
99  std::vector< std::vector<int> > G;
100  std::vector< scc_t > sortedConnections;
102 
103  struct suppressUnitConversion
104  {
108  };
109 
110  std::vector<suppressUnitConversion> unitConversion;
111  };
112 }
113 
114 #endif
std::set< oms::ComRef > component_names
Definition: DirectedGraph.h:60
oms::ComRef conA
Definition: DirectedGraph.h:105
std::vector< scc_t > sortedConnections
Definition: DirectedGraph.h:100
Strong connected components data type.
Definition: DirectedGraph.h:54
unsigned int size_including_internal
Definition: DirectedGraph.h:59
bool sortedConnectionsAreValid
Definition: DirectedGraph.h:101
Definition: DirectedGraph.h:103
std::vector< std::vector< int > > G
Definition: DirectedGraph.h:99
bool suppressUnitConversion
Definition: DirectedGraph.h:62
bool unitConversion
Definition: DirectedGraph.h:107
ComRef - component reference.
Definition: ComRef.h:46
Connector.
Definition: Connector.h:49
std::vector< std::pair< int, int > > connections
Definition: DirectedGraph.h:56
oms::ComRef conB
Definition: DirectedGraph.h:106
Definition: AlgLoop.h:44
double factor
Definition: DirectedGraph.h:61
bool thisIsALoop
Definition: DirectedGraph.h:57
std::vector< Connector > nodes
Definition: DirectedGraph.h:96
scc_t edges
Definition: DirectedGraph.h:97
const std::vector< Connector > & getNodes() const
Definition: DirectedGraph.h:82
std::vector< suppressUnitConversion > unitConversion
Definition: DirectedGraph.h:110
Definition: DirectedGraph.h:65
unsigned int size
Definition: DirectedGraph.h:58
const scc_t & getEdges() const
Definition: DirectedGraph.h:83