/usr/include/dolfin/graph/BoostGraphColoring.h is in libdolfin-dev 1.4.0+dfsg-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | // Copyright (C) 2010 Garth N. Wells
//
// This file is part of DOLFIN.
//
// DOLFIN is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// DOLFIN is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
//
// First added: 2010-11-24
// Last changed:
#ifndef __DOLFIN_BOOST_GRAPH_INTERFACE_H
#define __DOLFIN_BOOST_GRAPH_INTERFACE_H
#include <iostream>
#include <vector>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/compressed_sparse_row_graph.hpp>
#include <boost/graph/sequential_vertex_coloring.hpp>
#include <dolfin/common/Timer.h>
#include "Graph.h"
namespace dolfin
{
class Mesh;
/// This class colors a graph using the Boost Graph Library.
class BoostGraphColoring
{
public:
/// Compute vertex colors
template<typename ColorType>
static std::size_t compute_local_vertex_coloring(const Graph& graph,
std::vector<ColorType>& colors)
{
Timer timer("Boost graph coloring (from dolfin::Graph)");
// Typedef for Boost compressed sparse row graph
typedef boost::compressed_sparse_row_graph<boost::directedS,
boost::property<boost::vertex_color_t, ColorType> > BoostGraph;
// Number of vertices
const std::size_t n = graph.size();
// Count number of edges
Graph::const_iterator vertex;
std::size_t num_edges = 0;
for (vertex = graph.begin(); vertex != graph.end(); ++vertex)
num_edges += vertex->size();
// Build list of graph edges
std::vector<std::pair<std::size_t, std::size_t> > edges;
edges.reserve(num_edges);
graph_set_type::const_iterator edge;
for (vertex = graph.begin(); vertex != graph.end(); ++vertex)
{
for (edge = vertex->begin(); edge != vertex->end(); ++edge)
{
const std::size_t vertex_index = vertex - graph.begin();
if (vertex_index != *edge)
edges.push_back(std::make_pair(vertex_index, *edge));
}
}
// Build Boost graph
const BoostGraph g(boost::edges_are_unsorted_multi_pass,
edges.begin(), edges.end(), n);
// Resize vector to hold colors
colors.resize(n);
// Perform coloring
return compute_local_vertex_coloring(g, colors);
}
/// Compute vertex colors
template<typename T, typename ColorType>
static std::size_t compute_local_vertex_coloring(const T& graph,
std::vector<ColorType>& colors)
{
Timer timer("Boost graph coloring");
// Number of vertices in graph
const std::size_t num_vertices = boost::num_vertices(graph);
dolfin_assert(num_vertices == colors.size());
typedef typename boost::graph_traits<T>::vertices_size_type
vert_size_type;
typedef typename boost::property_map<T,
boost::vertex_index_t>::const_type vert_index_map;
// Resize to hold colors
colors.resize(num_vertices);
// Color vertices
std::vector<vert_size_type> _colors(num_vertices);
boost::iterator_property_map<vert_size_type*, vert_index_map>
color(&_colors.front(), get(boost::vertex_index, graph));
const vert_size_type num_colors = sequential_vertex_coloring(graph,
color);
// Coppy colors and return
std::copy(_colors.begin(), _colors.end(), colors.begin());
return num_colors;
}
};
}
#endif
|