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 <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
oms
Definition: AlgLoop.h:44
Util.h
oms::DirectedGraph::addNode
int addNode(const Connector &var)
Definition: DirectedGraph.cpp:66
ComRef.h
oms::scc_t
Strong connected components data type.
Definition: DirectedGraph.h:53
oms::ComRef
ComRef - component reference.
Definition: ComRef.h:46
oms::DirectedGraph::suppressUnitConversion::conA
oms::ComRef conA
Definition: DirectedGraph.h:104
oms::DirectedGraph::includeGraph
void includeGraph(const DirectedGraph &graph, const ComRef &prefix)
Definition: DirectedGraph.cpp:140
oms::DirectedGraph::nodes
std::vector< Connector > nodes
Definition: DirectedGraph.h:95
oms::DirectedGraph::unitConversion
std::vector< suppressUnitConversion > unitConversion
Definition: DirectedGraph.h:109
logInfo
#define logInfo(msg)
Definition: Logging.h:100
DirectedGraph.h
oms::DirectedGraph
Definition: DirectedGraph.h:64
oms::DirectedGraph::suppressUnitConversion::unitConversion
bool unitConversion
Definition: DirectedGraph.h:106
oms::DirectedGraph::getEdgeIndex
static int getEdgeIndex(const scc_t &edges, int from, int to)
Definition: DirectedGraph.cpp:149
oms::DirectedGraph::getSortedConnections
const std::vector< scc_t > & getSortedConnections()
Definition: DirectedGraph.cpp:247
oms::Connector::connectorUnits
std::map< std::string, std::map< std::string, std::string > > connectorUnits
single entry map which contains unit as key and BaseUnits as value for a connector
Definition: Connector.h:74
oms::DirectedGraph::addEdge
void addEdge(const Connector &var1, const Connector &var2)
Definition: DirectedGraph.cpp:74
oms::DirectedGraph::G
std::vector< std::vector< int > > G
Definition: DirectedGraph.h:98
oms::scc_t::suppressUnitConversion
bool suppressUnitConversion
Definition: DirectedGraph.h:61
oms::scc_t::size
unsigned int size
Definition: DirectedGraph.h:57
oms::DirectedGraph::calculateSortedConnections
void calculateSortedConnections()
Definition: DirectedGraph.cpp:254
oms::DirectedGraph::sortedConnections
std::vector< scc_t > sortedConnections
Definition: DirectedGraph.h:99
oms::DirectedGraph::~DirectedGraph
~DirectedGraph()
Definition: DirectedGraph.cpp:53
oms::scc_t::thisIsALoop
bool thisIsALoop
Definition: DirectedGraph.h:56
oms::DirectedGraph::setUnits
void setUnits(Connector *conA, Connector *conB, bool suppressUnitConversion)
Definition: DirectedGraph.cpp:338
oms::DirectedGraph::getSCCs
std::deque< std::vector< int > > getSCCs()
Definition: DirectedGraph.cpp:207
Connection.h
Connector.h
oms::DirectedGraph::suppressUnitConversion::conB
oms::ComRef conB
Definition: DirectedGraph.h:105
oms::scc_t::size_including_internal
unsigned int size_including_internal
Definition: DirectedGraph.h:58
oms::Connector::getName
const oms::ComRef getName() const
Definition: Connector.h:80
logError
#define logError(msg)
Definition: Logging.h:102
oms::DirectedGraph::getEdges
const scc_t & getEdges() const
Definition: DirectedGraph.h:82
oms::scc_t::component_names
std::set< oms::ComRef > component_names
Definition: DirectedGraph.h:59
oms::DirectedGraph::DirectedGraph
DirectedGraph()
Definition: DirectedGraph.cpp:48
oms::DirectedGraph::edges
scc_t edges
Definition: DirectedGraph.h:96
oms::DirectedGraph::strongconnect
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
oms::ComRef::pop_front
ComRef pop_front()
returns the first part of the ComRef and removed it from the current object
Definition: ComRef.cpp:184
oms::scc_t::connections
std::vector< std::pair< int, int > > connections
Definition: DirectedGraph.h:55
oms::DirectedGraph::dumpNodes
void dumpNodes() const
Definition: DirectedGraph.cpp:369
oms::DirectedGraph::getNodes
const std::vector< Connector > & getNodes() const
Definition: DirectedGraph.h:81
oms::DirectedGraph::suppressUnitConversion
Definition: DirectedGraph.h:102
oms::Connector
Connector.
Definition: Connector.h:49
Logging.h
oms::scc_t::factor
double factor
Definition: DirectedGraph.h:60
oms::DirectedGraph::clear
void clear()
Definition: DirectedGraph.cpp:57
oms::Connector::getOwner
const oms::ComRef getOwner() const
Definition: Connector.h:79
Variable.h
oms::Connection::isValid
static bool isValid(const ComRef &crefA, const ComRef &crefB, const Connector &conA, const Connector &conB)
Checks a connection based on SSP-1.0 connection table.
Definition: Connection.cpp:212
oms::DirectedGraph::dotExport
void dotExport(const std::string &filename)
Definition: DirectedGraph.cpp:101
oms::DirectedGraph::sortedConnectionsAreValid
bool sortedConnectionsAreValid
Definition: DirectedGraph.h:100