File indexing completed on 2025-01-18 09:37:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef BOOST_GRAPH_CONCEPTS_HPP
0014 #define BOOST_GRAPH_CONCEPTS_HPP
0015
0016 #include <boost/config.hpp>
0017 #include <boost/property_map/property_map.hpp>
0018 #include <boost/graph/graph_traits.hpp>
0019 #include <boost/graph/properties.hpp>
0020 #include <boost/graph/numeric_values.hpp>
0021 #include <boost/graph/buffer_concepts.hpp>
0022 #include <boost/concept_check.hpp>
0023 #include <boost/type_traits/is_same.hpp>
0024 #include <boost/mpl/not.hpp>
0025 #include <boost/static_assert.hpp>
0026 #include <boost/detail/workaround.hpp>
0027 #include <boost/concept/assert.hpp>
0028
0029 #include <boost/concept/detail/concept_def.hpp>
0030 namespace boost
0031 {
0032
0033
0034
0035
0036
0037
0038
0039
0040 #if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) \
0041 && !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
0042 #define BOOST_VECTOR_AS_GRAPH_GRAPH_ADL_HACK
0043 #endif
0044
0045 #ifdef BOOST_VECTOR_AS_GRAPH_GRAPH_ADL_HACK
0046 template < class T >
0047 typename T::ThereReallyIsNoMemberByThisNameInT vertices(T const&);
0048 #endif
0049
0050 namespace concepts
0051 {
0052 BOOST_concept(MultiPassInputIterator, (T)) { BOOST_CONCEPT_USAGE(
0053 MultiPassInputIterator) { BOOST_CONCEPT_ASSERT((InputIterator< T >));
0054 }
0055 };
0056
0057 BOOST_concept(Graph, (G))
0058 {
0059 typedef typename graph_traits< G >::vertex_descriptor vertex_descriptor;
0060 typedef typename graph_traits< G >::edge_descriptor edge_descriptor;
0061 typedef typename graph_traits< G >::directed_category directed_category;
0062 typedef typename graph_traits< G >::edge_parallel_category
0063 edge_parallel_category;
0064 typedef typename graph_traits< G >::traversal_category traversal_category;
0065
0066 BOOST_CONCEPT_USAGE(Graph)
0067 {
0068 BOOST_CONCEPT_ASSERT((DefaultConstructible< vertex_descriptor >));
0069 BOOST_CONCEPT_ASSERT((EqualityComparable< vertex_descriptor >));
0070 BOOST_CONCEPT_ASSERT((Assignable< vertex_descriptor >));
0071 }
0072 G g;
0073 };
0074
0075 BOOST_concept(IncidenceGraph, (G)) : Graph< G >
0076 {
0077 typedef typename graph_traits< G >::edge_descriptor edge_descriptor;
0078 typedef typename graph_traits< G >::out_edge_iterator out_edge_iterator;
0079 typedef typename graph_traits< G >::degree_size_type degree_size_type;
0080 typedef typename graph_traits< G >::traversal_category traversal_category;
0081
0082 BOOST_STATIC_ASSERT(
0083 (boost::mpl::not_< boost::is_same< out_edge_iterator, void > >::value));
0084 BOOST_STATIC_ASSERT(
0085 (boost::mpl::not_< boost::is_same< degree_size_type, void > >::value));
0086
0087 BOOST_CONCEPT_USAGE(IncidenceGraph)
0088 {
0089 BOOST_CONCEPT_ASSERT((MultiPassInputIterator< out_edge_iterator >));
0090 BOOST_CONCEPT_ASSERT((DefaultConstructible< edge_descriptor >));
0091 BOOST_CONCEPT_ASSERT((EqualityComparable< edge_descriptor >));
0092 BOOST_CONCEPT_ASSERT((Assignable< edge_descriptor >));
0093 BOOST_CONCEPT_ASSERT(
0094 (Convertible< traversal_category, incidence_graph_tag >));
0095
0096 p = out_edges(u, g);
0097 n = out_degree(u, g);
0098 e = *p.first;
0099 u = source(e, g);
0100 v = target(e, g);
0101 const_constraints(g);
0102 }
0103 void const_constraints(const G& cg)
0104 {
0105 p = out_edges(u, cg);
0106 n = out_degree(u, cg);
0107 e = *p.first;
0108 u = source(e, cg);
0109 v = target(e, cg);
0110 }
0111 std::pair< out_edge_iterator, out_edge_iterator > p;
0112 typename graph_traits< G >::vertex_descriptor u, v;
0113 typename graph_traits< G >::edge_descriptor e;
0114 typename graph_traits< G >::degree_size_type n;
0115 G g;
0116 };
0117
0118 BOOST_concept(BidirectionalGraph, (G)) : IncidenceGraph< G >
0119 {
0120 typedef typename graph_traits< G >::in_edge_iterator in_edge_iterator;
0121 typedef typename graph_traits< G >::traversal_category traversal_category;
0122
0123 BOOST_CONCEPT_USAGE(BidirectionalGraph)
0124 {
0125 BOOST_CONCEPT_ASSERT((MultiPassInputIterator< in_edge_iterator >));
0126 BOOST_CONCEPT_ASSERT(
0127 (Convertible< traversal_category, bidirectional_graph_tag >));
0128
0129 BOOST_STATIC_ASSERT((boost::mpl::not_<
0130 boost::is_same< in_edge_iterator, void > >::value));
0131
0132 p = in_edges(v, g);
0133 n = in_degree(v, g);
0134 n = degree(v, g);
0135 e = *p.first;
0136 const_constraints(g);
0137 }
0138 void const_constraints(const G& cg)
0139 {
0140 p = in_edges(v, cg);
0141 n = in_degree(v, cg);
0142 n = degree(v, cg);
0143 e = *p.first;
0144 }
0145 std::pair< in_edge_iterator, in_edge_iterator > p;
0146 typename graph_traits< G >::vertex_descriptor v;
0147 typename graph_traits< G >::edge_descriptor e;
0148 typename graph_traits< G >::degree_size_type n;
0149 G g;
0150 };
0151
0152 BOOST_concept(AdjacencyGraph, (G)) : Graph< G >
0153 {
0154 typedef typename graph_traits< G >::adjacency_iterator adjacency_iterator;
0155 typedef typename graph_traits< G >::traversal_category traversal_category;
0156
0157 BOOST_CONCEPT_USAGE(AdjacencyGraph)
0158 {
0159 BOOST_CONCEPT_ASSERT((MultiPassInputIterator< adjacency_iterator >));
0160 BOOST_CONCEPT_ASSERT(
0161 (Convertible< traversal_category, adjacency_graph_tag >));
0162
0163 BOOST_STATIC_ASSERT((boost::mpl::not_<
0164 boost::is_same< adjacency_iterator, void > >::value));
0165
0166 p = adjacent_vertices(v, g);
0167 v = *p.first;
0168 const_constraints(g);
0169 }
0170 void const_constraints(const G& cg) { p = adjacent_vertices(v, cg); }
0171 std::pair< adjacency_iterator, adjacency_iterator > p;
0172 typename graph_traits< G >::vertex_descriptor v;
0173 G g;
0174 };
0175
0176 BOOST_concept(VertexListGraph, (G)) : Graph< G >
0177 {
0178 typedef typename graph_traits< G >::vertex_iterator vertex_iterator;
0179 typedef typename graph_traits< G >::vertices_size_type vertices_size_type;
0180 typedef typename graph_traits< G >::traversal_category traversal_category;
0181
0182 BOOST_CONCEPT_USAGE(VertexListGraph)
0183 {
0184 BOOST_CONCEPT_ASSERT((MultiPassInputIterator< vertex_iterator >));
0185 BOOST_CONCEPT_ASSERT(
0186 (Convertible< traversal_category, vertex_list_graph_tag >));
0187
0188 BOOST_STATIC_ASSERT((boost::mpl::not_<
0189 boost::is_same< vertex_iterator, void > >::value));
0190 BOOST_STATIC_ASSERT((boost::mpl::not_<
0191 boost::is_same< vertices_size_type, void > >::value));
0192
0193 #ifdef BOOST_VECTOR_AS_GRAPH_GRAPH_ADL_HACK
0194
0195
0196
0197
0198
0199 using boost::vertices;
0200 #endif
0201 p = vertices(g);
0202 v = *p.first;
0203 const_constraints(g);
0204 }
0205 void const_constraints(const G& cg)
0206 {
0207 #ifdef BOOST_VECTOR_AS_GRAPH_GRAPH_ADL_HACK
0208
0209
0210
0211
0212
0213 using boost::vertices;
0214 #endif
0215
0216 p = vertices(cg);
0217 v = *p.first;
0218 V = num_vertices(cg);
0219 }
0220 std::pair< vertex_iterator, vertex_iterator > p;
0221 typename graph_traits< G >::vertex_descriptor v;
0222 G g;
0223 vertices_size_type V;
0224 };
0225
0226 BOOST_concept(EdgeListGraph, (G)) : Graph< G >
0227 {
0228 typedef typename graph_traits< G >::edge_descriptor edge_descriptor;
0229 typedef typename graph_traits< G >::edge_iterator edge_iterator;
0230 typedef typename graph_traits< G >::edges_size_type edges_size_type;
0231 typedef typename graph_traits< G >::traversal_category traversal_category;
0232
0233 BOOST_CONCEPT_USAGE(EdgeListGraph)
0234 {
0235 BOOST_CONCEPT_ASSERT((MultiPassInputIterator< edge_iterator >));
0236 BOOST_CONCEPT_ASSERT((DefaultConstructible< edge_descriptor >));
0237 BOOST_CONCEPT_ASSERT((EqualityComparable< edge_descriptor >));
0238 BOOST_CONCEPT_ASSERT((Assignable< edge_descriptor >));
0239 BOOST_CONCEPT_ASSERT(
0240 (Convertible< traversal_category, edge_list_graph_tag >));
0241
0242 BOOST_STATIC_ASSERT(
0243 (boost::mpl::not_< boost::is_same< edge_iterator, void > >::value));
0244 BOOST_STATIC_ASSERT((boost::mpl::not_<
0245 boost::is_same< edges_size_type, void > >::value));
0246
0247 p = edges(g);
0248 e = *p.first;
0249 u = source(e, g);
0250 v = target(e, g);
0251 const_constraints(g);
0252 }
0253 void const_constraints(const G& cg)
0254 {
0255 p = edges(cg);
0256 E = num_edges(cg);
0257 e = *p.first;
0258 u = source(e, cg);
0259 v = target(e, cg);
0260 }
0261 std::pair< edge_iterator, edge_iterator > p;
0262 typename graph_traits< G >::vertex_descriptor u, v;
0263 typename graph_traits< G >::edge_descriptor e;
0264 edges_size_type E;
0265 G g;
0266 };
0267
0268 BOOST_concept(VertexAndEdgeListGraph, (G))
0269 : VertexListGraph< G >, EdgeListGraph< G > {};
0270
0271
0272
0273
0274
0275 BOOST_concept(EdgeMutableGraph, (G))
0276 {
0277 typedef typename graph_traits< G >::edge_descriptor edge_descriptor;
0278
0279 BOOST_CONCEPT_USAGE(EdgeMutableGraph)
0280 {
0281 p = add_edge(u, v, g);
0282 remove_edge(u, v, g);
0283 remove_edge(e, g);
0284 clear_vertex(v, g);
0285 }
0286 G g;
0287 edge_descriptor e;
0288 std::pair< edge_descriptor, bool > p;
0289 typename graph_traits< G >::vertex_descriptor u, v;
0290 };
0291
0292 BOOST_concept(VertexMutableGraph, (G))
0293 {
0294
0295 BOOST_CONCEPT_USAGE(VertexMutableGraph)
0296 {
0297 v = add_vertex(g);
0298 remove_vertex(v, g);
0299 }
0300 G g;
0301 typename graph_traits< G >::vertex_descriptor u, v;
0302 };
0303
0304 BOOST_concept(MutableGraph, (G))
0305 : EdgeMutableGraph< G >, VertexMutableGraph< G > {};
0306
0307 template < class edge_descriptor > struct dummy_edge_predicate
0308 {
0309 bool operator()(const edge_descriptor&) const { return false; }
0310 };
0311
0312 BOOST_concept(MutableIncidenceGraph, (G)) : MutableGraph< G >
0313 {
0314 BOOST_CONCEPT_USAGE(MutableIncidenceGraph)
0315 {
0316 remove_edge(iter, g);
0317 remove_out_edge_if(u, p, g);
0318 }
0319 G g;
0320 typedef typename graph_traits< G >::edge_descriptor edge_descriptor;
0321 dummy_edge_predicate< edge_descriptor > p;
0322 typename boost::graph_traits< G >::vertex_descriptor u;
0323 typename boost::graph_traits< G >::out_edge_iterator iter;
0324 };
0325
0326 BOOST_concept(MutableBidirectionalGraph, (G)) : MutableIncidenceGraph< G >
0327 {
0328 BOOST_CONCEPT_USAGE(MutableBidirectionalGraph)
0329 {
0330 remove_in_edge_if(u, p, g);
0331 }
0332 G g;
0333 typedef typename graph_traits< G >::edge_descriptor edge_descriptor;
0334 dummy_edge_predicate< edge_descriptor > p;
0335 typename boost::graph_traits< G >::vertex_descriptor u;
0336 };
0337
0338 BOOST_concept(MutableEdgeListGraph, (G)) : EdgeMutableGraph< G >
0339 {
0340 BOOST_CONCEPT_USAGE(MutableEdgeListGraph) { remove_edge_if(p, g); }
0341 G g;
0342 typedef typename graph_traits< G >::edge_descriptor edge_descriptor;
0343 dummy_edge_predicate< edge_descriptor > p;
0344 };
0345
0346 BOOST_concept(VertexMutablePropertyGraph, (G)) : VertexMutableGraph< G >
0347 {
0348 BOOST_CONCEPT_USAGE(VertexMutablePropertyGraph) { v = add_vertex(vp, g); }
0349 G g;
0350 typename graph_traits< G >::vertex_descriptor v;
0351 typename vertex_property_type< G >::type vp;
0352 };
0353
0354 BOOST_concept(EdgeMutablePropertyGraph, (G)) : EdgeMutableGraph< G >
0355 {
0356 typedef typename graph_traits< G >::edge_descriptor edge_descriptor;
0357
0358 BOOST_CONCEPT_USAGE(EdgeMutablePropertyGraph) { p = add_edge(u, v, ep, g); }
0359 G g;
0360 std::pair< edge_descriptor, bool > p;
0361 typename graph_traits< G >::vertex_descriptor u, v;
0362 typename edge_property_type< G >::type ep;
0363 };
0364
0365 BOOST_concept(AdjacencyMatrix, (G)) : Graph< G >
0366 {
0367 typedef typename graph_traits< G >::edge_descriptor edge_descriptor;
0368
0369 BOOST_CONCEPT_USAGE(AdjacencyMatrix)
0370 {
0371 p = edge(u, v, g);
0372 const_constraints(g);
0373 }
0374 void const_constraints(const G& cg) { p = edge(u, v, cg); }
0375 typename graph_traits< G >::vertex_descriptor u, v;
0376 std::pair< edge_descriptor, bool > p;
0377 G g;
0378 };
0379
0380 BOOST_concept(ReadablePropertyGraph, (G)(X)(Property)) : Graph< G >
0381 {
0382 typedef typename property_map< G, Property >::const_type const_Map;
0383
0384 BOOST_CONCEPT_USAGE(ReadablePropertyGraph)
0385 {
0386 BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept< const_Map, X >));
0387
0388 const_constraints(g);
0389 }
0390 void const_constraints(const G& cg)
0391 {
0392 const_Map pmap = get(Property(), cg);
0393 pval = get(Property(), cg, x);
0394 ignore_unused_variable_warning(pmap);
0395 }
0396 G g;
0397 X x;
0398 typename property_traits< const_Map >::value_type pval;
0399 };
0400
0401 BOOST_concept(PropertyGraph, (G)(X)(Property))
0402 : ReadablePropertyGraph< G, X, Property >
0403 {
0404 typedef typename property_map< G, Property >::type Map;
0405 BOOST_CONCEPT_USAGE(PropertyGraph)
0406 {
0407 BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept< Map, X >));
0408
0409 Map pmap = get(Property(), g);
0410 pval = get(Property(), g, x);
0411 put(Property(), g, x, pval);
0412 ignore_unused_variable_warning(pmap);
0413 }
0414 G g;
0415 X x;
0416 typename property_traits< Map >::value_type pval;
0417 };
0418
0419 BOOST_concept(LvaluePropertyGraph, (G)(X)(Property))
0420 : ReadablePropertyGraph< G, X, Property >
0421 {
0422 typedef typename property_map< G, Property >::type Map;
0423 typedef typename property_map< G, Property >::const_type const_Map;
0424
0425 BOOST_CONCEPT_USAGE(LvaluePropertyGraph)
0426 {
0427 BOOST_CONCEPT_ASSERT((LvaluePropertyMapConcept< const_Map, X >));
0428
0429 pval = get(Property(), g, x);
0430 put(Property(), g, x, pval);
0431 }
0432 G g;
0433 X x;
0434 typename property_traits< Map >::value_type pval;
0435 };
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446 BOOST_concept(VertexIndexGraph, (Graph))
0447 {
0448 BOOST_CONCEPT_USAGE(VertexIndexGraph)
0449 {
0450 typedef typename graph_traits< Graph >::vertex_descriptor Vertex;
0451 typedef typename property_map< Graph, vertex_index_t >::type Map;
0452 typedef unsigned Index;
0453 Map m = get(vertex_index, g);
0454 Index x = get(vertex_index, g, Vertex());
0455 ignore_unused_variable_warning(m);
0456 ignore_unused_variable_warning(x);
0457
0458
0459 renumber_vertex_indices(g);
0460
0461 const_constraints(g);
0462 }
0463 void const_constraints(const Graph& g_)
0464 {
0465 typedef typename property_map< Graph, vertex_index_t >::const_type Map;
0466 Map m = get(vertex_index, g_);
0467 ignore_unused_variable_warning(m);
0468 }
0469
0470 private:
0471 Graph g;
0472 };
0473
0474 BOOST_concept(EdgeIndexGraph, (Graph))
0475 {
0476 BOOST_CONCEPT_USAGE(EdgeIndexGraph)
0477 {
0478 typedef typename graph_traits< Graph >::edge_descriptor Edge;
0479 typedef typename property_map< Graph, edge_index_t >::type Map;
0480 typedef unsigned Index;
0481 Map m = get(edge_index, g);
0482 Index x = get(edge_index, g, Edge());
0483 ignore_unused_variable_warning(m);
0484 ignore_unused_variable_warning(x);
0485
0486
0487 renumber_edge_indices(g);
0488
0489 const_constraints(g);
0490 }
0491 void const_constraints(const Graph& g_)
0492 {
0493 typedef typename property_map< Graph, edge_index_t >::const_type Map;
0494 Map m = get(edge_index, g_);
0495 ignore_unused_variable_warning(m);
0496 }
0497
0498 private:
0499 Graph g;
0500 };
0501
0502 BOOST_concept(ColorValue, (C))
0503 : EqualityComparable< C >, DefaultConstructible< C >
0504 {
0505 BOOST_CONCEPT_USAGE(ColorValue)
0506 {
0507 c = color_traits< C >::white();
0508 c = color_traits< C >::gray();
0509 c = color_traits< C >::black();
0510 }
0511 C c;
0512 };
0513
0514 BOOST_concept(BasicMatrix, (M)(I)(V))
0515 {
0516 BOOST_CONCEPT_USAGE(BasicMatrix)
0517 {
0518 V& elt = A[i][j];
0519 const_constraints(A);
0520 ignore_unused_variable_warning(elt);
0521 }
0522 void const_constraints(const M& cA)
0523 {
0524 const V& elt = cA[i][j];
0525 ignore_unused_variable_warning(elt);
0526 }
0527 M A;
0528 I i, j;
0529 };
0530
0531
0532
0533
0534
0535 BOOST_concept(NumericValue, (Numeric)) { BOOST_CONCEPT_USAGE(NumericValue) {
0536 BOOST_CONCEPT_ASSERT((DefaultConstructible< Numeric >));
0537 BOOST_CONCEPT_ASSERT((CopyConstructible< Numeric >));
0538 numeric_values< Numeric >::zero();
0539 numeric_values< Numeric >::infinity();
0540 }
0541 }
0542 ;
0543
0544 BOOST_concept(DegreeMeasure, (Measure)(Graph))
0545 {
0546 BOOST_CONCEPT_USAGE(DegreeMeasure)
0547 {
0548 typedef typename Measure::degree_type Degree;
0549 typedef typename Measure::vertex_type Vertex;
0550
0551 Degree d = m(Vertex(), g);
0552 ignore_unused_variable_warning(d);
0553 }
0554
0555 private:
0556 Measure m;
0557 Graph g;
0558 };
0559
0560 BOOST_concept(DistanceMeasure, (Measure)(Graph))
0561 {
0562 BOOST_CONCEPT_USAGE(DistanceMeasure)
0563 {
0564 typedef typename Measure::distance_type Distance;
0565 typedef typename Measure::result_type Result;
0566 Result r = m(Distance(), g);
0567 ignore_unused_variable_warning(r);
0568 }
0569
0570 private:
0571 Measure m;
0572 Graph g;
0573 };
0574
0575 }
0576
0577 using boost::concepts::MultiPassInputIteratorConcept;
0578
0579
0580 using boost::concepts::AdjacencyGraphConcept;
0581 using boost::concepts::AdjacencyMatrixConcept;
0582 using boost::concepts::BidirectionalGraphConcept;
0583 using boost::concepts::EdgeIndexGraphConcept;
0584 using boost::concepts::EdgeListGraphConcept;
0585 using boost::concepts::EdgeMutableGraphConcept;
0586 using boost::concepts::EdgeMutablePropertyGraphConcept;
0587 using boost::concepts::GraphConcept;
0588 using boost::concepts::IncidenceGraphConcept;
0589 using boost::concepts::LvaluePropertyGraphConcept;
0590 using boost::concepts::MutableBidirectionalGraphConcept;
0591 using boost::concepts::MutableEdgeListGraphConcept;
0592 using boost::concepts::MutableGraphConcept;
0593 using boost::concepts::MutableIncidenceGraphConcept;
0594 using boost::concepts::PropertyGraphConcept;
0595 using boost::concepts::ReadablePropertyGraphConcept;
0596 using boost::concepts::VertexAndEdgeListGraphConcept;
0597 using boost::concepts::VertexIndexGraphConcept;
0598 using boost::concepts::VertexListGraphConcept;
0599 using boost::concepts::VertexMutableGraphConcept;
0600 using boost::concepts::VertexMutablePropertyGraphConcept;
0601
0602
0603 using boost::concepts::BasicMatrixConcept;
0604 using boost::concepts::ColorValueConcept;
0605 using boost::concepts::DegreeMeasureConcept;
0606 using boost::concepts::DistanceMeasureConcept;
0607 using boost::concepts::NumericValueConcept;
0608
0609 }
0610 #include <boost/concept/detail/concept_undef.hpp>
0611
0612 #endif