Boost logo

Boost Users :

Subject: Re: [Boost-users] [graph] abort algorithm execution from a visitor
From: Daniel Hofmann (daniel_at_[hidden])
Date: 2016-02-22 16:53:31


Hey Frank,

for early exiting e.g. a BGL Dijkstra algorithm you can throw your local
type as a signal and than catch this on the call site.

Here are two early exit visitors I found useful:
> https://gist.github.com/daniel-j-h/0301b07ff3324b44e0c5

The first one is for the classical One-To-Many routing, the second one
for One-To-Many routing scenario.

The call site could look similar to:

    try {
      dijkstra_shortest_paths_no_color_map(graph,
        source,
        predecessor_map(predMap)
        .weight_map(weightMap)
        .disance_map(distanceMap)
       .visitor(stopOnTarget<Graph>{target}));
    } catch (const stopSearchSignal&) { }

If you need more advanced features e.g. you want to do a bidirectional
Dijkstra aborting in "the middle", follow this thread:
> http://lists.boost.org/boost-users/2015/11/85302.php

Cheers,
Daniel J H

On 02/22/2016 09:08 PM, Frank Tetzel wrote:
> Hi all,
>
> i played around with the bfs example calculating distances to all
> vertices. Now i just want to calculate the distance between two
> vertices, so i want to stop when the target vertex is visited.
>
> If i understood the visitor concept correctly it's not really possible
> to change the behaviour of the algorithm from a visitor. Does anybody
> know of any workaround to do early exit? Do i have to implement a new
> algorithm for this?
>
> In a different thread on this list Paolo Bolzoni wrote that he aborts in
> a custom visitor by throwing an exception. Is this the only way?
>
> I'm using bfs here and not dijkstra because i have uniform edge weights.
>
>
> Btw, if someone could fix the documentation that would be really nice:
>
> http://www.boost.org/doc/libs/1_60_0/libs/graph/doc/bfs_visitor.html
>
> The code snippet there did not work for me. I had to wrap
> make_bfs_visitor() in visitor() like it is done in examples/bfs.cpp too.
>
> Regards,
> Frank
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


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