#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/chrono.hpp>
#include <algorithm>
#include <ctime>
#include <boost/graph/graphviz.hpp>
#include <boost/graph/grid_graph.hpp>
#include <boost/array.hpp>
#include <boost/graph/grid_graph.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/test/unit_test.hpp>
#include <iostream> // for std::cout
#include <utility> // for std::pair
#include <algorithm> // for std::for_each
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/config.hpp>
#include <iostream>
#include <fstream>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/graph/graphviz.hpp>
using namespace std;
using namespace boost;
using namespace boost::gregorian;
#define DIMENSIONS 2
typedef grid_graph<2> Graph;
typedef graph_traits<Graph> Traits;
// Define a simple function to print vertices
void print_vertex(Traits::vertex_descriptor vertex_to_print) {
std::cout << "(" << vertex_to_print[0] << ", " << vertex_to_print[1] << ")" << std::endl;
}
int main(int argc, char* argv[]) {
// Define a 3x5 grid_graph where the second dimension doesn't wrap
// boost::array<std::size_t, 2> lengths = { { 3, 5 } };
boost::array<size_t, 2> lengths = { { 3, 5 } };
Graph graph(lengths);
// Do a round-trip test of the vertex index functions
for (Traits::vertices_size_type v_index = 0;
v_index < num_vertices(graph); ++v_index) {
// The two indicies should always be equal
std::cout << "Index of vertex " << v_index << " is " <<
get(boost::vertex_index, graph, vertex(v_index, graph)) << std::endl;
}
// Do a round-trip test of the edge index functions
for (Traits::edges_size_type e_index = 0;
e_index < num_edges(graph); ++e_index) {
// The two indicies should always be equal
std::cout << "Index of edge " << e_index << " is " <<
get(boost::edge_index, graph, edge_at(e_index, graph)) << std::endl;
}
// Print number of dimensions
std::cout << graph.dimensions() << std::endl; // prints "3"
// Print dimension lengths (same order as in the lengths array)
std::cout << graph.length(0) << "x" << graph.length(1) << std::endl; // prints "3x5x7"
// Start with the first vertex in the graph
Traits::vertex_descriptor first_vertex = vertex(0, graph);
print_vertex(first_vertex); // prints "(0, 0)"
// Print the next vertex in dimension 0
print_vertex(graph.next(first_vertex, 0)); // prints "(1, 0)"
// Print the next vertex in dimension 1
print_vertex(graph.next(first_vertex, 1)); // prints "(0, 1)"
}
所以这是Boost库的Grid图。但我不知道如何用int权重实现边。我应该用什么属性来做呢? 我可以遍历边缘和节点,但只能遍历它们的缺点,而不是它们的值。