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 
46 namespace oms
47 {
49  {
50  public:
51  DirectedGraph();
53 
54  void clear();
55 
56  int addNode(const Connector& var);
57  void addEdge(const Connector& var1, const Connector& var2);
58 
59  void dotExport(const std::string& filename);
60 
61  void includeGraph(const DirectedGraph& graph, const ComRef& prefix);
62 
63  const std::vector< std::vector< std::pair<int, int> > >& getSortedConnections();
64 
65  const std::vector<Connector>& getNodes() const {return nodes;}
66  const std::vector< std::pair<int, int> >& getEdges() const {return edges;}
67 
68  private:
69  std::deque< std::vector<int> > getSCCs();
71  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);
72 
73  static int getEdgeIndex(const std::vector< std::pair<int, int> >& edges, int from, int to);
74 
75  private:
76  std::vector<Connector> nodes;
77  std::vector< std::pair<int, int> > edges;
78 
79  std::vector< std::vector<int> > G;
80  std::vector< std::vector< std::pair<int, int> > > sortedConnections;
82  };
83 }
84 
85 #endif
void includeGraph(const DirectedGraph &graph, const ComRef &prefix)
Definition: DirectedGraph.cpp:138
std::vector< std::pair< int, int > > edges
Definition: DirectedGraph.h:77
std::deque< std::vector< int > > getSCCs()
Definition: DirectedGraph.cpp:205
void addEdge(const Connector &var1, const Connector &var2)
Definition: DirectedGraph.cpp:72
~DirectedGraph()
Definition: DirectedGraph.cpp:51
bool sortedConnectionsAreValid
Definition: DirectedGraph.h:81
std::vector< std::vector< int > > G
Definition: DirectedGraph.h:79
const std::vector< std::vector< std::pair< int, int > > > & getSortedConnections()
Definition: DirectedGraph.cpp:245
static int getEdgeIndex(const std::vector< std::pair< int, int > > &edges, int from, int to)
Definition: DirectedGraph.cpp:147
DirectedGraph()
Definition: DirectedGraph.cpp:46
ComRef - component reference.
Definition: ComRef.h:43
Connector.
Definition: Connector.h:48
void calculateSortedConnections()
Definition: DirectedGraph.cpp:252
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:157
Definition: BusConnector.h:15
int addNode(const Connector &var)
Definition: DirectedGraph.cpp:64
std::vector< Connector > nodes
Definition: DirectedGraph.h:76
const std::vector< Connector > & getNodes() const
Definition: DirectedGraph.h:65
void clear()
Definition: DirectedGraph.cpp:55
Definition: DirectedGraph.h:48
std::vector< std::vector< std::pair< int, int > > > sortedConnections
Definition: DirectedGraph.h:80
const std::vector< std::pair< int, int > > & getEdges() const
Definition: DirectedGraph.h:66
void dotExport(const std::string &filename)
Definition: DirectedGraph.cpp:99