-1

I've got a project with a large graph filled like this:

struct EdgeItem{
    int mPid1;
    int mPid2;
    double weight;
};
struct StationItem{
    int mPid;
    QString mName;
};
QMap<int, StationItem> StationsMap;
QList<EdgeItem> mEdgesList;
QVector<EdgeItem*> GetEdgesByPid(int Pid);
// and some other service methods

Stations map indexed by Pid. Graph's edges as MapLayerEdgeItem have weight. It's inmportant no not have to copy graph's data and use existing structures. I need to run and calculate dijkstra_shortest_paths on it. Please suggest what I need to start with.

Dmitry Ilukhin
  • 490
  • 3
  • 9
  • See the [Docs](http://www.boost.org/doc/libs/1_57_0/libs/graph/doc/dijkstra_shortest_paths.html) and [example](http://www.boost.org/doc/libs/1_57_0/libs/graph/example/dijkstra-example.cpp) – pbible Feb 03 '15 at 22:08
  • "When you ask Nix programmer for a toilet paper, he gives you an axe and shows nearest forest". An examples provided with boost docs graph is known as quite simple and not including all situations. You linked a sample that using simple arrays. I need to use QMap and QList without copying data to another format. Thank you. – Dmitry Ilukhin Feb 04 '15 at 09:21
  • You asked please suggest what I need to start. I think the the docs and example is a great place. If you want to use the built in algorithms you need to use the boost graph interface. Dijkstra isn't that hard to implement. if I were you I would roll my own. Otherwise you need to adapt your structures to the interface. – pbible Feb 04 '15 at 13:33
  • See this [adapting other graphs to boost](http://www.boost.org/doc/libs/1_57_0/libs/graph/doc/leda_conversion.html) and this [question](http://stackoverflow.com/questions/20418753/boost-graph-designing-without-adjacency-list-or-adjacency-matrix). – pbible Feb 04 '15 at 13:43

1 Answers1

2

In order do this you need to first adapt your graph to the boost graph library (BGL) interface. As mentioned in the comment look at this question which links boost's how to convert existing graphs.

It seems you are really asking two questions. How do I adapt my graph representation to BGL? and How do I perform (and extract meaning from) Dijsktra in boost?

Both aren't exactly trivial if you are not used to BGL. Why not try to tackle the adapter then ask a more specific question when you run into trouble?

If all you need is Djikstra, I would suggest using your own implementation. If you think you will use other BGL functionality then an adapter is the way to go.

Community
  • 1
  • 1
pbible
  • 1,259
  • 1
  • 18
  • 34