I've implimented this snippet of code
dijkstra_shortest_paths(
g, name2v[tempName1],
get(&VertexProperty::predecessor, g),
get(&VertexProperty::distance, g),
get(&EdgeProperty::weight, g),
boost::identity_property_map(), // index-map
std::less<double>(), // compare
std::plus<double>(), // combine
std::numeric_limits<double>::infinity(), // infinity
0.0, // zero
do_nothing_dijkstra_visitor(),
get(&VertexProperty::color, g));
to use dijkstra's on a map created from a text file, but I have no idea how to output the vertex I start at to the next one required to be visited and the distance between them repeatedly followed by the total distance traveled.
I can post any part of the code to assists with this.
I think this may be required, this is what I used to build the graph:
std::map<std::string, Vertex> name2v;
std::getline(fin, tempString); //Vertices:
std::getline(fin, tempString); //Location1, Location2, ...
std::stringstream tempSS(tempString);
while (std::getline(tempSS,tempName1, ',')){
name2v[tempName1] = add_vertex(VertexProperty(tempName1), g);
}
std::getline(fin,tempString); //Edges:
while (std::getline(fin,tempString)){ // (Location1, Location2, 6)
//remove parentheses
tempString.erase( tempString.begin(), tempString.begin() + tempString.find('(') + 1 );
tempString.erase( tempString.begin() + tempString.find(')'), tempString.end() );
std::stringstream temp_ss(tempString);
std::getline(temp_ss, tempName1, ',');
std::getline(temp_ss, tempName2, ',');
temp_ss >> weight;
add_edge(name2v[tempName1],name2v[tempName2],EdgeProperty(weight), g);
}
and if for some reason this is required to help me these are all of the things I've had to build to try to get this program working:
typedef boost::adjacency_list_traits<
boost::vecS, boost::vecS, boost::undirectedS, boost::listS> GraphTraits;
typedef GraphTraits::vertex_descriptor Vertex;
struct VertexProperty {
std::string name;
Vertex predecessor;
double distance;
boost::default_color_type color;
VertexProperty(const std::string& aName = "") : name(aName) { };
};
struct EdgeProperty {
double weight;
EdgeProperty(double aWeight = 0.0) : weight(aWeight) { };
};
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, VertexProperty, EdgeProperty> Graph;
Graph g;
typedef float Weight;
typedef boost::adjacency_list_traits<
boost::vecS, boost::vecS, boost::undirectedS, boost::listS> GraphTraits;
typedef boost::property<boost::edge_weight_t, Weight> WeightProperty;
typedef boost::property<boost::vertex_name_t, std::string> NameProperty;
std::vector<Vertex> predecessors(boost::num_vertices(g)); // To store parents
std::vector<Weight> distances(boost::num_vertices(g)); // To store distances
struct do_nothing_dijkstra_visitor {
template <typename Vertex, typename Graph>
void initialize_vertex(Vertex u, const Graph& g) const { };
template <typename Vertex, typename Graph>
void examine_vertex(Vertex u, const Graph& g) const { };
template <typename Edge, typename Graph>
void examine_edge(Edge e, const Graph& g) const { };
template <typename Vertex, typename Graph>
void discover_vertex(Vertex u, const Graph& g) const { };
template <typename Edge, typename Graph>
void edge_relaxed(Edge e, const Graph& g) const { };
template <typename Edge, typename Graph>
void edge_not_relaxed(Edge e, const Graph& g) const { };
template <typename Vertex, typename Graph>
void finish_vertex(Vertex u, const Graph& g) const { };
};