26
26
#include <boost/foreach.hpp>
27
27
#include <boost/graph/adjacency_list.hpp>
28
#include <boost/graph/compressed_sparse_row_graph.hpp>
29
30
#include <dolfin/common/Array.h>
30
31
#include "dolfin/common/Timer.h"
35
36
using namespace dolfin;
37
38
//-----------------------------------------------------------------------------
38
dolfin::uint BoostGraphInterface::compute_local_vertex_coloring(const Graph& graph,
39
std::vector<uint>& colors)
39
std::size_t BoostGraphInterface::compute_local_vertex_coloring(const Graph& graph,
40
std::vector<std::size_t>& colors)
41
// Number of vertices in graph
42
const uint num_vertices = graph.size();
43
dolfin_assert(num_vertices == colors.size());
45
// Copy Graph data structure into a BoostGraph
46
BoostBidirectionalGraph g(num_vertices);
47
for (uint i = 0; i < graph.size(); ++i)
49
BOOST_FOREACH(boost::unordered_set<uint>::value_type edge, graph[i])
52
boost::add_edge(i, e, g);
43
const std::size_t n = graph.size();
44
dolfin_assert(n == colors.size());
46
// Typedef for Boost compressed sparse row graph
47
typedef boost::compressed_sparse_row_graph<boost::directedS> BoostGraph;
49
// Count number of edges
50
Graph::const_iterator vertex;
51
std::size_t num_edges = 0;
52
for (vertex = graph.begin(); vertex != graph.end(); ++vertex)
53
num_edges += vertex->size();
55
// Build list of graph edges
56
std::vector<std::pair<std::size_t, std::size_t> > edges;
57
edges.reserve(num_edges);
58
graph_set_type::const_iterator edge;
59
for (vertex = graph.begin(); vertex != graph.end(); ++vertex)
60
for (edge = vertex->begin(); edge != vertex->end(); ++edge)
61
edges.push_back(std::make_pair(vertex - graph.begin(), *edge));
64
BoostGraph g(boost::edges_are_unsorted_multi_pass,
65
edges.begin(), edges.end(), n);
56
67
// Perform coloring
57
68
return compute_local_vertex_coloring(g, colors);