MicroModelicaCCompiler  4.5.3
graph.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  This file is part of QSS Solver.
4 
5  QSS Solver is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  QSS Solver is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QSS Solver. If not, see <http://www.gnu.org/licenses/>.
17 
18  ******************************************************************************/
19 
20 #include "graph.hpp"
21 
22 #include <iostream>
23 
24 Graph::Graph(int states, int events)
25  : _states(states),
26  _events(events),
27  _nvtxs(states + events),
28  _graphEdges(0),
29  _graph(),
30  _graphInputs(),
31  _graphDiscretes(),
32  _hyperGraph(),
33  _wmap(),
34  _hwmap()
35 {
37 }
38 
40 
41 map<int, set<int>> Graph::graph() { return _graph; }
42 
43 map<int, set<int>> Graph::hyperGraph() { return _hyperGraph; }
44 
45 void Graph::addGraphEdge(int orig, int dest)
46 {
47  _graph[orig].insert(dest);
48  _graphInputs[dest].insert(orig);
49 }
50 
51 void Graph::addHyperGraphEdge(int orig, int dest) { _hyperGraph[orig].insert(dest); }
52 
53 int Graph::edgeWeight(int node)
54 {
55  int w = 0;
56  if (node < _states) {
58  } else {
60  }
61  return w;
62 }
63 
64 int Graph::graphEdgeWeight(int node, int inf)
65 {
66  int w = 1;
67  if ((inf == node + 1) && (_wmap[node].find(node + 1) != _wmap[node].end())) {
69  } else if ((inf == node - 1) && (_wmap[node].find(node - 1) != _wmap[node].end())) {
71  } else {
72  w = edgeWeight(node);
73  }
74  return w;
75 }
76 
78 {
79  int w = 1;
80  set<int>::iterator it;
81  for (it = _hyperGraph[node].begin(); it != _hyperGraph[node].end(); ++it) {
82  if (*it != node) {
83  if ((*it == node + 1) && (_hwmap[node].find(node + 1) != _hwmap[node].end())) {
85  } else {
86  w += edgeWeight(node);
87  }
88  }
89  }
90  return w;
91 }
92 
94 {
95  int i, nvtxs = _states + _events - 1;
96  for (i = 0; i < nvtxs; i++) {
97  if (_graph[i].find(i + 1) == _graph[i].end()) {
98  _graph[i].insert(i + 1);
99  _graph[i + 1].insert(i);
100  _wmap[i].insert(i + 1);
101  _wmap[i + 1].insert(i);
102  }
103  if (_hyperGraph[i].find(i + 1) == _hyperGraph[i].end()) {
104  _hyperGraph[i].insert(i + 1);
105  _hyperGraph[i].insert(i);
106  _hwmap[i].insert(i + 1);
107  }
108  _graphEdges += _graph[i].size();
109  }
110  _graphEdges += _graph[nvtxs].size();
111 }
112 
114 
115 int Graph::graphNodeEdges(int node) { return _graph[node].size(); }
116 
117 int Graph::hyperGraphEdges() { return _hyperGraph.size(); }
118 
119 bool Graph::empty() { return _graph.empty(); }
120 
121 int Graph::nodeWeight(int node) { return _graphInputs[node].size() + _graphDiscretes[node] + 1; }
122 
123 void Graph::addNodeWeight(int node, int weight)
124 {
125  if (node >= _states) {
126  _graphDiscretes[node] = weight;
127  }
128 }
Graph::_hyperGraph
map< int, set< int > > _hyperGraph
Definition: graph.hpp:121
Graph::_graphEdges
int _graphEdges
Definition: graph.hpp:117
Graph::edgeWeight
int edgeWeight(int node)
Definition: graph.cpp:53
GRP_GraphProfile
GRP_graphProfile GRP_GraphProfile()
Definition: graph_profile.cpp:36
Graph::addNodeWeight
void addNodeWeight(int node, int weight)
Definition: graph.cpp:123
GRP_Weight
double GRP_Weight(GRP_graphProfile g, GRP_EdgeType type)
Definition: graph_profile.cpp:73
Graph::addHyperGraphEdge
void addHyperGraphEdge(int orig, int dest)
Definition: graph.cpp:51
Graph::_wmap
map< int, set< int > > _wmap
Definition: graph.hpp:122
GRP_VIRT
@ GRP_VIRT
Definition: graph_profile.hpp:40
Graph::_profile
GRP_graphProfile _profile
Definition: graph.hpp:124
Graph::_graph
map< int, set< int > > _graph
Definition: graph.hpp:118
Graph::empty
bool empty()
Definition: graph.cpp:119
Graph::graph
map< int, set< int > > graph()
Definition: graph.cpp:41
Graph::graphEdges
int graphEdges()
Definition: graph.cpp:113
GRP_CONT
@ GRP_CONT
Definition: graph_profile.hpp:40
Graph::_graphDiscretes
map< int, int > _graphDiscretes
Definition: graph.hpp:120
Graph::nodeWeight
int nodeWeight(int node)
Definition: graph.cpp:121
Graph::addGraphEdge
void addGraphEdge(int orig, int dest)
Definition: graph.cpp:45
Graph::_graphInputs
map< int, set< int > > _graphInputs
Definition: graph.hpp:119
Graph::_states
int _states
Definition: graph.hpp:114
Graph::_events
int _events
Definition: graph.hpp:115
Graph::graphNodeEdges
int graphNodeEdges(int node)
Definition: graph.cpp:115
Graph::_hwmap
map< int, set< int > > _hwmap
Definition: graph.hpp:123
Graph::graphEdgeWeight
int graphEdgeWeight(int node, int inf)
Definition: graph.cpp:64
graph.hpp
GRP_DSC
@ GRP_DSC
Definition: graph_profile.hpp:40
Graph::hyperGraphEdges
int hyperGraphEdges()
Definition: graph.cpp:117
Graph::hyperGraphEdgeWeight
int hyperGraphEdgeWeight(int node)
Definition: graph.cpp:77
Graph::Graph
Graph(int states, int events)
Definition: graph.cpp:24
Graph::connectGraphs
void connectGraphs()
Definition: graph.cpp:93
Graph::hyperGraph
map< int, set< int > > hyperGraph()
Definition: graph.cpp:43
Graph::~Graph
~Graph()
Definition: graph.cpp:39