OMSimulatorLib The OMSimulator project is a FMI-based co-simulation environment.

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