2
0
mirror of https://github.com/boostorg/graph.git synced 2026-01-31 08:12:14 +00:00

concept checking changes, and usage of concept changes

[SVN r8305]
This commit is contained in:
Jeremy Siek
2000-11-22 19:17:36 +00:00
parent f7f4e4ca0c
commit 644a810441
11 changed files with 109 additions and 65 deletions

View File

@@ -49,7 +49,8 @@ main(int,char*[])
typedef graph_traits<Graph>::vertex_descriptor Vertex;
typedef graph_traits<Graph>::edge_descriptor Edge;
function_requires< VertexAndEdgeListGraphConcept<Graph> >();
function_requires< MutableGraphConcept<Graph> >();
function_requires< MutableIncidenceGraphConcept<Graph> >();
function_requires< MutableEdgeListGraphConcept<Graph> >();
function_requires< PropertyGraphConcept<Graph, Vertex, vertex_color_t> >();
function_requires< PropertyGraphConcept<Graph, Edge, edge_weight_t> >();
// the builtin id property is readable but not writable
@@ -66,7 +67,8 @@ main(int,char*[])
typedef graph_traits<Graph>::edge_descriptor Edge;
function_requires< VertexAndEdgeListGraphConcept<Graph> >();
function_requires< BidirectionalGraphConcept<Graph> >();
function_requires< MutableGraphConcept<Graph> >();
function_requires< MutableBidirectionalGraphConcept<Graph> >();
function_requires< MutableEdgeListGraphConcept<Graph> >();
function_requires< PropertyGraphConcept<Graph, Vertex, vertex_color_t> >();
function_requires< PropertyGraphConcept<Graph, Edge, edge_weight_t> >();
// the builtin id property is readable but not writable
@@ -81,7 +83,8 @@ main(int,char*[])
typedef graph_traits<Graph>::vertex_descriptor Vertex;
typedef graph_traits<Graph>::edge_descriptor Edge;
function_requires< VertexAndEdgeListGraphConcept<Graph> >();
function_requires< MutableGraphConcept<Graph> >();
function_requires< MutableIncidenceGraphConcept<Graph> >();
function_requires< MutableEdgeListGraphConcept<Graph> >();
function_requires< PropertyGraphConcept<Graph, Vertex, vertex_color_t> >();
function_requires< PropertyGraphConcept<Graph, Edge, edge_weight_t> >();
}
@@ -93,7 +96,8 @@ main(int,char*[])
typedef graph_traits<Graph>::vertex_descriptor Vertex;
typedef graph_traits<Graph>::edge_descriptor Edge;
function_requires< VertexAndEdgeListGraphConcept<Graph> >();
function_requires< MutableGraphConcept<Graph> >();
function_requires< MutableBidirectionalGraphConcept<Graph> >();
function_requires< MutableEdgeListGraphConcept<Graph> >();
function_requires< PropertyGraphConcept<Graph, Vertex, vertex_color_t> >();
function_requires< PropertyGraphConcept<Graph, Edge, edge_weight_t> >();
}

View File

@@ -73,7 +73,7 @@ int main(int , char* [])
property< vertex_finish_time_t, int,
property< vertex_color_t, default_color_type > > > VertexProperty;
typedef adjacency_list <vecS, vecS, undirectedS, VertexProperty> Graph;
typedef Graph::vertex_descriptor Vertex;
typedef graph_traits<Graph>::vertex_descriptor Vertex;
Graph G;
add_edge(0, 1, G);
@@ -111,7 +111,7 @@ int main(int , char* [])
add_edge(3, 0, G);
add_edge(5, 2, G);
typedef Graph::vertex_descriptor Vertex;
typedef graph_traits<Graph>::vertex_descriptor Vertex;
std::vector<int> c(num_vertices(G));
int num = connected_components(G, &c[0], get(vertex_color, G),

View File

@@ -110,15 +110,15 @@ main()
{
typedef boost::adjacency_list<> IteratorConstructibleGraph;
typedef boost::graph_traits<IteratorConstructibleGraph> Traits;
Traits::vertices_size_type V;
Traits::edges_size_type E;
Traits::vertices_size_type size_V;
Traits::edges_size_type size_E;
std::ifstream f("edge_iterator_constructor.dat");
f >> V >> E;
f >> size_V >> size_E;
edge_stream_iterator edge_iter(f), end;
IteratorConstructibleGraph G(V, edge_iter, end);
IteratorConstructibleGraph G(size_V, edge_iter, end);
boost::print_graph(G);
return 0;

View File

@@ -75,21 +75,15 @@ struct print_visitor : public bfs_visitor<> {
};
template <class Color>
struct cycle_detector : public dfs_visitor<>
{
typedef typename boost::property_traits<Color>::value_type C;
cycle_detector(Color c, bool& has_cycle)
: _has_cycle(has_cycle), color(c) { }
cycle_detector(bool& has_cycle)
: m_has_cycle(has_cycle) { }
template <class Edge, class Graph>
void back_edge(Edge e, Graph& g) {
_has_cycle = true;
}
void back_edge(Edge e, Graph& g) { m_has_cycle = true; }
protected:
bool& _has_cycle;
Color color;
bool& m_has_cycle;
};
int main(int,char*[])
@@ -124,7 +118,6 @@ int main(int,char*[])
typedef graph_traits<Graph>::vertex_descriptor Vertex;
typedef property_map<Graph, vertex_color_t>::type Color;
Color color = get(vertex_color, g);
// Determine ordering for a full recompilation
{
@@ -185,7 +178,7 @@ int main(int,char*[])
// are there any cycles in the graph?
{
bool has_cycle = false;
cycle_detector<Color> vis(color, has_cycle);
cycle_detector vis(has_cycle);
depth_first_search(g, vis);
cout << "The graph has a cycle? " << has_cycle << endl;
}
@@ -201,9 +194,8 @@ int main(int,char*[])
// are there any cycles in the graph?
{
typedef property_map<Graph,vertex_color_t>::type Color;
Color color = get(vertex_color, g);
bool has_cycle = false;
cycle_detector<Color> vis(color, has_cycle);
cycle_detector vis(has_cycle);
depth_first_search(g, vis);
cout << "The graph has a cycle now? " << has_cycle << endl;
}

View File

@@ -73,7 +73,7 @@ main()
6 };
int* wp = weights;
Graph::edge_iterator e,e_end;
graph_traits<Graph>::edge_iterator e,e_end;
for (boost::tie(e,e_end) = edges(g); e != e_end; ++e)
w[*e] = *wp++;

View File

@@ -38,7 +38,7 @@
namespace boost {
template <class Visitor, class Graph>
struct BellmanFordVisitor_concept {
struct BellmanFordVisitorConcept {
void constraints() {
vis.examine_edge(e, g);
vis.edge_relaxed(e, g);
@@ -104,12 +104,12 @@ namespace boost {
typedef typename graph_traits<EdgeListGraph>::edge_descriptor Edge;
typedef typename graph_traits<EdgeListGraph>::vertex_descriptor
Vertex;
BOOST_FUNCTION_REQUIRES2(DistanceMap, Vertex, ReadWritePropertyMapConcept);
BOOST_FUNCTION_REQUIRES2(WeightMap, Edge, ReadablePropertyMapConcept);
function_requires<ReadWritePropertyMapConcept<DistanceMap, Vertex> >();
function_requires<ReadablePropertyMapConcept<WeightMap, Edge> >();
typedef typename property_traits<DistanceMap>::value_type D_value;
typedef typename property_traits<WeightMap>::value_type W_value;
BOOST_FUNCTION_REQUIRES(D_value, ComparableConcept);
BOOST_FUNCTION_REQUIRES3(D_value, D_value, W_value, PlusOpConcept);
function_requires<ComparableConcept<D_value> >();
function_requires<PlusOpConcept<D_value, D_value, W_value> >();
std::plus<D_value> combine;
std::less<D_value> compare;
return bellman_ford_shortest_paths(g, N, weight, distance,
@@ -126,12 +126,12 @@ namespace boost {
BinaryPredicate compare,
BellmanFordVisitor v)
{
BOOST_FUNCTION_REQUIRES(EdgeListGraph, EdgeListGraphConcept);
function_requires<EdgeListGraphConcept<EdgeListGraph> >();
typedef graph_traits<EdgeListGraph> GTraits;
typedef typename GTraits::edge_descriptor Edge;
typedef typename GTraits::vertex_descriptor Vertex;
BOOST_FUNCTION_REQUIRES2(DistanceMap, Vertex, ReadWritePropertyMapConcept);
BOOST_FUNCTION_REQUIRES2(WeightMap, Edge, ReadablePropertyMapConcept);
function_requires<ReadWritePropertyMapConcept<DistanceMap, Vertex> >();
function_requires<ReadablePropertyMapConcept<WeightMap, Edge> >();
typedef typename property_traits<DistanceMap>::value_type D_value;
typedef typename property_traits<WeightMap>::value_type W_value;

View File

@@ -39,7 +39,7 @@
namespace boost {
template <class Visitor, class Graph>
struct BFSVisitor_concept {
struct BFSVisitorConcept {
void constraints() {
vis.initialize_vertex(u, g);
vis.start_vertex(u, g);
@@ -91,12 +91,12 @@ namespace boost {
typename graph_traits<IncidenceGraph>::vertex_descriptor s,
Buffer& Q, BFSVisitor vis, ColorMap color)
{
BOOST_FUNCTION_REQUIRES(IncidenceGraph, IncidenceGraphConcept);
function_requires< IncidenceGraphConcept<IncidenceGraph> >();
typedef graph_traits<IncidenceGraph> GTraits;
typedef typename GTraits::vertex_descriptor Vertex;
typedef typename GTraits::edge_descriptor Edge;
BOOST_FUNCTION_REQUIRES2(BFSVisitor, IncidenceGraph, BFSVisitorConcept);
BOOST_FUNCTION_REQUIRES2(ColorMap, Vertex, ReadWritePropertyMapConcept);
function_requires< BFSVisitorConcept<BFSVisitor, IncidenceGraph> >();
function_requires< ReadWritePropertyMapConcept<ColorMap, Vertex> >();
typename property_traits<ColorMap>::value_type c = get(color, s);
put(color, s, gray(c));
@@ -106,8 +106,7 @@ namespace boost {
Vertex u = Q.top();
Q.pop(); // pop before push to avoid problem if Q is priority_queue.
vis.discover_vertex(u, g);
typename boost::GTraits::out_edge_iterator
ei, ei_end;
typename GTraits::out_edge_iterator ei, ei_end;
for (tie(ei, ei_end) = out_edges(u, g); ei != ei_end; ++ei) {
Edge e = *ei;
vis.examine_edge(e, g);

View File

@@ -37,7 +37,7 @@
namespace boost {
template <class Visitor, class Graph>
class DFSVisitor_concept {
class DFSVisitorConcept {
public:
void constraints() {
vis.initialize_vertex(u, g);
@@ -70,7 +70,7 @@ namespace boost {
void
depth_first_search(VertexListGraph& g, DFSVisitor vis, ColorMap color)
{
BOOST_FUNCTION_REQUIRES2(DFSVisitor, VertexListGraph, DFSVisitorConcept);
function_requires<DFSVisitorConcept<DFSVisitor, VertexListGraph> >();
typename property_traits<ColorMap>::value_type
c = get(color, *vertices(g).first); // value of c not used, just type
@@ -91,8 +91,8 @@ namespace boost {
typename graph_traits<IncidenceGraph>::vertex_descriptor u,
DFSVisitor& vis, ColorMap color)
{
BOOST_FUNCTION_REQUIRES(IncidenceGraph, IncidenceGraphConcept);
BOOST_FUNCTION_REQUIRES2(DFSVisitor, IncidenceGraph, DFSVisitorConcept);
function_requires<IncidenceGraphConcept<IncidenceGraph> >();
function_requires<DFSVisitorConcept<DFSVisitor, IncidenceGraph> >();
typename property_traits<ColorMap>::value_type c = get(color, u);
put(color, u, gray(c));

View File

@@ -210,9 +210,8 @@ namespace boost {
clear_vertex(v, g);
remove_vertex(v, g);
p = add_edge(u, v, g);
remove_edge(u, v, g);
remove_edge(u, v, g); // Hmm, maybe this shouldn't be here...
remove_edge(e, g);
remove_edge(iter, g);
}
G g;
edge_descriptor e;
@@ -221,6 +220,53 @@ namespace boost {
typename graph_traits<G>::out_edge_iterator iter;
};
template <class edge_descriptor>
struct dummy_edge_predicate {
bool operator()(const edge_descriptor& e) const {
return false;
}
};
template <class G>
struct MutableIncidenceGraphConcept
{
void constraints() {
function_requires< MutableGraphConcept<G> >();
remove_edge(iter, g);
remove_out_edge_if(u, p, g);
}
G g;
typedef typename graph_traits<G>::edge_descriptor edge_descriptor;
dummy_edge_predicate<edge_descriptor> p;
typename boost::graph_traits<G>::vertex_descriptor u;
typename boost::graph_traits<G>::out_edge_iterator iter;
};
template <class G>
struct MutableBidirectionalGraphConcept
{
void constraints() {
function_requires< MutableIncidenceGraphConcept<G> >();
remove_in_edge_if(u, p, g);
}
G g;
typedef typename graph_traits<G>::edge_descriptor edge_descriptor;
dummy_edge_predicate<edge_descriptor> p;
typename boost::graph_traits<G>::vertex_descriptor u;
};
template <class G>
struct MutableEdgeListGraphConcept
{
void constraints() {
function_requires< MutableGraphConcept<G> >();
remove_edge_if(p, g);
}
G g;
typedef typename graph_traits<G>::edge_descriptor edge_descriptor;
dummy_edge_predicate<edge_descriptor> p;
};
template <class G>
struct MutablePropertyGraphConcept
{

View File

@@ -76,17 +76,17 @@ namespace boost {
{
typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
typedef typename graph_traits<Graph>::edge_descriptor Edge;
REQUIRE(Graph, VertexAndEdgeListGraph);
REQUIRE2(OutputIterator, Edge, OutputIterator);
REQUIRE2(Rank, Vertex, ReadWritePropertyMap);
REQUIRE2(Parent, Vertex, ReadWritePropertyMap);
REQUIRE2(Weight, Edge, ReadablePropertyMap);
function_requires<VertexAndEdgeListGraphConcept<Graph> >();
function_requires<OutputIteratorConcept<OutputIterator, Edge> >();
function_requires<ReadWritePropertyMapConcept<Rank, Vertex> >();
function_requires<ReadWritePropertyMapConcept<Parent, Vertex> >();
function_requires<ReadablePropertyMapConcept<Weight, Edge> >();
typedef typename property_traits<Weight>::value_type W_value;
typedef typename property_traits<Rank>::value_type R_value;
typedef typename property_traits<Parent>::value_type P_value;
REQUIRE(W_value, LessThanComparable);
REQUIRE2(P_value, Vertex, Convertible);
REQUIRE(R_value, Integer);
function_requires<LessThanComparableConcept<W_value> >();
function_requires<ConvertibleConcept<P_value, Vertex> >();
function_requires<IntegerConcept<R_value> >();
disjoint_sets<Rank, Parent> dset(rank, parent);

View File

@@ -41,7 +41,7 @@
namespace boost {
template <class Visitor, class Graph>
struct UniformCostVisitor_concept {
struct UniformCostVisitorConcept {
void constraints() {
vis.start_vertex(u, g);
vis.initialize_vertex(u, g);
@@ -125,7 +125,7 @@ namespace boost {
m_vis.initialize_vertex(u, g);
}
template <class Vertex, class Graph>
void start_vertex(Vertex v, Graph& g) {
void start_vertex(Vertex u, Graph& g) {
m_vis.start_vertex(u, g);
}
template <class Vertex, class Graph>
@@ -187,22 +187,25 @@ namespace boost {
BinaryPredicate compare, BinaryFunction combine,
UniformCostVisitor vis)
{
REQUIRE(VertexListGraph, VertexListGraph);
function_requires<VertexListGraphConcept<VertexListGraph> >();
typedef typename graph_traits<VertexListGraph>::vertex_descriptor Vertex;
typedef typename graph_traits<VertexListGraph>::edge_descriptor Edge;
REQUIRE2(ColorMap, Vertex, ReadWritePropertyMap);
REQUIRE2(DistanceMap, Vertex, ReadWritePropertyMap);
REQUIRE2(WeightMap, Edge, ReadablePropertyMap);
REQUIRE2(IndexMap, Vertex, ReadablePropertyMap);
function_requires<ReadWritePropertyMapConcept<ColorMap, Vertex> >();
function_requires<ReadWritePropertyMapConcept<DistanceMap, Vertex> >();
function_requires<ReadablePropertyMapConcept<WeightMap, Edge> >();
function_requires<ReadablePropertyMapConcept<IndexMap, Vertex> >();
typedef typename property_traits<DistanceMap>::value_type D_value;
typedef typename property_traits<WeightMap>::value_type W_value;
typedef typename property_traits<IndexMap>::value_type ID_value;
typedef typename property_traits<ColorMap>::value_type Color_value;
REQUIRE(Color_value, ColorValue);
REQUIRE3(BinaryPredicate, D_value, D_value, BinaryPredicate);
REQUIRE4(BinaryFunction, D_value, D_value, W_value, BinaryFunction);
REQUIRE(ID_value, Integer);
REQUIRE2(UniformCostVisitor, VertexListGraph, UniformCostVisitor);
function_requires<ColorValueConcept<Color_value> >();
function_requires<BinaryPredicateConcept
<BinaryPredicate, D_value, D_value> >();
function_requires<BinaryFunctionConcept
<BinaryFunction, D_value, D_value, W_value> >();
function_requires<IntegerConcept<ID_value> >();
function_requires<UniformCostVisitorConcept
<UniformCostVisitor, VertexListGraph> >();
typedef indirect_cmp<DistanceMap, BinaryPredicate> IndirectCmp;
IndirectCmp icmp(d, compare);