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 <stack>
43 #include <string>
44 #include <vector>
45 
51 typedef std::vector< std::pair<int, int> > oms_ssc_t;
52 
53 namespace oms
54 {
56  {
57  public:
58  DirectedGraph();
60 
61  void clear();
62 
63  int addNode(const Connector& var);
64  void addEdge(const Connector& var1, const Connector& var2);
65 
66  void dotExport(const std::string& filename);
67 
68  void includeGraph(const DirectedGraph& graph, const ComRef& prefix);
69 
70  const std::vector< oms_ssc_t >& getSortedConnections();
71 
72  const std::vector<Connector>& getNodes() const {return nodes;}
73  const oms_ssc_t& getEdges() const {return edges;}
74 
75  private:
76  std::deque< std::vector<int> > getSCCs();
78  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);
79 
80  static int getEdgeIndex(const oms_ssc_t& edges, int from, int to);
81 
82  private:
83  std::vector<Connector> nodes;
85 
86  std::vector< std::vector<int> > G;
87  std::vector< oms_ssc_t > sortedConnections;
89  };
90 }
91 
92 #endif
std::vector< oms_ssc_t > sortedConnections
Definition: DirectedGraph.h:87
void includeGraph(const DirectedGraph &graph, const ComRef &prefix)
Definition: DirectedGraph.cpp:139
oms_ssc_t edges
Definition: DirectedGraph.h:84
std::deque< std::vector< int > > getSCCs()
Definition: DirectedGraph.cpp:206
void addEdge(const Connector &var1, const Connector &var2)
Definition: DirectedGraph.cpp:73
~DirectedGraph()
Definition: DirectedGraph.cpp:52
std::vector< std::pair< int, int > > oms_ssc_t
Strong connected components data type.
Definition: DirectedGraph.h:51
bool sortedConnectionsAreValid
Definition: DirectedGraph.h:88
static int getEdgeIndex(const oms_ssc_t &edges, int from, int to)
Definition: DirectedGraph.cpp:148
std::vector< std::vector< int > > G
Definition: DirectedGraph.h:86
const std::vector< oms_ssc_t > & getSortedConnections()
Definition: DirectedGraph.cpp:246
DirectedGraph()
Definition: DirectedGraph.cpp:47
ComRef - component reference.
Definition: ComRef.h:43
Connector.
Definition: Connector.h:48
void calculateSortedConnections()
Definition: DirectedGraph.cpp:253
const oms_ssc_t & getEdges() const
Definition: DirectedGraph.h:73
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:158
Definition: AlgLoop.h:44
int addNode(const Connector &var)
Definition: DirectedGraph.cpp:65
std::vector< Connector > nodes
Definition: DirectedGraph.h:83
const std::vector< Connector > & getNodes() const
Definition: DirectedGraph.h:72
void clear()
Definition: DirectedGraph.cpp:56
Definition: DirectedGraph.h:55
void dotExport(const std::string &filename)
Definition: DirectedGraph.cpp:100