OMSimulatorLib
The OMSimulator project is a FMI-based co-simulation environment.
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 <map>
41 #include <set>
42 #include <stack>
43 #include <string>
44 #include <vector>
45 
46 namespace oms
47 {
53  struct scc_t
54  {
55  std::vector< std::pair<int, int> > connections;
56  bool thisIsALoop; // needed because a SSC with just one connection can be a loop! fmu.y -> fmu.u
57  unsigned int size;
59  std::set<oms::ComRef> component_names;
60  double factor;
62  };
63 
65  {
66  public:
67  DirectedGraph();
69 
70  void clear();
71 
72  int addNode(const Connector& var);
73  void addEdge(const Connector& var1, const Connector& var2);
74 
75  void dotExport(const std::string& filename);
76 
77  void includeGraph(const DirectedGraph& graph, const ComRef& prefix);
78 
79  const std::vector< scc_t >& getSortedConnections();
80 
81  const std::vector<Connector>& getNodes() const {return nodes;}
82  const scc_t& getEdges() const {return edges;}
83 
84  void setUnits(Connector* conA, Connector* conB, bool suppressUnitConversion);
85  void dumpNodes() const;
86 
87  private:
88  std::deque< std::vector<int> > getSCCs();
90  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);
91 
92  static int getEdgeIndex(const scc_t& edges, int from, int to);
93 
94  private:
95  std::vector<Connector> nodes;
97 
98  std::vector< std::vector<int> > G;
99  std::vector< scc_t > sortedConnections;
101 
103  {
107  };
108 
109  std::vector<suppressUnitConversion> unitConversion;
110  };
111 }
112 
113 #endif
ComRef - component reference.
Definition: ComRef.h:47
Connector.
Definition: Connector.h:50
Definition: DirectedGraph.h:65
void includeGraph(const DirectedGraph &graph, const ComRef &prefix)
Definition: DirectedGraph.cpp:140
bool sortedConnectionsAreValid
Definition: DirectedGraph.h:100
std::deque< std::vector< int > > getSCCs()
Definition: DirectedGraph.cpp:207
const std::vector< scc_t > & getSortedConnections()
Definition: DirectedGraph.cpp:247
scc_t edges
Definition: DirectedGraph.h:96
std::vector< Connector > nodes
Definition: DirectedGraph.h:95
DirectedGraph()
Definition: DirectedGraph.cpp:48
void dumpNodes() const
Definition: DirectedGraph.cpp:372
std::vector< std::vector< int > > G
Definition: DirectedGraph.h:98
static int getEdgeIndex(const scc_t &edges, int from, int to)
Definition: DirectedGraph.cpp:149
const scc_t & getEdges() const
Definition: DirectedGraph.h:82
int addNode(const Connector &var)
Definition: DirectedGraph.cpp:66
~DirectedGraph()
Definition: DirectedGraph.cpp:53
void calculateSortedConnections()
Definition: DirectedGraph.cpp:254
void clear()
Definition: DirectedGraph.cpp:57
void setUnits(Connector *conA, Connector *conB, bool suppressUnitConversion)
Definition: DirectedGraph.cpp:341
std::vector< scc_t > sortedConnections
Definition: DirectedGraph.h:99
void dotExport(const std::string &filename)
Definition: DirectedGraph.cpp:101
const std::vector< Connector > & getNodes() const
Definition: DirectedGraph.h:81
std::vector< suppressUnitConversion > unitConversion
Definition: DirectedGraph.h:109
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)
Definition: DirectedGraph.cpp:159
void addEdge(const Connector &var1, const Connector &var2)
Definition: DirectedGraph.cpp:74
Definition: AlgLoop.h:45
Definition: DirectedGraph.h:103
bool unitConversion
Definition: DirectedGraph.h:106
oms::ComRef conB
Definition: DirectedGraph.h:105
oms::ComRef conA
Definition: DirectedGraph.h:104
Strong connected components data type.
Definition: DirectedGraph.h:54
std::set< oms::ComRef > component_names
Definition: DirectedGraph.h:59
double factor
Definition: DirectedGraph.h:60
std::vector< std::pair< int, int > > connections
Definition: DirectedGraph.h:55
unsigned int size
Definition: DirectedGraph.h:57
bool suppressUnitConversion
Definition: DirectedGraph.h:61
unsigned int size_including_internal
Definition: DirectedGraph.h:58
bool thisIsALoop
Definition: DirectedGraph.h:56