main page
namespaces
classes
files
GGL home
Generated on Wed Apr 29 2015 11:51:40 for GGL-4.1.2 by
doxygen
1.8.3.1
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
src
sgm
Graph_Interface.hh
Go to the documentation of this file.
1
#ifndef SGM_GRAPH_INTERFACE_HH_
2
#define SGM_GRAPH_INTERFACE_HH_
3
4
#include <vector>
5
#include <string>
6
#include <memory>
7
#include <climits>
8
9
namespace
sgm {
10
11
/*! @brief Interface of graphs for graph matching
12
*
13
* The class is used as an abstract interface to allow for a generic
14
* interface of the search algorithms in the library.
15
* It describes an undirected labeled graph.
16
*
17
* @author Martin Mann (c) 2008 http://www.bioinf.uni-freiburg.de/~mmann/
18
*/
19
class
Graph_Interface
{
20
public
:
21
22
//! Type for global indicex of nodes in the graph.
23
typedef
size_t
IndexType
;
24
25
class
Edge_iterator
;
26
class
OutEdge_iterator
;
27
28
//! Container that stores the global edge information, i.e. from, to,
29
//! and the label of the edge.
30
class
EdgeDescriptor
{
31
public
:
32
//! Default Construction
33
EdgeDescriptor
();
34
35
//! Construction
36
//! @param from the source of the edge
37
//! @param to the target of the edge
38
EdgeDescriptor
(
const
Graph_Interface::IndexType
&
from
,
39
const
Graph_Interface::IndexType
&
to
);
40
41
//! Destruction
42
virtual
43
~EdgeDescriptor
();
44
45
protected
:
46
47
// define friends for direct data member access
48
friend
class
Edge_iterator
;
49
// define friends for direct data member access
50
friend
class
OutEdge_iterator
;
51
52
//! the source of the edge described
53
Graph_Interface::IndexType
from
;
54
//! the target of the edge described
55
Graph_Interface::IndexType
to
;
56
57
public
:
58
//! Access to the source of the edge.
59
//! @return the global source node index
60
const
Graph_Interface::IndexType
&
61
getFromIndex
(
void
)
const
;
62
//! Access to the target of the edge.
63
//! @return the global target node index
64
const
Graph_Interface::IndexType
&
65
getToIndex
(
void
)
const
;
66
//! Access to the label of the edge.
67
//! @return the edge label
68
virtual
69
const
std::string&
70
getEdgeLabel
(
void
)
const
= 0;
71
//! Equality comparison
72
//! @param ed the edge to compare to
73
//! @return true if both descriptors describe the same edge
74
virtual
75
bool
76
operator==
(
const
EdgeDescriptor
& ed )
const
;
77
//! Inequality comparison
78
//! @param ed the edge to compare to
79
//! @return true if both descriptors describe different edges
80
virtual
81
bool
82
operator!=
(
const
EdgeDescriptor
& ed )
const
= 0;
83
84
//! Iterator support
85
//! @return the next EdgeDescriptor in the adjacency
86
virtual
87
EdgeDescriptor
&
88
operator++
() = 0;
89
90
//! Create a heap copy of this object. NOTE: this has to be
91
//! removed by the calling function.
92
//! @return a new heap copy of this object
93
virtual
94
EdgeDescriptor
*
95
clone
()
const
= 0;
96
};
97
98
/*!
99
* Generic constant iterator class to enumerate the outgoing edges
100
* for a given node. For each out edge an EdgeDescriptor instance is
101
* provided.
102
*/
103
class
OutEdge_iterator
{
104
protected
:
105
106
//! the data object to be used for iteration. Note: the object
107
//! can be also any subclass of EdgeDescriptor.
108
std::auto_ptr< EdgeDescriptor >
data
;
109
110
public
:
111
112
//! Default construction
113
OutEdge_iterator
();
114
115
//! Construction from data
116
//! @param data the EdgeDescriptor data to use
117
OutEdge_iterator
(
const
EdgeDescriptor
&
data
);
118
119
//! Copy construction
120
//! @param toCopy the object to make this iterator a copy of
121
OutEdge_iterator
(
const
OutEdge_iterator
& toCopy );
122
123
//! Destruction
124
~OutEdge_iterator
();
125
126
//! Assign to the given iterator
127
//! @param toCopy the object to make this iterator a copy of
128
OutEdge_iterator
&
operator =
(
const
OutEdge_iterator
& toCopy);
129
130
//! Prefix increment (++I) to next element
131
OutEdge_iterator
&
operator ++
();
132
133
//! Postfix increment (I++) to next element
134
OutEdge_iterator
operator ++
(
int
);
135
136
//! access to the descriptive data of the current edge
137
//! @return the current edge data
138
const
EdgeDescriptor
&
operator *
()
const
;
139
140
//! access to the descriptive data of the current edge
141
//! @return the current edge data
142
const
EdgeDescriptor
*
const
operator ->
()
const
;
143
144
//! Equality comparison
145
//! @return true if both iterators are pointing to the same edge
146
bool
operator ==
(
const
OutEdge_iterator
& it )
const
;
147
148
//! Inequality comparison
149
//! @return true if both iterators are NOT pointing to the same edge
150
bool
operator !=
(
const
OutEdge_iterator
& it )
const
;
151
152
};
153
154
155
/*!
156
* Generic constant iterator class to enumerate the edges between two
157
* nodes. It uses the OutEdge_iterator interface to perform the
158
* enumeration. For each edge an EdgeDescriptor is provided.
159
*/
160
class
Edge_iterator
{
161
protected
:
162
163
//! The OutEdge_iterator used to enumerate the edges
164
OutEdge_iterator
curEdge
;
165
//! The OutEdge_iterator marking the end of the enumeration
166
OutEdge_iterator
edgeEnd
;
167
//! The targeted index of the edges to be reported
168
const
size_t
toIndex
;
169
170
public
:
171
172
//! Default construction
173
Edge_iterator
();
174
175
//! Construction from data
176
//! @param curEdge the begin of the outEdges to iterator
177
//! @param edgeEnd the end of the outEdges to iterator
178
//! @param toIndex the targeted index of the edges to be reported
179
Edge_iterator
(
const
OutEdge_iterator
&
curEdge
180
,
const
OutEdge_iterator
&
edgeEnd
181
,
const
IndexType
&
toIndex
);
182
183
//! Prefix increment (++I) to next element
184
Edge_iterator
&
operator ++
();
185
186
//! Postfix increment (I++) to next element
187
Edge_iterator
operator ++
(
int
);
188
189
//! access to the descriptive data of the current edge
190
//! @return the current edge data
191
const
EdgeDescriptor
&
operator *
()
const
;
192
193
//! access to the descriptive data of the current edge
194
//! @return the current edge data
195
const
EdgeDescriptor
*
const
operator ->
()
const
;
196
197
//! Equality comparison
198
//! @return true if both iterators are pointing to the same edge
199
bool
operator ==
(
const
Edge_iterator
& it )
const
;
200
201
//! Inequality comparison
202
//! @return true if both iterators are NOT pointing to the same edge
203
bool
operator !=
(
const
Edge_iterator
& it )
const
;
204
205
};
206
207
//! Destruction
208
virtual
209
~Graph_Interface
() {}
210
211
//! Access to the number of nodes of the graph
212
//! @return the overall node number
213
virtual
214
size_t
215
getNodeNumber
(
void
)
const
= 0;
216
217
//! Access to iteration begin for the edge in the adjacency list of
218
//! a specified node
219
//! @param i the index of the node of interest
220
//! @return the iterator to the first edge within the adjacency of i
221
virtual
222
OutEdge_iterator
223
getOutEdgesBegin
(
const
IndexType
& i )
const
= 0;
224
225
//! Access to iteration end for the edge in the adjacency list of
226
//! a specified node
227
//! @param i the index of the node of interest
228
//! @return the iterator the end of the adjacency iteration of i
229
virtual
230
OutEdge_iterator
231
getOutEdgesEnd
(
const
IndexType
& i )
const
= 0;
232
233
//! Access to the label of a specified node
234
//! @param i the index of the node of interest
235
//! @return a string representation of the node label
236
virtual
237
std::string
238
getNodeLabel
(
const
IndexType
& i)
const
= 0;
239
240
//! Access to the label of a specified edge
241
//! @param i the index of the first end node of interest
242
//! @param j the index of the second end node of interest
243
//! @return the edge iterator pointing to the first edge between
244
//! node i and j or to getEdgesEnd(i,j) if no edge exists
245
virtual
246
Edge_iterator
247
getEdgesBegin
(
const
IndexType
& i,
const
IndexType
& j)
const
;
248
249
//! Access to the label of a specified edge
250
//! @param i the index of the first end node of interest
251
//! @param j the index of the second end node of interest
252
//! @return the edge iterator pointing to the first edge between
253
//! node i and j or to getEdgesEnd(i,j) if no edge exists
254
virtual
255
Edge_iterator
256
getEdgesEnd
(
const
IndexType
& i,
const
IndexType
& j)
const
;
257
258
//! Interface equality comparison : NOTE : this function checks
259
//! whether the interfaces of two graphs are identical or not, i.e.
260
//! nodes with same index are equal and the order of adjacent edges
261
//! is the same. This function performs NO GRAPH ISOMORPHISM !!!
262
//! Thus, slight changes in the node order etc. will result in a
263
//! non-equal interface!
264
//! @param toCompare the Graph_Interface to compare to
265
//! @return true if both graph interfaces are equal
266
virtual
267
bool
268
operator==
(
const
Graph_Interface
& toCompare )
const
;
269
270
//! Interface inequality comparison : NOTE : this function checks
271
//! whether the interfaces of two graphs are identical or not, i.e.
272
//! nodes with same index are equal and the order of adjacent edges
273
//! is the same. This function performs NO GRAPH ISOMORPHISM !!!
274
//! Thus, slight changes in the node order etc. will result in a
275
//! non-equal interface!
276
//! @param toCompare the Graph_Interface to compare to
277
//! @return true if both graph interfaces are different
278
virtual
279
bool
280
operator!=
(
const
Graph_Interface
& toCompare )
const
;
281
282
////////////////// STATIC MEMBERS /////////////////////////////////////
283
284
typedef
std::vector<size_t>
CompLabel
;
285
286
/*!
287
* Computes the connected components of a given graph. It stores the
288
* connected component ID of each node within the provided container
289
* and returns the number of components.
290
* @param g the graph to check for connected components
291
* @param compID the container to store the component ID information
292
* within
293
* @return the number of connected components within g
294
*/
295
static
296
size_t
297
connectedComponents
(
const
Graph_Interface
& g
298
,
CompLabel
& compID );
299
300
protected
:
301
302
303
/*!
304
* Performs a depths-first-search labeling of all accessible nodes
305
* starting from curNode within g. The reached nodes are labeled
306
* with the given label in the component ID container compID
307
*
308
* @param the graph to screen
309
* @param curNode the node to start the search from
310
* @param compID the container to store the component ID information
311
* within
312
* @param label the component ID to be used for all nodes of the
313
* connected component reachable from curNode
314
*/
315
static
316
void
317
labelAdjacentNodes
(
const
Graph_Interface
& g
318
,
const
size_t
curNode
319
,
CompLabel
& compID
320
,
const
size_t
label );
321
322
};
323
324
}
// namespace sgm
325
326
327
#include <iostream>
328
#include <iomanip>
329
330
331
/*! Prints a Graph_Interface instance to stream. For each node its label and
332
* the adjancent nodes including the edge label is printed.
333
*
334
* @param out the stream to write to
335
* @param g the graph to write
336
* @return the modified out stream
337
*/
338
std::ostream&
339
operator <<
( std::ostream & out,
const
sgm::Graph_Interface
& g );
340
341
342
// include inline function bodies
343
#include "sgm/Graph_Interface.icc"
344
345
#endif
/*SGM_GRAPH_INTERFACE_HH_*/