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-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;
58 unsigned int size_including_internal;
59 std::set<oms::ComRef> component_names;
60 double factor;
61 bool suppressUnitConversion;
62 };
63
64 class DirectedGraph
65 {
66 public:
67 DirectedGraph();
68 ~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();
89 void calculateSortedConnections();
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;
96 scc_t edges;
97
98 std::vector< std::vector<int> > G;
99 std::vector< scc_t > sortedConnections;
100 bool sortedConnectionsAreValid;
101
102 struct suppressUnitConversion
103 {
104 oms::ComRef conA;
105 oms::ComRef conB;
106 bool unitConversion;
107 };
108
109 std::vector<suppressUnitConversion> unitConversion;
110 };
111}
112
113#endif
ComRef.h
Connector.h
Variable.h
oms::ComRef
ComRef - component reference.
Definition ComRef.h:47
oms::Connector
Connector.
Definition Connector.h:50
oms::DirectedGraph
Definition DirectedGraph.h:65
oms::DirectedGraph::includeGraph
void includeGraph(const DirectedGraph &graph, const ComRef &prefix)
Definition DirectedGraph.cpp:140
oms::DirectedGraph::sortedConnectionsAreValid
bool sortedConnectionsAreValid
Definition DirectedGraph.h:100
oms::DirectedGraph::getSCCs
std::deque< std::vector< int > > getSCCs()
Definition DirectedGraph.cpp:207
oms::DirectedGraph::getSortedConnections
const std::vector< scc_t > & getSortedConnections()
Definition DirectedGraph.cpp:247
oms::DirectedGraph::edges
scc_t edges
Definition DirectedGraph.h:96
oms::DirectedGraph::nodes
std::vector< Connector > nodes
Definition DirectedGraph.h:95
oms::DirectedGraph::DirectedGraph
DirectedGraph()
Definition DirectedGraph.cpp:48
oms::DirectedGraph::dumpNodes
void dumpNodes() const
Definition DirectedGraph.cpp:377
oms::DirectedGraph::G
std::vector< std::vector< int > > G
Definition DirectedGraph.h:98
oms::DirectedGraph::getEdgeIndex
static int getEdgeIndex(const scc_t &edges, int from, int to)
Definition DirectedGraph.cpp:149
oms::DirectedGraph::getEdges
const scc_t & getEdges() const
Definition DirectedGraph.h:82
oms::DirectedGraph::addNode
int addNode(const Connector &var)
Definition DirectedGraph.cpp:66
oms::DirectedGraph::getNodes
const std::vector< Connector > & getNodes() const
Definition DirectedGraph.h:81
oms::DirectedGraph::~DirectedGraph
~DirectedGraph()
Definition DirectedGraph.cpp:53
oms::DirectedGraph::calculateSortedConnections
void calculateSortedConnections()
Definition DirectedGraph.cpp:254
oms::DirectedGraph::clear
void clear()
Definition DirectedGraph.cpp:57
oms::DirectedGraph::setUnits
void setUnits(Connector *conA, Connector *conB, bool suppressUnitConversion)
Definition DirectedGraph.cpp:343
oms::DirectedGraph::sortedConnections
std::vector< scc_t > sortedConnections
Definition DirectedGraph.h:99
oms::DirectedGraph::dotExport
void dotExport(const std::string &filename)
Definition DirectedGraph.cpp:101
oms::DirectedGraph::unitConversion
std::vector< suppressUnitConversion > unitConversion
Definition DirectedGraph.h:109
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::DirectedGraph::addEdge
void addEdge(const Connector &var1, const Connector &var2)
Definition DirectedGraph.cpp:74
oms
Definition AlgLoop.h:45
oms::DirectedGraph::suppressUnitConversion
Definition DirectedGraph.h:103
oms::DirectedGraph::suppressUnitConversion::unitConversion
bool unitConversion
Definition DirectedGraph.h:106
oms::DirectedGraph::suppressUnitConversion::conB
oms::ComRef conB
Definition DirectedGraph.h:105
oms::DirectedGraph::suppressUnitConversion::conA
oms::ComRef conA
Definition DirectedGraph.h:104
oms::scc_t
Strong connected components data type.
Definition DirectedGraph.h:54
oms::scc_t::component_names
std::set< oms::ComRef > component_names
Definition DirectedGraph.h:59
oms::scc_t::factor
double factor
Definition DirectedGraph.h:60
oms::scc_t::connections
std::vector< std::pair< int, int > > connections
Definition DirectedGraph.h:55
oms::scc_t::size
unsigned int size
Definition DirectedGraph.h:57
oms::scc_t::suppressUnitConversion
bool suppressUnitConversion
Definition DirectedGraph.h:61
oms::scc_t::size_including_internal
unsigned int size_including_internal
Definition DirectedGraph.h:58
oms::scc_t::thisIsALoop
bool thisIsALoop
Definition DirectedGraph.h:56