Note that there are some explanatory texts on larger screens.

plurals
  1. PODijkstra Shortest Path with VertexList = ListS in boost graph
    primarykey
    data
    text
    <p>I am quite new to Boost graph. I am trying to adapt an example for finding Dijkstra Shortest Path algorithm which used VertexList = vecS. I changed the vertex container to ListS. I learned that we have to provide our own vertex_index for the algorithm to work if we use listS.</p> <pre><code>int main(int, char *[]) { typedef float Weight; typedef boost::property&lt;boost::edge_weight_t, Weight&gt; WeightProperty; typedef boost::property&lt;boost::vertex_name_t, std::string&gt; NameProperty; typedef boost::property&lt;boost::vertex_index_t, int&gt; IndexProperty; typedef boost::adjacency_list &lt; boost::listS, boost::listS, boost::directedS, NameProperty, WeightProperty &gt; Graph; typedef boost::graph_traits &lt; Graph &gt;::vertex_descriptor Vertex; typedef boost::graph_traits &lt;Graph&gt;::vertex_iterator Viter; typedef boost::property_map &lt; Graph, boost::vertex_index_t &gt;::type IndexMap; typedef boost::property_map &lt; Graph, boost::vertex_name_t &gt;::type NameMap; typedef boost::iterator_property_map &lt; Vertex*, IndexMap, Vertex, Vertex&amp; &gt; PredecessorMap; typedef boost::iterator_property_map &lt; Weight*, IndexMap, Weight, Weight&amp; &gt; DistanceMap; Graph g; Vertex v0 = boost::add_vertex(std::string("v0"), g); Vertex v1 = boost::add_vertex(std::string("v1"), g); Vertex v2 = boost::add_vertex(std::string("v2"), g); Vertex v3 = boost::add_vertex(std::string("v3"), g); Weight weight0 = 5; Weight weight1 = 3; Weight weight2 = 2; Weight weight3 = 4; boost::add_edge(v0, v1, weight0, g); boost::add_edge(v1, v3, weight1, g); boost::add_edge(v0, v2, weight2, g); boost::add_edge(v2, v3, weight3, g); std::vector&lt;Vertex&gt; predecessors(boost::num_vertices(g)); // To store parents std::vector&lt;Weight&gt; distances(boost::num_vertices(g)); // To store distances IndexMap indexMap; // = boost::get(boost::vertex_index, g); NameMap name; Viter i, iend; //Create our own vertex index. This is what I changed in the original code int c = 0; for (boost::tie(i, iend) = vertices(g); i != iend; ++i, ++c) { indexMap[*i] = c; // **Error points to this line** name[*i] = 'A' + c; } PredecessorMap predecessorMap(&amp;predecessors[0], indexMap); DistanceMap distanceMap(&amp;distances[0], indexMap); boost::dijkstra_shortest_paths(g, v0, boost::distance_map(distanceMap).predecessor_map(predecessorMap)); // Extract a shortest path std::cout &lt;&lt; std::endl; typedef std::vector&lt;Graph::edge_descriptor&gt; PathType; PathType path; Vertex v = v3; for(Vertex u = predecessorMap[v]; u != v; // Keep tracking the path until we get to the source v = u, u = predecessorMap[v]) // Set the current vertex to the current predecessor, and the predecessor to one level up { std::pair&lt;Graph::edge_descriptor, bool&gt; edgePair = boost::edge(u, v, g); Graph::edge_descriptor edge = edgePair.first; path.push_back( edge ); } // Write shortest path std::cout &lt;&lt; "Shortest path from v0 to v3:" &lt;&lt; std::endl; float totalDistance = 0; for(PathType::reverse_iterator pathIterator = path.rbegin(); pathIterator != path.rend(); ++pathIterator) { std::cout &lt;&lt; name[boost::source(*pathIterator, g)] &lt;&lt; " -&gt; " &lt;&lt; name[boost::target(*pathIterator, g)] &lt;&lt; " = " &lt;&lt; boost::get( boost::edge_weight, g, *pathIterator ) &lt;&lt; std::endl; } std::cout &lt;&lt; std::endl; std::cout &lt;&lt; "Distance: " &lt;&lt; distanceMap[v3] &lt;&lt; std::endl; return EXIT_SUCCESS; } </code></pre> <p>I get the following error:</p> <p>/spvec.cpp:62:20: error: no match for ‘operator=’ in ‘index.boost::adj_list_vertex_property_map::operator[] [with Graph = boost::adjacency_list >, boost::property >, ValueType = boost::detail::error_property_not_found, Reference = boost::detail::error_property_not_found&amp;, Tag = boost::vertex_index_t, boost::adj_list_vertex_property_map::key_type = void*](i.std::_List_iterator&lt;_Tp>::operator* with _Tp = void*, _Tp&amp; = void*&amp;) = c’</p> <p>I am sure I made a mistake in creating my own vertex index. But couldn´t find out exactly what´s the issue. Does anyone have some suggestions on what I am doing wrong.. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload