cleaned up a few things

[SVN r8612]
This commit is contained in:
Jeremy Siek 2001-01-16 01:30:32 +00:00
parent b2fe5a80e9
commit a13ce4535a

View File

@ -1,6 +1,35 @@
/*
Adapted from the GIRTH program of the Stanford GraphBase.
Sample output:
This program explores the girth and diameter of Ramanujan graphs.
The bipartite graphs have q^3-q vertices, and the non-bipartite
graphs have half that number. Each vertex has degree p+1.
Both p and q should be odd prime numbers;
or you can try p = 2 with q = 17 or 43.
Choose a branching factor, p: 2
Ok, now choose the cube root of graph size, q: 17
Starting at any given vertex, there are
3 vertices at distance 1,
6 vertices at distance 2,
12 vertices at distance 3,
24 vertices at distance 4,
46 vertices at distance 5,
90 vertices at distance 6,
169 vertices at distance 7,
290 vertices at distance 8,
497 vertices at distance 9,
634 vertices at distance 10,
521 vertices at distance 11,
138 vertices at distance 12,
13 vertices at distance 13,
3 vertices at distance 14,
1 vertices at distance 15.
So the diameter is 15, and the girth is 9.
*/
#include <boost/config.hpp>
@ -17,7 +46,7 @@ typedef Traits::vertex_descriptor vertex_descriptor;
typedef Traits::edge_descriptor edge_descriptor;
typedef Traits::vertex_iterator vertex_iterator;
std::vector< std::list<vertex_descriptor> > distance_list;
std::vector<std::size_t> distance_list;
typedef boost::v_property<long> dist_t;
boost::property_map<Graph*, dist_t>::type distance;
@ -40,20 +69,22 @@ public:
diameter_and_girth_visitor(std::size_t& k_, std::size_t& girth_)
: k(k_), girth(girth_) { }
void examine_edge(edge_descriptor e, Graph* g) {
assert(source(e, g) != target(e, g));
}
void tree_edge(edge_descriptor e, Graph* g) {
vertex_descriptor u, v;
boost::tie(u, v) = incident(e, g);
vertex_descriptor u = source(e, g), v = target(e, g);
k = distance[u] + 1;
distance[v] = k;
distance_list[k].push_back(v);
++distance_list[k];
predecessor[v] = u;
}
void cycle_edge(edge_descriptor e, Graph* g) {
vertex_descriptor u, v;
boost::tie(u, v) = incident(e, g);
vertex_descriptor u = source(e, g), v = target(e, g);
k = distance[u] + 1;
if (distance[v] + k < girth && v != predecessor[u])
girth = distance[v] + k;
girth = distance[v]+ k;
}
private:
std::size_t& k;
@ -97,7 +128,7 @@ main()
continue;
}
distance_list.clear();
distance_list.resize(boost::num_vertices(g));
distance_list.resize(boost::num_vertices(g), 0);
distance = get(dist_t(), g);
predecessor = get(pred_t(), g);
@ -118,9 +149,9 @@ main()
std::cout << "Starting at any given vertex, there are" << std::endl;
for (long d = 1; !distance_list[d].empty(); ++d)
std::cout << distance_list[d].size() << " vertices at distance " << d
<< (!distance_list[d+1].empty() ? "," : ".") << std::endl;
for (long d = 1; distance_list[d] != 0; ++d)
std::cout << distance_list[d] << " vertices at distance " << d
<< (distance_list[d+1] != 0 ? "," : ".") << std::endl;
std::cout << "So the diameter is " << k - 1
<< ", and the girth is " << girth