| 1 | #include <iostream>
|
|---|
| 2 | #include <vector>
|
|---|
| 3 | #include <boost/graph/adjacency_list.hpp>
|
|---|
| 4 | #include <boost/property_map/property_map.hpp>
|
|---|
| 5 | #include <boost/graph/core_numbers.hpp>
|
|---|
| 6 |
|
|---|
| 7 | using namespace boost;
|
|---|
| 8 |
|
|---|
| 9 | int main(int argc, char* argv[])
|
|---|
| 10 | {
|
|---|
| 11 | typedef adjacency_list <vecS, vecS, undirectedS,
|
|---|
| 12 | no_property, property<edge_weight_t, int>> UGraph;
|
|---|
| 13 |
|
|---|
| 14 | typedef std::pair<int,int> Edge;
|
|---|
| 15 |
|
|---|
| 16 | int vertexCount = 21;
|
|---|
| 17 |
|
|---|
| 18 | Edge edgeArray[] =
|
|---|
| 19 | {
|
|---|
| 20 | Edge(1, 2), Edge(1, 4), Edge(2, 3), Edge(2, 4), Edge(3, 1), Edge(3, 5),
|
|---|
| 21 | Edge(4, 3), Edge(5, 6), Edge(6, 7), Edge(6, 10), Edge(6, 12), Edge(7, 5),
|
|---|
| 22 | Edge(7, 8), Edge(7, 9), Edge(10, 4), Edge(10, 11), Edge(10, 13), Edge(11, 6),
|
|---|
| 23 | Edge(12, 10), Edge(12, 11), Edge(13, 14), Edge(14, 4), Edge(14, 10), Edge(14, 15),
|
|---|
| 24 | Edge(16, 17), Edge(17, 19), Edge(18, 16), Edge(19, 18), Edge(20, 16)
|
|---|
| 25 | };
|
|---|
| 26 |
|
|---|
| 27 | int weightArray[] =
|
|---|
| 28 | {
|
|---|
| 29 | 3, 1, 1, 2, 1, 1,
|
|---|
| 30 | 3, 2, 1, 3, 1, 1,
|
|---|
| 31 | 2, 1, 2, 1, 2, 1,
|
|---|
| 32 | 3, 2, 2, 1, 1, 3,
|
|---|
| 33 | 3, 2, 1, 3, 1
|
|---|
| 34 | };
|
|---|
| 35 |
|
|---|
| 36 | int edgeCount = sizeof(edgeArray) / sizeof(Edge);
|
|---|
| 37 |
|
|---|
| 38 | UGraph g(edgeArray, edgeArray + edgeCount, weightArray, vertexCount);
|
|---|
| 39 |
|
|---|
| 40 | std::vector<int> coreArray(num_vertices(g));
|
|---|
| 41 |
|
|---|
| 42 | weighted_core_numbers(g, make_iterator_property_map(coreArray.begin(), get(vertex_index,g)));
|
|---|
| 43 |
|
|---|
| 44 | for (size_t i = 0; i < num_vertices(g); ++i)
|
|---|
| 45 | {
|
|---|
| 46 | std::cout << "vertex " << i << " core " << coreArray[i] << std::endl;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | return 0;
|
|---|
| 50 | }
|
|---|