/usr/include/boost/graph/adjacency_matrix.hpp is in libboost1.46-dev 1.46.1-7ubuntu3.
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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 | //=======================================================================
// Copyright 2001 University of Notre Dame.
// Copyright 2006 Trustees of Indiana University
// Authors: Jeremy G. Siek and Douglas Gregor <dgregor@cs.indiana.edu>
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================
#ifndef BOOST_ADJACENCY_MATRIX_HPP
#define BOOST_ADJACENCY_MATRIX_HPP
#include <boost/config.hpp>
#include <vector>
#include <memory>
#include <boost/assert.hpp>
#include <boost/limits.hpp>
#include <boost/iterator.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/graph_mutability_traits.hpp>
#include <boost/graph/graph_selectors.hpp>
#include <boost/mpl/if.hpp>
#include <boost/graph/adjacency_iterator.hpp>
#include <boost/graph/detail/edge.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
#include <boost/iterator/filter_iterator.hpp>
#include <boost/range/irange.hpp>
#include <boost/graph/properties.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits/ice.hpp>
namespace boost {
namespace detail {
template <class Directed, class Vertex>
class matrix_edge_desc_impl : public edge_desc_impl<Directed,Vertex>
{
typedef edge_desc_impl<Directed,Vertex> Base;
public:
matrix_edge_desc_impl() { }
matrix_edge_desc_impl(bool exists, Vertex s, Vertex d,
const void* ep = 0)
: Base(s, d, ep), m_exists(exists) { }
bool exists() const { return m_exists; }
private:
bool m_exists;
};
struct does_edge_exist {
template <class Edge>
bool operator()(const Edge& e) const { return e.exists(); }
};
// Note to self... The int for get_edge_exists and set_edge exist helps
// make these calls unambiguous.
template <typename EdgeProperty>
bool get_edge_exists(const std::pair<bool, EdgeProperty>& stored_edge, int) {
return stored_edge.first;
}
template <typename EdgeProperty>
void set_edge_exists(
std::pair<bool, EdgeProperty>& stored_edge,
bool flag,
int
) {
stored_edge.first = flag;
}
template <typename EdgeProxy>
bool get_edge_exists(const EdgeProxy& edge_proxy, ...) {
return edge_proxy;
}
template <typename EdgeProxy>
EdgeProxy& set_edge_exists(EdgeProxy& edge_proxy, bool flag, ...) {
edge_proxy = flag;
return edge_proxy; // just to avoid never used warning
}
// NOTE: These functions collide with the get_property function for
// accessing bundled graph properties. Be excplicit when using them.
template <typename EdgeProperty>
const EdgeProperty&
get_edge_property(const std::pair<bool, EdgeProperty>& stored_edge) {
return stored_edge.second;
}
template <typename EdgeProperty>
EdgeProperty&
get_edge_property(std::pair<bool, EdgeProperty>& stored_edge) {
return stored_edge.second;
}
template <typename StoredEdgeProperty, typename EdgeProperty>
inline void
set_edge_property(std::pair<bool, StoredEdgeProperty>& stored_edge,
const EdgeProperty& ep, int) {
stored_edge.second = ep;
}
inline const no_property& get_edge_property(const char&) {
static no_property s_prop;
return s_prop;
}
inline no_property& get_edge_property(char&) {
static no_property s_prop;
return s_prop;
}
template <typename EdgeProxy, typename EdgeProperty>
inline void set_edge_property(EdgeProxy, const EdgeProperty&, ...) {}
//=======================================================================
// Directed Out Edge Iterator
template <
typename VertexDescriptor, typename MatrixIter
, typename VerticesSizeType, typename EdgeDescriptor
>
struct dir_adj_matrix_out_edge_iter
: iterator_adaptor<
dir_adj_matrix_out_edge_iter<VertexDescriptor, MatrixIter, VerticesSizeType, EdgeDescriptor>
, MatrixIter
, EdgeDescriptor
, use_default
, EdgeDescriptor
, std::ptrdiff_t
>
{
typedef iterator_adaptor<
dir_adj_matrix_out_edge_iter<VertexDescriptor, MatrixIter, VerticesSizeType, EdgeDescriptor>
, MatrixIter
, EdgeDescriptor
, use_default
, EdgeDescriptor
, std::ptrdiff_t
> super_t;
dir_adj_matrix_out_edge_iter() { }
dir_adj_matrix_out_edge_iter(
const MatrixIter& i
, const VertexDescriptor& src
, const VerticesSizeType& n
)
: super_t(i), m_src(src), m_targ(0), m_n(n)
{ }
void increment() {
++this->base_reference();
++m_targ;
}
inline EdgeDescriptor
dereference() const
{
return EdgeDescriptor(get_edge_exists(*this->base(), 0),
m_src, m_targ,
&get_edge_property(*this->base()));
}
VertexDescriptor m_src, m_targ;
VerticesSizeType m_n;
};
//=======================================================================
// Directed In Edge Iterator
template <
typename VertexDescriptor, typename MatrixIter
, typename VerticesSizeType, typename EdgeDescriptor
>
struct dir_adj_matrix_in_edge_iter
: iterator_adaptor<
dir_adj_matrix_in_edge_iter<VertexDescriptor, MatrixIter, VerticesSizeType, EdgeDescriptor>
, MatrixIter
, EdgeDescriptor
, use_default
, EdgeDescriptor
, std::ptrdiff_t
>
{
typedef iterator_adaptor<
dir_adj_matrix_in_edge_iter<VertexDescriptor, MatrixIter, VerticesSizeType, EdgeDescriptor>
, MatrixIter
, EdgeDescriptor
, use_default
, EdgeDescriptor
, std::ptrdiff_t
> super_t;
dir_adj_matrix_in_edge_iter() { }
dir_adj_matrix_in_edge_iter(
const MatrixIter& i
, const MatrixIter& last
, const VertexDescriptor& tgt
, const VerticesSizeType& n
)
: super_t(i), m_last(last), m_src(0), m_targ(tgt), m_n(n)
{ }
void increment() {
if (VerticesSizeType(m_last - this->base_reference()) >= m_n) {
this->base_reference() += m_n;
++m_src;
} else {
this->base_reference() = m_last;
}
}
inline EdgeDescriptor
dereference() const
{
return EdgeDescriptor(get_edge_exists(*this->base(), 0),
m_src, m_targ,
&get_edge_property(*this->base()));
}
MatrixIter m_last;
VertexDescriptor m_src, m_targ;
VerticesSizeType m_n;
};
//=======================================================================
// Undirected Out Edge Iterator
template <
typename VertexDescriptor, typename MatrixIter
, typename VerticesSizeType, typename EdgeDescriptor
>
struct undir_adj_matrix_out_edge_iter
: iterator_adaptor<
undir_adj_matrix_out_edge_iter<VertexDescriptor, MatrixIter, VerticesSizeType, EdgeDescriptor>
, MatrixIter
, EdgeDescriptor
, use_default
, EdgeDescriptor
, std::ptrdiff_t
>
{
typedef iterator_adaptor<
undir_adj_matrix_out_edge_iter<VertexDescriptor, MatrixIter, VerticesSizeType, EdgeDescriptor>
, MatrixIter
, EdgeDescriptor
, use_default
, EdgeDescriptor
, std::ptrdiff_t
> super_t;
undir_adj_matrix_out_edge_iter() { }
undir_adj_matrix_out_edge_iter(
const MatrixIter& i
, const VertexDescriptor& src
, const VerticesSizeType& n
)
: super_t(i), m_src(src), m_inc(src), m_targ(0), m_n(n)
{}
void increment()
{
if (m_targ < m_src) // first half
{
++this->base_reference();
}
else if (m_targ < m_n - 1)
{ // second half
++m_inc;
this->base_reference() += m_inc;
}
else
{ // past-the-end
this->base_reference() += m_n - m_src;
}
++m_targ;
}
inline EdgeDescriptor
dereference() const
{
return EdgeDescriptor(get_edge_exists(*this->base(), 0),
m_src, m_targ,
&get_edge_property(*this->base()));
}
VertexDescriptor m_src, m_inc, m_targ;
VerticesSizeType m_n;
};
//=======================================================================
// Undirected In Edge Iterator
template <
typename VertexDescriptor, typename MatrixIter
, typename VerticesSizeType, typename EdgeDescriptor
>
struct undir_adj_matrix_in_edge_iter
: iterator_adaptor<
undir_adj_matrix_in_edge_iter<VertexDescriptor, MatrixIter, VerticesSizeType, EdgeDescriptor>
, MatrixIter
, EdgeDescriptor
, use_default
, EdgeDescriptor
, std::ptrdiff_t
>
{
typedef iterator_adaptor<
undir_adj_matrix_in_edge_iter<VertexDescriptor, MatrixIter, VerticesSizeType, EdgeDescriptor>
, MatrixIter
, EdgeDescriptor
, use_default
, EdgeDescriptor
, std::ptrdiff_t
> super_t;
undir_adj_matrix_in_edge_iter() { }
undir_adj_matrix_in_edge_iter(
const MatrixIter& i
, const VertexDescriptor& src
, const VerticesSizeType& n
)
: super_t(i), m_src(src), m_inc(src), m_targ(0), m_n(n)
{}
void increment()
{
if (m_targ < m_src) // first half
{
++this->base_reference();
}
else if (m_targ < m_n - 1)
{ // second half
++m_inc;
this->base_reference() += m_inc;
}
else
{ // past-the-end
this->base_reference() += m_n - m_src;
}
++m_targ;
}
inline EdgeDescriptor
dereference() const
{
return EdgeDescriptor(get_edge_exists(*this->base(), 0),
m_targ, m_src,
&get_edge_property(*this->base()));
}
VertexDescriptor m_src, m_inc, m_targ;
VerticesSizeType m_n;
};
//=======================================================================
// Edge Iterator
template <typename Directed, typename MatrixIter,
typename VerticesSizeType, typename EdgeDescriptor>
struct adj_matrix_edge_iter
: iterator_adaptor<
adj_matrix_edge_iter<Directed, MatrixIter, VerticesSizeType, EdgeDescriptor>
, MatrixIter
, EdgeDescriptor
, use_default
, EdgeDescriptor
, std::ptrdiff_t
>
{
typedef iterator_adaptor<
adj_matrix_edge_iter<Directed, MatrixIter, VerticesSizeType, EdgeDescriptor>
, MatrixIter
, EdgeDescriptor
, use_default
, EdgeDescriptor
, std::ptrdiff_t
> super_t;
adj_matrix_edge_iter() { }
adj_matrix_edge_iter(const MatrixIter& i, const MatrixIter& start, const VerticesSizeType& n)
: super_t(i), m_start(start), m_src(0), m_targ(0), m_n(n) { }
void increment()
{
increment_dispatch(this->base_reference(), Directed());
}
void increment_dispatch(MatrixIter& i, directedS)
{
++i;
if (m_targ == m_n - 1)
{
m_targ = 0;
++m_src;
}
else
{
++m_targ;
}
}
void increment_dispatch(MatrixIter& i, undirectedS)
{
++i;
if (m_targ == m_src)
{
m_targ = 0;
++m_src;
}
else
{
++m_targ;
}
}
inline EdgeDescriptor
dereference() const
{
return EdgeDescriptor(get_edge_exists(*this->base(), 0),
m_src, m_targ,
&get_edge_property(*this->base()));
}
MatrixIter m_start;
VerticesSizeType m_src, m_targ, m_n;
};
} // namespace detail
//=========================================================================
// Adjacency Matrix Traits
template <typename Directed = directedS>
class adjacency_matrix_traits {
typedef typename Directed::is_directed_t is_directed;
public:
// The bidirectionalS tag is not allowed with the adjacency_matrix
// graph type. Instead, use directedS, which also provides the
// functionality required for a Bidirectional Graph (in_edges,
// in_degree, etc.).
#if !defined(_MSC_VER) || _MSC_VER > 1300
BOOST_STATIC_ASSERT(type_traits::ice_not<(is_same<Directed, bidirectionalS>::value)>::value);
#endif
typedef typename mpl::if_<is_directed,
bidirectional_tag, undirected_tag>::type
directed_category;
typedef disallow_parallel_edge_tag edge_parallel_category;
typedef std::size_t vertex_descriptor;
typedef detail::matrix_edge_desc_impl<directed_category,
vertex_descriptor> edge_descriptor;
};
struct adjacency_matrix_class_tag { };
struct adj_matrix_traversal_tag :
public virtual adjacency_matrix_tag,
public virtual vertex_list_graph_tag,
public virtual incidence_graph_tag,
public virtual adjacency_graph_tag,
public virtual edge_list_graph_tag { };
//=========================================================================
// Adjacency Matrix Class
template <typename Directed = directedS,
typename VertexProperty = no_property,
typename EdgeProperty = no_property,
typename GraphProperty = no_property,
typename Allocator = std::allocator<bool> >
class adjacency_matrix {
typedef adjacency_matrix self;
typedef adjacency_matrix_traits<Directed> Traits;
public:
#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
// The bidirectionalS tag is not allowed with the adjacency_matrix
// graph type. Instead, use directedS, which also provides the
// functionality required for a Bidirectional Graph (in_edges,
// in_degree, etc.).
BOOST_STATIC_ASSERT(!(is_same<Directed, bidirectionalS>::value));
#endif
#if !defined(BOOST_GRAPH_NO_BUNDLED_PROPERTIES)
typedef typename graph_detail::graph_prop<GraphProperty>::property graph_property_type;
typedef typename graph_detail::graph_prop<GraphProperty>::bundle graph_bundled;
typedef typename graph_detail::vertex_prop<VertexProperty>::property vertex_property_type;
typedef typename graph_detail::vertex_prop<VertexProperty>::bundle vertex_bundled;
typedef typename graph_detail::edge_prop<EdgeProperty>::property edge_property_type;
typedef typename graph_detail::edge_prop<EdgeProperty>::bundle edge_bundled;
#else
typedef GraphProperty graph_property_type;
typedef no_graph_bundle graph_bundled;
typedef VertexProperty vertex_property_type;
typedef no_vertex_bundle vertex_bundled;
typedef EdgeProperty edge_property_type;
typedef no_edge_bundle edge_bundled;
#endif
public: // should be private
typedef typename mpl::if_<typename has_property<edge_property_type>::type,
std::pair<bool, edge_property_type>, char>::type StoredEdge;
#if (defined(BOOST_MSVC) && BOOST_MSVC <= 1300) || defined(BOOST_NO_STD_ALLOCATOR)
typedef std::vector<StoredEdge> Matrix;
#else
// This causes internal compiler error for MSVC
typedef typename Allocator::template rebind<StoredEdge>::other Alloc;
typedef std::vector<StoredEdge, Alloc> Matrix;
#endif
typedef typename Matrix::iterator MatrixIter;
typedef typename Matrix::size_type size_type;
public:
// Graph concept required types
typedef typename Traits::vertex_descriptor vertex_descriptor;
typedef typename Traits::edge_descriptor edge_descriptor;
typedef typename Traits::directed_category directed_category;
typedef typename Traits::edge_parallel_category edge_parallel_category;
typedef adj_matrix_traversal_tag traversal_category;
static vertex_descriptor null_vertex()
{
return (std::numeric_limits<vertex_descriptor>::max)();
}
//private: if friends worked, these would be private
typedef detail::dir_adj_matrix_out_edge_iter<
vertex_descriptor, MatrixIter, size_type, edge_descriptor
> DirOutEdgeIter;
typedef detail::undir_adj_matrix_out_edge_iter<
vertex_descriptor, MatrixIter, size_type, edge_descriptor
> UnDirOutEdgeIter;
typedef typename mpl::if_<
typename Directed::is_directed_t, DirOutEdgeIter, UnDirOutEdgeIter
>::type unfiltered_out_edge_iter;
typedef detail::dir_adj_matrix_in_edge_iter<
vertex_descriptor, MatrixIter, size_type, edge_descriptor
> DirInEdgeIter;
typedef detail::undir_adj_matrix_in_edge_iter<
vertex_descriptor, MatrixIter, size_type, edge_descriptor
> UnDirInEdgeIter;
typedef typename mpl::if_<
typename Directed::is_directed_t, DirInEdgeIter, UnDirInEdgeIter
>::type unfiltered_in_edge_iter;
typedef detail::adj_matrix_edge_iter<
Directed, MatrixIter, size_type, edge_descriptor
> unfiltered_edge_iter;
public:
// IncidenceGraph concept required types
typedef filter_iterator<detail::does_edge_exist, unfiltered_out_edge_iter>
out_edge_iterator;
typedef size_type degree_size_type;
// BidirectionalGraph required types
typedef filter_iterator<detail::does_edge_exist, unfiltered_in_edge_iter>
in_edge_iterator;
// AdjacencyGraph required types
typedef typename adjacency_iterator_generator<self,
vertex_descriptor, out_edge_iterator>::type adjacency_iterator;
// VertexListGraph required types
typedef size_type vertices_size_type;
typedef integer_range<vertex_descriptor> VertexList;
typedef typename VertexList::iterator vertex_iterator;
// EdgeListGraph required types
typedef size_type edges_size_type;
typedef filter_iterator<
detail::does_edge_exist, unfiltered_edge_iter
> edge_iterator;
// PropertyGraph required types
typedef adjacency_matrix_class_tag graph_tag;
// Constructor required by MutableGraph
adjacency_matrix(vertices_size_type n_vertices,
const GraphProperty& p = GraphProperty())
: m_matrix(Directed::is_directed ?
(n_vertices * n_vertices)
: (n_vertices * (n_vertices + 1) / 2)),
m_vertex_set(0, n_vertices),
m_vertex_properties(n_vertices),
m_num_edges(0),
m_property(p) { }
template <typename EdgeIterator>
adjacency_matrix(EdgeIterator first,
EdgeIterator last,
vertices_size_type n_vertices,
const GraphProperty& p = GraphProperty())
: m_matrix(Directed::is_directed ?
(n_vertices * n_vertices)
: (n_vertices * (n_vertices + 1) / 2)),
m_vertex_set(0, n_vertices),
m_vertex_properties(n_vertices),
m_num_edges(0),
m_property(p)
{
for (; first != last; ++first) {
add_edge(first->first, first->second, *this);
}
}
template <typename EdgeIterator, typename EdgePropertyIterator>
adjacency_matrix(EdgeIterator first,
EdgeIterator last,
EdgePropertyIterator ep_iter,
vertices_size_type n_vertices,
const GraphProperty& p = GraphProperty())
: m_matrix(Directed::is_directed ?
(n_vertices * n_vertices)
: (n_vertices * (n_vertices + 1) / 2)),
m_vertex_set(0, n_vertices),
m_vertex_properties(n_vertices),
m_num_edges(0),
m_property(p)
{
for (; first != last; ++first, ++ep_iter) {
add_edge(first->first, first->second, *ep_iter, *this);
}
}
#ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES
// Directly access a vertex or edge bundle
vertex_bundled& operator[](vertex_descriptor v)
{ return get(vertex_bundle, *this)[v]; }
const vertex_bundled& operator[](vertex_descriptor v) const
{ return get(vertex_bundle, *this)[v]; }
edge_bundled& operator[](edge_descriptor e)
{ return get(edge_bundle, *this)[e]; }
const edge_bundled& operator[](edge_descriptor e) const
{ return get(edge_bundle, *this)[e]; }
graph_bundled& operator[](graph_bundle_t)
{ return get_property(*this); }
const graph_bundled& operator[](graph_bundle_t) const
{ return get_property(*this); }
#endif
//private: if friends worked, these would be private
typename Matrix::const_reference
get_edge(vertex_descriptor u, vertex_descriptor v) const {
if (Directed::is_directed)
return m_matrix[u * m_vertex_set.size() + v];
else {
if (v > u)
std::swap(u, v);
return m_matrix[u * (u + 1)/2 + v];
}
}
typename Matrix::reference
get_edge(vertex_descriptor u, vertex_descriptor v) {
if (Directed::is_directed)
return m_matrix[u * m_vertex_set.size() + v];
else {
if (v > u)
std::swap(u, v);
return m_matrix[u * (u + 1)/2 + v];
}
}
Matrix m_matrix;
VertexList m_vertex_set;
std::vector<vertex_property_type> m_vertex_properties;
size_type m_num_edges;
graph_property_type m_property;
};
//=========================================================================
// Functions required by the AdjacencyMatrix concept
template <typename D, typename VP, typename EP, typename GP, typename A>
std::pair<typename adjacency_matrix<D,VP,EP,GP,A>::edge_descriptor,
bool>
edge(typename adjacency_matrix<D,VP,EP,GP,A>::vertex_descriptor u,
typename adjacency_matrix<D,VP,EP,GP,A>::vertex_descriptor v,
const adjacency_matrix<D,VP,EP,GP,A>& g)
{
bool exists = detail::get_edge_exists(g.get_edge(u,v), 0);
typename adjacency_matrix<D,VP,EP,GP,A>::edge_descriptor
e(exists, u, v, &detail::get_edge_property(g.get_edge(u,v)));
return std::make_pair(e, exists);
}
//=========================================================================
// Functions required by the IncidenceGraph concept
// O(1)
template <typename VP, typename EP, typename GP, typename A>
std::pair<typename adjacency_matrix<directedS,VP,EP,GP,A>::out_edge_iterator,
typename adjacency_matrix<directedS,VP,EP,GP,A>::out_edge_iterator>
out_edges
(typename adjacency_matrix<directedS,VP,EP,GP,A>::vertex_descriptor u,
const adjacency_matrix<directedS,VP,EP,GP,A>& g_)
{
typedef adjacency_matrix<directedS,VP,EP,GP,A> Graph;
Graph& g = const_cast<Graph&>(g_);
typename Graph::vertices_size_type offset = u * g.m_vertex_set.size();
typename Graph::MatrixIter f = g.m_matrix.begin() + offset;
typename Graph::MatrixIter l = f + g.m_vertex_set.size();
typename Graph::unfiltered_out_edge_iter
first(f, u, g.m_vertex_set.size())
, last(l, u, g.m_vertex_set.size());
detail::does_edge_exist pred;
typedef typename Graph::out_edge_iterator out_edge_iterator;
return std::make_pair(out_edge_iterator(pred, first, last),
out_edge_iterator(pred, last, last));
}
// O(1)
template <typename VP, typename EP, typename GP, typename A>
std::pair<
typename adjacency_matrix<undirectedS,VP,EP,GP,A>::out_edge_iterator,
typename adjacency_matrix<undirectedS,VP,EP,GP,A>::out_edge_iterator>
out_edges
(typename adjacency_matrix<undirectedS,VP,EP,GP,A>::vertex_descriptor u,
const adjacency_matrix<undirectedS,VP,EP,GP,A>& g_)
{
typedef adjacency_matrix<undirectedS,VP,EP,GP,A> Graph;
Graph& g = const_cast<Graph&>(g_);
typename Graph::vertices_size_type offset = u * (u + 1) / 2;
typename Graph::MatrixIter f = g.m_matrix.begin() + offset;
typename Graph::MatrixIter l = g.m_matrix.end();
typename Graph::unfiltered_out_edge_iter
first(f, u, g.m_vertex_set.size())
, last(l, u, g.m_vertex_set.size());
detail::does_edge_exist pred;
typedef typename Graph::out_edge_iterator out_edge_iterator;
return std::make_pair(out_edge_iterator(pred, first, last),
out_edge_iterator(pred, last, last));
}
// O(N)
template <typename D, typename VP, typename EP, typename GP, typename A>
typename adjacency_matrix<D,VP,EP,GP,A>::degree_size_type
out_degree(typename adjacency_matrix<D,VP,EP,GP,A>::vertex_descriptor u,
const adjacency_matrix<D,VP,EP,GP,A>& g)
{
typename adjacency_matrix<D,VP,EP,GP,A>::degree_size_type n = 0;
typename adjacency_matrix<D,VP,EP,GP,A>::out_edge_iterator f, l;
for (boost::tie(f, l) = out_edges(u, g); f != l; ++f)
++n;
return n;
}
// O(1)
template <typename D, typename VP, typename EP, typename GP, typename A,
typename Dir, typename Vertex>
typename adjacency_matrix<D,VP,EP,GP,A>::vertex_descriptor
source(const detail::matrix_edge_desc_impl<Dir,Vertex>& e,
const adjacency_matrix<D,VP,EP,GP,A>&)
{
return e.m_source;
}
// O(1)
template <typename D, typename VP, typename EP, typename GP, typename A,
typename Dir, typename Vertex>
typename adjacency_matrix<D,VP,EP,GP,A>::vertex_descriptor
target(const detail::matrix_edge_desc_impl<Dir,Vertex>& e,
const adjacency_matrix<D,VP,EP,GP,A>&)
{
return e.m_target;
}
//=========================================================================
// Functions required by the BidirectionalGraph concept
// O(1)
template <typename VP, typename EP, typename GP, typename A>
std::pair<typename adjacency_matrix<directedS,VP,EP,GP,A>::in_edge_iterator,
typename adjacency_matrix<directedS,VP,EP,GP,A>::in_edge_iterator>
in_edges
(typename adjacency_matrix<directedS,VP,EP,GP,A>::vertex_descriptor u,
const adjacency_matrix<directedS,VP,EP,GP,A>& g_)
{
typedef adjacency_matrix<directedS,VP,EP,GP,A> Graph;
Graph& g = const_cast<Graph&>(g_);
typename Graph::MatrixIter f = g.m_matrix.begin() + u;
typename Graph::MatrixIter l = g.m_matrix.end();
typename Graph::unfiltered_in_edge_iter
first(f, l, u, g.m_vertex_set.size())
, last(l, l, u, g.m_vertex_set.size());
detail::does_edge_exist pred;
typedef typename Graph::in_edge_iterator in_edge_iterator;
return std::make_pair(in_edge_iterator(pred, first, last),
in_edge_iterator(pred, last, last));
}
// O(1)
template <typename VP, typename EP, typename GP, typename A>
std::pair<
typename adjacency_matrix<undirectedS,VP,EP,GP,A>::in_edge_iterator,
typename adjacency_matrix<undirectedS,VP,EP,GP,A>::in_edge_iterator>
in_edges
(typename adjacency_matrix<undirectedS,VP,EP,GP,A>::vertex_descriptor u,
const adjacency_matrix<undirectedS,VP,EP,GP,A>& g_)
{
typedef adjacency_matrix<undirectedS,VP,EP,GP,A> Graph;
Graph& g = const_cast<Graph&>(g_);
typename Graph::vertices_size_type offset = u * (u + 1) / 2;
typename Graph::MatrixIter f = g.m_matrix.begin() + offset;
typename Graph::MatrixIter l = g.m_matrix.end();
typename Graph::unfiltered_in_edge_iter
first(f, u, g.m_vertex_set.size())
, last(l, u, g.m_vertex_set.size());
detail::does_edge_exist pred;
typedef typename Graph::in_edge_iterator in_edge_iterator;
return std::make_pair(in_edge_iterator(pred, first, last),
in_edge_iterator(pred, last, last));
}
// O(N)
template <typename D, typename VP, typename EP, typename GP, typename A>
typename adjacency_matrix<D,VP,EP,GP,A>::degree_size_type
in_degree(typename adjacency_matrix<D,VP,EP,GP,A>::vertex_descriptor u,
const adjacency_matrix<D,VP,EP,GP,A>& g)
{
typename adjacency_matrix<D,VP,EP,GP,A>::degree_size_type n = 0;
typename adjacency_matrix<D,VP,EP,GP,A>::in_edge_iterator f, l;
for (boost::tie(f, l) = in_edges(u, g); f != l; ++f)
++n;
return n;
}
//=========================================================================
// Functions required by the AdjacencyGraph concept
template <typename D, typename VP, typename EP, typename GP, typename A>
std::pair<typename adjacency_matrix<D,VP,EP,GP,A>::adjacency_iterator,
typename adjacency_matrix<D,VP,EP,GP,A>::adjacency_iterator>
adjacent_vertices
(typename adjacency_matrix<D,VP,EP,GP,A>::vertex_descriptor u,
const adjacency_matrix<D,VP,EP,GP,A>& g_)
{
typedef adjacency_matrix<D,VP,EP,GP,A> Graph;
const Graph& cg = static_cast<const Graph&>(g_);
Graph& g = const_cast<Graph&>(cg);
typedef typename Graph::adjacency_iterator adjacency_iterator;
typename Graph::out_edge_iterator first, last;
boost::tie(first, last) = out_edges(u, g);
return std::make_pair(adjacency_iterator(first, &g),
adjacency_iterator(last, &g));
}
//=========================================================================
// Functions required by the VertexListGraph concept
template <typename D, typename VP, typename EP, typename GP, typename A>
std::pair<typename adjacency_matrix<D,VP,EP,GP,A>::vertex_iterator,
typename adjacency_matrix<D,VP,EP,GP,A>::vertex_iterator>
vertices(const adjacency_matrix<D,VP,EP,GP,A>& g_) {
typedef adjacency_matrix<D,VP,EP,GP,A> Graph;
Graph& g = const_cast<Graph&>(g_);
return std::make_pair(g.m_vertex_set.begin(), g.m_vertex_set.end());
}
template <typename D, typename VP, typename EP, typename GP, typename A>
typename adjacency_matrix<D,VP,EP,GP,A>::vertices_size_type
num_vertices(const adjacency_matrix<D,VP,EP,GP,A>& g) {
return g.m_vertex_set.size();
}
//=========================================================================
// Functions required by the EdgeListGraph concept
template <typename D, typename VP, typename EP, typename GP, typename A>
std::pair<typename adjacency_matrix<D,VP,EP,GP,A>::edge_iterator,
typename adjacency_matrix<D,VP,EP,GP,A>::edge_iterator>
edges(const adjacency_matrix<D,VP,EP,GP,A>& g_)
{
typedef adjacency_matrix<D,VP,EP,GP,A> Graph;
Graph& g = const_cast<Graph&>(g_);
typename Graph::unfiltered_edge_iter
first(g.m_matrix.begin(), g.m_matrix.begin(),
g.m_vertex_set.size()),
last(g.m_matrix.end(), g.m_matrix.begin(),
g.m_vertex_set.size());
detail::does_edge_exist pred;
typedef typename Graph::edge_iterator edge_iterator;
return std::make_pair(edge_iterator(pred, first, last),
edge_iterator(pred, last, last));
}
// O(1)
template <typename D, typename VP, typename EP, typename GP, typename A>
typename adjacency_matrix<D,VP,EP,GP,A>::edges_size_type
num_edges(const adjacency_matrix<D,VP,EP,GP,A>& g)
{
return g.m_num_edges;
}
//=========================================================================
// Functions required by the MutableGraph concept
// O(1)
template <typename D, typename VP, typename EP, typename GP, typename A,
typename EP2>
std::pair<typename adjacency_matrix<D,VP,EP,GP,A>::edge_descriptor, bool>
add_edge(typename adjacency_matrix<D,VP,EP,GP,A>::vertex_descriptor u,
typename adjacency_matrix<D,VP,EP,GP,A>::vertex_descriptor v,
const EP2& ep,
adjacency_matrix<D,VP,EP,GP,A>& g)
{
typedef typename adjacency_matrix<D,VP,EP,GP,A>::edge_descriptor
edge_descriptor;
if (detail::get_edge_exists(g.get_edge(u,v), 0) == false) {
++(g.m_num_edges);
detail::set_edge_property(g.get_edge(u,v), EP(ep), 0);
detail::set_edge_exists(g.get_edge(u,v), true, 0);
return std::make_pair
(edge_descriptor(true, u, v, &detail::get_edge_property(g.get_edge(u,v))),
true);
} else
return std::make_pair
(edge_descriptor(true, u, v, &detail::get_edge_property(g.get_edge(u,v))),
false);
}
// O(1)
template <typename D, typename VP, typename EP, typename GP, typename A>
std::pair<typename adjacency_matrix<D,VP,EP,GP,A>::edge_descriptor, bool>
add_edge(typename adjacency_matrix<D,VP,EP,GP,A>::vertex_descriptor u,
typename adjacency_matrix<D,VP,EP,GP,A>::vertex_descriptor v,
adjacency_matrix<D,VP,EP,GP,A>& g)
{
EP ep;
return add_edge(u, v, ep, g);
}
// O(1)
template <typename D, typename VP, typename EP, typename GP, typename A>
void
remove_edge(typename adjacency_matrix<D,VP,EP,GP,A>::vertex_descriptor u,
typename adjacency_matrix<D,VP,EP,GP,A>::vertex_descriptor v,
adjacency_matrix<D,VP,EP,GP,A>& g)
{
// Don'remove the edge unless it already exists.
if(detail::get_edge_exists(g.get_edge(u,v), 0)) {
--(g.m_num_edges);
detail::set_edge_exists(g.get_edge(u,v), false, 0);
}
}
// O(1)
template <typename D, typename VP, typename EP, typename GP, typename A>
void
remove_edge(typename adjacency_matrix<D,VP,EP,GP,A>::edge_descriptor e,
adjacency_matrix<D,VP,EP,GP,A>& g)
{
remove_edge(source(e, g), target(e, g), g);
}
template <typename D, typename VP, typename EP, typename GP, typename A>
inline typename adjacency_matrix<D,VP,EP,GP,A>::vertex_descriptor
add_vertex(adjacency_matrix<D,VP,EP,GP,A>& g) {
// UNDER CONSTRUCTION
BOOST_ASSERT(false);
return *vertices(g).first;
}
template <typename D, typename VP, typename EP, typename GP, typename A,
typename VP2>
inline typename adjacency_matrix<D,VP,EP,GP,A>::vertex_descriptor
add_vertex(const VP2& /*vp*/, adjacency_matrix<D,VP,EP,GP,A>& g) {
// UNDER CONSTRUCTION
BOOST_ASSERT(false);
return *vertices(g).first;
}
template <typename D, typename VP, typename EP, typename GP, typename A>
inline void
remove_vertex(typename adjacency_matrix<D,VP,EP,GP,A>::vertex_descriptor /*u*/,
adjacency_matrix<D,VP,EP,GP,A>& /*g*/)
{
// UNDER CONSTRUCTION
BOOST_ASSERT(false);
}
// O(V)
template <typename VP, typename EP, typename GP, typename A>
void
clear_vertex
(typename adjacency_matrix<directedS,VP,EP,GP,A>::vertex_descriptor u,
adjacency_matrix<directedS,VP,EP,GP,A>& g)
{
typename adjacency_matrix<directedS,VP,EP,GP,A>::vertex_iterator
vi, vi_end;
for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
remove_edge(u, *vi, g);
for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
remove_edge(*vi, u, g);
}
// O(V)
template <typename VP, typename EP, typename GP, typename A>
void
clear_vertex
(typename adjacency_matrix<undirectedS,VP,EP,GP,A>::vertex_descriptor u,
adjacency_matrix<undirectedS,VP,EP,GP,A>& g)
{
typename adjacency_matrix<undirectedS,VP,EP,GP,A>::vertex_iterator
vi, vi_end;
for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
remove_edge(u, *vi, g);
}
//=========================================================================
// Functions required by the PropertyGraph concept
// O(1)
template <typename D, typename VP, typename EP, typename GP, typename A,
typename Tag, typename Value>
inline void
set_property(adjacency_matrix<D,VP,EP,GP,A>& g, Tag, const Value& value)
{
get_property_value(g.m_property, Tag()) = value;
}
template <typename D, typename VP, typename EP, typename GP, typename A,
typename Tag>
inline typename graph_property<adjacency_matrix<D,VP,EP,GP,A>, Tag>::type&
get_property(adjacency_matrix<D,VP,EP,GP,A>& g, Tag)
{
return get_property_value(g.m_property, Tag());
}
template <typename D, typename VP, typename EP, typename GP, typename A,
typename Tag>
inline const typename graph_property<adjacency_matrix<D,VP,EP,GP,A>, Tag>::type&
get_property(const adjacency_matrix<D,VP,EP,GP,A>& g, Tag)
{
return get_property_value(g.m_property, Tag());
}
//=========================================================================
// Vertex Property Map
template <typename GraphPtr, typename Vertex, typename T, typename R,
typename Tag>
class adj_matrix_vertex_property_map
: public put_get_helper<R,
adj_matrix_vertex_property_map<GraphPtr, Vertex, T, R, Tag> >
{
public:
typedef T value_type;
typedef R reference;
typedef Vertex key_type;
typedef boost::lvalue_property_map_tag category;
adj_matrix_vertex_property_map() { }
adj_matrix_vertex_property_map(GraphPtr g) : m_g(g) { }
inline reference operator[](key_type v) const {
return get_property_value(m_g->m_vertex_properties[v], Tag());
}
GraphPtr m_g;
};
template <class Property, class Vertex>
struct adj_matrix_vertex_id_map
: public boost::put_get_helper<Vertex,
adj_matrix_vertex_id_map<Property, Vertex> >
{
typedef Vertex value_type;
typedef Vertex reference;
typedef Vertex key_type;
typedef boost::readable_property_map_tag category;
adj_matrix_vertex_id_map() { }
template <class Graph>
inline adj_matrix_vertex_id_map(const Graph&) { }
inline value_type operator[](key_type v) const { return v; }
};
namespace detail {
struct adj_matrix_any_vertex_pa {
template <class Tag, class Graph, class Property>
struct bind_ {
typedef typename property_value<Property,Tag>::type Value;
typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
typedef adj_matrix_vertex_property_map<Graph*, Vertex, Value, Value&,
Tag> type;
typedef adj_matrix_vertex_property_map<const Graph*, Vertex, Value,
const Value&, Tag> const_type;
};
};
struct adj_matrix_id_vertex_pa {
template <class Tag, class Graph, class Property>
struct bind_ {
typedef typename Graph::vertex_descriptor Vertex;
typedef adj_matrix_vertex_id_map<Property, Vertex> type;
typedef adj_matrix_vertex_id_map<Property, Vertex> const_type;
};
};
template <class Tag>
struct adj_matrix_choose_vertex_pa_helper {
typedef adj_matrix_any_vertex_pa type;
};
template <>
struct adj_matrix_choose_vertex_pa_helper<vertex_index_t> {
typedef adj_matrix_id_vertex_pa type;
};
template <class Tag, class Graph, class Property>
struct adj_matrix_choose_vertex_pa {
typedef typename adj_matrix_choose_vertex_pa_helper<Tag>::type Helper;
typedef typename Helper::template bind_<Tag,Graph,Property> Bind;
typedef typename Bind::type type;
typedef typename Bind::const_type const_type;
};
struct adj_matrix_vertex_property_selector {
template <class Graph, class Property, class Tag>
struct bind_ {
typedef adj_matrix_choose_vertex_pa<Tag,Graph,Property> Choice;
typedef typename Choice::type type;
typedef typename Choice::const_type const_type;
};
};
} // namespace detail
template <>
struct vertex_property_selector<adjacency_matrix_class_tag> {
typedef detail::adj_matrix_vertex_property_selector type;
};
//=========================================================================
// Edge Property Map
template <typename Directed, typename Property, typename Vertex,
typename T, typename R, typename Tag>
class adj_matrix_edge_property_map
: public put_get_helper<R,
adj_matrix_edge_property_map<Directed, Property, Vertex, T, R, Tag> >
{
public:
typedef T value_type;
typedef R reference;
typedef detail::matrix_edge_desc_impl<Directed, Vertex> key_type;
typedef boost::lvalue_property_map_tag category;
inline reference operator[](key_type e) const {
Property& p = *(Property*)e.get_property();
return get_property_value(p, Tag());
}
};
struct adj_matrix_edge_property_selector {
template <class Graph, class Property, class Tag>
struct bind_ {
typedef typename property_value<Property,Tag>::type T;
typedef typename Graph::vertex_descriptor Vertex;
typedef adj_matrix_edge_property_map<typename Graph::directed_category,
Property, Vertex, T, T&, Tag> type;
typedef adj_matrix_edge_property_map<typename Graph::directed_category,
Property, Vertex, T, const T&, Tag> const_type;
};
};
template <>
struct edge_property_selector<adjacency_matrix_class_tag> {
typedef adj_matrix_edge_property_selector type;
};
//=========================================================================
// Functions required by PropertyGraph
namespace detail {
template <typename Property, typename D, typename VP, typename EP,
typename GP, typename A>
typename boost::property_map<adjacency_matrix<D,VP,EP,GP,A>,
Property>::type
get_dispatch(adjacency_matrix<D,VP,EP,GP,A>& g, Property,
vertex_property_tag)
{
typedef adjacency_matrix<D,VP,EP,GP,A> Graph;
typedef typename boost::property_map<adjacency_matrix<D,VP,EP,GP,A>,
Property>::type PA;
return PA(&g);
}
template <typename Property, typename D, typename VP, typename EP,
typename GP, typename A>
typename boost::property_map<adjacency_matrix<D,VP,EP,GP,A>,
Property>::type
get_dispatch(adjacency_matrix<D,VP,EP,GP,A>&, Property,
edge_property_tag)
{
typedef typename boost::property_map<adjacency_matrix<D,VP,EP,GP,A>,
Property>::type PA;
return PA();
}
template <typename Property, typename D, typename VP, typename EP,
typename GP, typename A>
typename boost::property_map<adjacency_matrix<D,VP,EP,GP,A>,
Property>::const_type
get_dispatch(const adjacency_matrix<D,VP,EP,GP,A>& g, Property,
vertex_property_tag)
{
typedef adjacency_matrix<D,VP,EP,GP,A> Graph;
typedef typename boost::property_map<adjacency_matrix<D,VP,EP,GP,A>,
Property>::const_type PA;
return PA(&g);
}
template <typename Property, typename D, typename VP, typename EP,
typename GP, typename A>
typename boost::property_map<adjacency_matrix<D,VP,EP,GP,A>,
Property>::const_type
get_dispatch(const adjacency_matrix<D,VP,EP,GP,A>&, Property,
edge_property_tag)
{
typedef typename boost::property_map<adjacency_matrix<D,VP,EP,GP,A>,
Property>::const_type PA;
return PA();
}
} // namespace detail
template <typename Property, typename D, typename VP, typename EP,
typename GP, typename A>
inline
typename property_map<adjacency_matrix<D,VP,EP,GP,A>, Property>::type
get(Property p, adjacency_matrix<D,VP,EP,GP,A>& g)
{
typedef typename property_kind<Property>::type Kind;
return detail::get_dispatch(g, p, Kind());
}
template <typename Property, typename D, typename VP, typename EP,
typename GP, typename A>
inline
typename property_map<adjacency_matrix<D,VP,EP,GP,A>, Property>::const_type
get(Property p, const adjacency_matrix<D,VP,EP,GP,A>& g)
{
typedef typename property_kind<Property>::type Kind;
return detail::get_dispatch(g, p, Kind());
}
template <typename Property, typename D, typename VP, typename EP,
typename GP, typename A, typename Key>
inline
typename property_traits<
typename property_map<adjacency_matrix<D,VP,EP,GP,A>, Property>::const_type
>::value_type
get(Property p, const adjacency_matrix<D,VP,EP,GP,A>& g,
const Key& key)
{
return get(get(p, g), key);
}
template <typename Property, typename D, typename VP, typename EP,
typename GP, typename A, typename Key, typename Value>
inline void
put(Property p, adjacency_matrix<D,VP,EP,GP,A>& g,
const Key& key, const Value& value)
{
typedef adjacency_matrix<D,VP,EP,GP,A> Graph;
typedef typename boost::property_map<Graph, Property>::type Map;
Map pmap = get(p, g);
put(pmap, key, value);
}
//=========================================================================
// Other Functions
template <typename D, typename VP, typename EP, typename GP, typename A>
typename adjacency_matrix<D,VP,EP,GP,A>::vertex_descriptor
vertex(typename adjacency_matrix<D,VP,EP,GP,A>::vertices_size_type n,
const adjacency_matrix<D,VP,EP,GP,A>&)
{
return n;
}
// Support for bundled properties
#ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES
template <typename Directed, typename VertexProperty, typename EdgeProperty, typename GraphProperty,
typename Allocator, typename T, typename Bundle>
inline
typename property_map<adjacency_matrix<Directed, VertexProperty, EdgeProperty, GraphProperty, Allocator>,
T Bundle::*>::type
get(T Bundle::* p, adjacency_matrix<Directed, VertexProperty, EdgeProperty, GraphProperty, Allocator>& g)
{
typedef typename property_map<adjacency_matrix<Directed, VertexProperty, EdgeProperty, GraphProperty, Allocator>,
T Bundle::*>::type
result_type;
return result_type(&g, p);
}
template <typename Directed, typename VertexProperty, typename EdgeProperty, typename GraphProperty,
typename Allocator, typename T, typename Bundle>
inline
typename property_map<adjacency_matrix<Directed, VertexProperty, EdgeProperty, GraphProperty, Allocator>,
T Bundle::*>::const_type
get(T Bundle::* p, adjacency_matrix<Directed, VertexProperty, EdgeProperty, GraphProperty, Allocator> const & g)
{
typedef typename property_map<adjacency_matrix<Directed, VertexProperty, EdgeProperty, GraphProperty, Allocator>,
T Bundle::*>::const_type
result_type;
return result_type(&g, p);
}
template <typename Directed, typename VertexProperty, typename EdgeProperty, typename GraphProperty,
typename Allocator, typename T, typename Bundle, typename Key>
inline T
get(T Bundle::* p, adjacency_matrix<Directed, VertexProperty, EdgeProperty, GraphProperty, Allocator> const & g,
const Key& key)
{
return get(get(p, g), key);
}
template <typename Directed, typename VertexProperty, typename EdgeProperty, typename GraphProperty,
typename Allocator, typename T, typename Bundle, typename Key>
inline void
put(T Bundle::* p, adjacency_matrix<Directed, VertexProperty, EdgeProperty, GraphProperty, Allocator>& g,
const Key& key, const T& value)
{
put(get(p, g), key, value);
}
#endif
#define ADJMAT_PARAMS \
typename D, typename VP, typename EP, typename GP, typename A
#define ADJMAT adjacency_matrix<D,VP,EP,GP,A>
template <ADJMAT_PARAMS>
struct graph_mutability_traits<ADJMAT> {
typedef mutable_edge_property_graph_tag category;
};
#undef ADJMAT_PARAMS
#undef ADJMAT
} // namespace boost
#endif // BOOST_ADJACENCY_MATRIX_HPP
|