Boost logo

Boost Users :

Subject: Re: [Boost-users] Calling dijkstra_shortest_paths while including boost/graph/graphviz.hpp fails
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2012-12-18 13:43:59


On Tue, 18 Dec 2012, Brammert Ottens wrote:

> Hi,
>
> when I try to compile the following code it fails, but when I remove the graphviz part of the code it works just fine. Below I've added both my code and the error I get. Am I doing something wrong, or is this a bug in boost? The method ParseDIMECSGraph::ParseGraph simply parses a DIMECS challenge graph.
>
> #include "stdafx.h"
> #include "ParseDIMECSGraph.h"
> #include <boost/config.hpp>
> #include <boost/graph/graphviz.hpp>
> #include <boost/graph/adjacency_list.hpp>
> #include <boost/graph/dijkstra_shortest_paths.hpp>
> #include <boost/graph/graph_traits.hpp>
>
> using namespace boost;
>
> int _tmain(int argc, _TCHAR* argv[])
> {
> typedef adjacency_list<listS, vecS, directedS, no_property, property < edge_weight_t, int >> Graph;
> typedef graph_traits < Graph >::edge_descriptor edge_descriptor;
>
> Graph g = *ParseDIMECSGraph::ParseGraph("sample.gr");
>
> std::ofstream ofs( "test.dot" );
> write_graphviz(ofs, g);
> ofs.flush();
> ofs.close();
>
> typedef boost::graph_traits < Graph >::vertex_descriptor Vertex;
> std::vector<Vertex> predecessor(boost::num_vertices(g));
> std::vector<int> distances(boost::num_vertices(g));
>
> Vertex source = vertex(0, g);
> Vertex target = vertex(5, g);
>
> property_map<Graph, edge_weight_t>::type weightmap = get(edge_weight, g);
> property_map<Graph, vertex_index_t>::type indexmap = get(vertex_index, g);
>
> boost::dijkstra_shortest_paths( g,
> source,
> &predecessor[0],
> &distances[0],
> weightmap,
> indexmap,
> std::less<int>(),
> closed_plus<int>(),
> (std::numeric_limits<int>::max)(),
> 0,
> default_dijkstra_visitor());
> return 0;
> }

This seems to happen often with VC++. Try replacing "&predecessor[0]" by
"boost::make_iterator_property_map(predecessor.begin(),
get(boost::vertex_index, g))" and the same for "distances" and see if that
fixes anything.

-- Jeremiah Willcock


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net