]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/test/core_numbers_test.cpp
1 // (C) Copyright David Gleich 2007
3 // Use, modification and distribution are subject to the
4 // Boost Software License, Version 1.0 (See accompanying file
5 // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
8 #include <boost/graph/adjacency_list.hpp>
9 #include <boost/graph/core_numbers.hpp>
10 #include <boost/property_map/property_map.hpp>
13 using namespace boost
;
15 const char* errstr
= "";
19 // core numbers of sample graph
20 typedef adjacency_list
< vecS
, vecS
, undirectedS
> Graph
;
53 std::vector
< int > core_nums(num_vertices(G
));
55 G
, make_iterator_property_map(core_nums
.begin(), get(vertex_index
, G
)));
57 for (size_t i
= 0; i
< num_vertices(G
); ++i
)
59 printf("vertex %3lu : %i\n", (unsigned long)i
, core_nums
[i
]);
63 = { 1, 2, 2, 3, 3, 3, 3, 3, 2, 3, 2, 1, 1, 3, 3, 0, 2, 2, 2, 2, 1 };
64 for (size_t i
= 0; i
< num_vertices(G
); ++i
)
66 if (core_nums
[i
] != correct
[i
])
76 // core numbers of sample graph
77 typedef adjacency_list
< listS
, vecS
, undirectedS
, no_property
,
78 property
< edge_weight_t
, int > >
81 typedef std::pair
< int, int > Edge
;
83 Edge edge_array
[] = { Edge(0, 1), Edge(0, 2), Edge(1, 2) };
84 int weights
[] = { -1, -2, -2 };
85 int num_arcs
= sizeof(edge_array
) / sizeof(Edge
);
87 graph_t
G(edge_array
, edge_array
+ num_arcs
, weights
, num_nodes
);
89 std::vector
< int > core_nums(num_vertices(G
));
90 weighted_core_numbers(
91 G
, make_iterator_property_map(core_nums
.begin(), get(vertex_index
, G
)));
93 for (size_t i
= 0; i
< num_vertices(G
); ++i
)
95 printf("vertex %3lu : %i\n", (unsigned long)i
, core_nums
[i
]);
98 int correct
[3] = { -1, -1, -4 };
99 for (size_t i
= 0; i
< num_vertices(G
); ++i
)
101 if (core_nums
[i
] != correct
[i
])
111 // core numbers of a directed graph, the core numbers of a directed
112 // cycle are always one
113 typedef adjacency_list
< vecS
, vecS
, directedS
> graph_t
;
115 typedef std::pair
< int, int > Edge
;
118 = { Edge(0, 1), Edge(1, 2), Edge(2, 3), Edge(3, 4), Edge(4, 0) };
119 int num_arcs
= sizeof(edge_array
) / sizeof(Edge
);
121 graph_t
G(edge_array
, edge_array
+ num_arcs
, num_nodes
);
123 std::vector
< int > core_nums(num_vertices(G
));
125 G
, make_iterator_property_map(core_nums
.begin(), get(vertex_index
, G
)));
127 for (size_t i
= 0; i
< num_vertices(G
); ++i
)
129 printf("vertex %3lu : %i\n", (unsigned long)i
, core_nums
[i
]);
132 int correct
[5] = { 1, 1, 1, 1, 1 };
133 for (size_t i
= 0; i
< num_vertices(G
); ++i
)
135 if (core_nums
[i
] != correct
[i
])
143 int main(int, char**)
145 int nfail
= 0, ntotal
= 0;
150 name
= "core_numbers";
156 printf("%20s %50s\n", name
, errstr
);
160 printf("%20s success\n", name
);
163 name
= "weighted_core_numbers";
169 printf("%20s %50s\n", name
, errstr
);
173 printf("%20s success\n", name
);
176 name
= "directed_corenums";
182 printf("%20s %50s\n", name
, errstr
);
186 printf("%20s success\n", name
);
190 printf("Total tests : %3i\n", ntotal
);
191 printf("Total failed : %3i\n", nfail
);