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
51namespace 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;
64 std::set<oms::ComRef> component_names;
65 double factor;
67 oms_linear_transformation_t linearTransformation;
68 };
69
71 {
72 public:
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();
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;
103
104 std::vector< std::vector<int> > G;
105 std::vector< scc_t > sortedConnections;
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 - component reference.
Definition ComRef.h:51
**
Definition Connection.h:52
Connector.
Definition Connector.h:54
Definition DirectedGraph.h:71
void includeGraph(const DirectedGraph &graph, const ComRef &prefix)
Definition DirectedGraph.cpp:144
bool sortedConnectionsAreValid
Definition DirectedGraph.h:106
std::deque< std::vector< int > > getSCCs()
Definition DirectedGraph.cpp:211
const std::vector< scc_t > & getSortedConnections()
Definition DirectedGraph.cpp:251
scc_t edges
Definition DirectedGraph.h:102
std::vector< Connector > nodes
Definition DirectedGraph.h:101
DirectedGraph()
Definition DirectedGraph.cpp:52
void dumpNodes() const
Definition DirectedGraph.cpp:381
std::vector< std::vector< int > > G
Definition DirectedGraph.h:104
static int getEdgeIndex(const scc_t &edges, int from, int to)
Definition DirectedGraph.cpp:153
const scc_t & getEdges() const
Definition DirectedGraph.h:88
int addNode(const Connector &var)
Definition DirectedGraph.cpp:70
const std::vector< Connector > & getNodes() const
Definition DirectedGraph.h:87
std::vector< Connection * > connections
Definition DirectedGraph.h:108
~DirectedGraph()
Definition DirectedGraph.cpp:57
void calculateSortedConnections()
Definition DirectedGraph.cpp:258
void clear()
Definition DirectedGraph.cpp:61
std::vector< scc_t > sortedConnections
Definition DirectedGraph.h:105
void dotExport(const std::string &filename)
Definition DirectedGraph.cpp:105
void setUnits(Connector *conA, Connector *conB, Connection *connection)
Definition DirectedGraph.cpp:354
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
void addEdge(const Connector &var1, const Connector &var2)
Definition DirectedGraph.cpp:78
Definition AlgLoop.h:49
Strong connected components data type.
Definition DirectedGraph.h:59
std::set< oms::ComRef > component_names
Definition DirectedGraph.h:64
double factor
Definition DirectedGraph.h:65
std::vector< std::pair< int, int > > connections
Definition DirectedGraph.h:60
unsigned int size
Definition DirectedGraph.h:62
oms_linear_transformation_t linearTransformation
Definition DirectedGraph.h:67
bool suppressUnitConversion
Definition DirectedGraph.h:66
unsigned int size_including_internal
Definition DirectedGraph.h:63
bool thisIsALoop
Definition DirectedGraph.h:61