Maximum Adjacency Search
Traverses vertices of an undirected graph, always visiting next the vertex with the most visited neighbors.
Complexity: O(E + V)
Defined in: <boost/graph/maximum_adjacency_search.hpp>
Example
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/maximum_adjacency_search.hpp>
#include <iostream>
#include <vector>
struct Edge { int weight; };
int main() {
using namespace boost;
using Graph = adjacency_list<vecS, vecS, undirectedS, no_property, Edge>;
Graph g(5);
add_edge(0, 1, Edge{2}, g);
add_edge(0, 4, Edge{3}, g);
add_edge(1, 2, Edge{3}, g);
add_edge(1, 4, Edge{2}, g);
add_edge(2, 3, Edge{4}, g);
add_edge(3, 4, Edge{1}, g);
// Bundled weight via member pointer — passed through the named parameter.
maximum_adjacency_search(g,
boost::weight_map(get(&Edge::weight, g)));
std::cout << "Maximum adjacency search completed\n";
std::cout << "Last vertex visited has highest connectivity\n";
}
Maximum adjacency search completed
Last vertex visited has highest connectivity
(1) Positional version
template <class Graph, class WeightMap, class MASVisitor>
void maximum_adjacency_search(
const Graph& g, WeightMap weights, MASVisitor vis,
const typename graph_traits<Graph>::vertex_descriptor start);
| Direction | Parameter | Description |
|---|---|---|
IN |
|
A connected, directed graph. The graph type must be a model of Incidence Graph and Vertex List Graph. |
IN |
|
The weight or length of each edge in the graph. The |
IN |
|
A visitor object that is invoked inside the algorithm at the event-points specified by the MAS Visitor concept. The visitor object is passed by value [1]. |
IN |
|
This specifies the vertex that the search should originate from. The type is the type of a vertex descriptor for the given graph. |
(2) Named parameter version
template <class Graph, class P, class T, class R>
void maximum_adjacency_search(
const Graph& g,
const bgl_named_params<P, T, R>& params);
| Direction | Parameter | Description |
|---|---|---|
IN |
|
A connected, directed graph. The graph type must be a model of Incidence Graph and Vertex List Graph. |
IN |
|
Named parameters passed via |
| Direction | Named Parameter | Description / Default |
|---|---|---|
IN |
|
The weight or length of each edge in the graph. The |
IN |
|
A visitor object that is invoked inside the algorithm at the event-points
specified by the MAS Visitor concept. The visitor object is passed by
value [1]. |
IN |
|
This specifies the vertex that the search should originate from. The type
is the type of a vertex descriptor for the given graph. |
IN |
|
This maps each vertex to an integer in the range |
UTIL |
|
|
UTIL |
|
|
UTIL |
|
This parameter only has an effect when the default max-priority queue is
used. |
UTIL |
|
This parameter only has an effect when the default max-priority queue is
used. |
Description
The maximum_adjacency_search() function performs a traversal of the
vertices in an undirected graph. The next vertex visited is the vertex
that has the most visited neighbors at any time. In the case of an
unweighted, undirected graph, the number of visited neighbors of the very
last vertex visited in the graph is also the number of edge-disjoint
paths between that vertex and the next-to-last vertex visited. These can
be retrieved from a visitor, an example of which is in the test harness
mas_test.cpp.
The maximum_adjacency_search() function invokes user-defined actions at
certain event-points within the algorithm. This provides a mechanism for
adapting the generic MAS algorithm to the many situations in which it can
be used. In the pseudo-code below, the event points for MAS are the
labels on the right. The user-defined actions must be provided in the
form of a visitor object, that is, an object whose type meets the
requirements for a MAS Visitor.
Pseudo-Code
|
|
Throws
bad_graph-
If
num_vertices(g)is less than 2. std::invalid_argument-
If a max-priority queue is given as an argument and it is not empty.
Visitor Event Points
-
vis.initialize_vertex(s, g)is invoked on every vertex of the graph before the start of the graph search. -
vis.start_vertex(s, g)is invoked on the source vertex once before processing its out edges. -
vis.examine_edge(e, g)is invoked on every out-edge of each vertex after it is started. -
vis.finish_vertex(u, g)is invoked on a vertex after all of its out edges have been examined and the reach counts of the unvisited targets have been updated.
Notes
[1] Since the visitor parameter is passed by value, if your visitor contains state then any changes to the state during the algorithm will be made to a copy of the visitor object, not the visitor object passed in. Therefore you may want the visitor to hold this state by pointer or reference.
References
-
David Matula (1993). "A linear time 2 + epsilon approximation algorithm for edge connectivity"
-
Cai, Weiqing and Matula, David W. Partitioning by maximum adjacency search of graphs. Partitioning Data Sets: Dimacs Workshop, April 19-21, 1993. Vol 19. Page 55. 1995. Amer Mathematical Society.