• boost图库简单操作


     1 #include <boost/graph/graph_traits.hpp>
    2 #include <boost/graph/adjacency_list.hpp>
    3 #include <boost/graph/dijkstra_shortest_paths.hpp>
    4 using namespace boost;
    5
    6 #include <iostream> // for std::cout
    7 #include <utility> // for std::pair
    8 #include <algorithm> // for std::for_each
    9 using namespace std;
    10
    11 #include <limits.h>
    12
    13 int main(int,char*[])
    14 {
    15
    16 typedef adjacency_list < listS, vecS, /*directedS*/undirectedS,
    17 no_property, property < edge_weight_t, int > > Graph;
    18 typedef graph_traits < Graph >::vertex_descriptor VertexDescriptor;
    19 typedef graph_traits < Graph >::edge_descriptor EdgeDescriptor;
    20 typedef graph_traits<Graph>::edge_iterator EdgeIterator;
    21 typedef graph_traits<Graph>::vertex_iterator VertexIterator;
    22 typedef std::pair<int, int> Edge;
    23 typedef std::pair<EdgeDescriptor, bool> EdgeExistResult;
    24
    25 const int vertice_num = 65536;
    26
    27 Graph g(vertice_num);
    28
    29 add_edge(0, 1, 1, g); // first, second, weight, graph
    30 add_edge(1, 2, 1, g);
    31 add_edge(2, 3, 1, g);
    32 add_edge(1, 3, 1, g);
    33
    34 EdgeExistResult edge_exist = edge(3, 1, g);
    35 if (edge_exist.second == true) {
    36 cout << "yes" << endl;
    37 } else {
    38 cout << "no" << endl;
    39 }
    40
    41 EdgeIterator ei, ei_end;
    42 for (tie(ei, ei_end) = edges(g); ei != ei_end; ++ei) {
    43 cout << source(*ei, g) << "," << target(*ei, g) << endl;
    44 }
    45
    46 /* graph_traits<Graph>::vertex_iterator vi, vi_end;
    47 for (tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi) {
    48 cout << *vi << endl;
    49 } */
    50
    51 vector<VertexDescriptor> parent(num_vertices(g));
    52 vector<int> dist(num_vertices(g));
    53 VertexDescriptor s = vertex(3, g);
    54 dijkstra_shortest_paths(g, s, predecessor_map(&parent[0]).distance_map(&dist[0]));
    55 // shortest path from 3 to 0
    56 if (dist[0] != INT_MAX)
    57 cout << dist[0] << endl;
    58
    59 int i = 0;
    60 while (i != 3) {
    61 cout << i << endl;
    62 i = parent[i];
    63 }
    64 return 0;
    65
    66 }



  • 相关阅读:
    站立会议(二)
    站立会议(一)
    买书优惠问题
    软件的NABCD----安装部分
    你的灯亮着吗读书笔记(一)
    软件工程概论---环状二维数组最大子数组和
    梦断代码读书笔记(三)
    梦断代码读书笔记(二)
    课程作业3.10
    软件工程作业提交3.06
  • 原文地址:https://www.cnblogs.com/tzhangofseu/p/2244120.html
Copyright © 2020-2023  润新知