RE: [Boost-Users] [BGL] Best way to abort an algorithm from withi n a visitor?
Steve M. Robbins [mailto:steven.robbins@videotron.ca] wrote:
I use that technique to abort the Dijkstra shortest path search when I find my goal node. It works fine, as far as I can tell, but I'd be interested to learn if there is a better way. It seems anti-idiomatic to me. Exceptions are intended to signify exceptional circumstances that you would not normally expect to encounter (at least according to one school of thought).
An exception tells me "Oops, something went wrong here" not "we succeeded, here's the answer". Many of the exceptions I catch are called "oops": try { /* ... */ } catch (std::exception &oops) { /* ... */ } One possible snag might be if your code interacts with someone else's code, which will catch the exception and not pass it on to you. In the context we're talking about, though, I don't see that as a significant problem. An exception is certainly an easy way to abort the search, and since I don't have an alternative to offer, I'll shut up now ;=) -- Jim
Hi Jim, the problem here is that when using the generic BGL algorithms,
there's no explicit way to feed control information (e.g. stop - I found
what I need) back to the algorithm that is sequencing through the graph and
dispatching "events" into your visitor code. I'm guessing the lack of such a
feedback path in the first several algorithms I've looked at is due to the
fact that aborting the algorithm is an atypical requirement?
"Jim.Hyslop"
Steve M. Robbins [mailto:steven.robbins@videotron.ca] wrote:
I use that technique to abort the Dijkstra shortest path search when I find my goal node. It works fine, as far as I can tell, but I'd be interested to learn if there is a better way. It seems anti-idiomatic to me. Exceptions are intended to signify exceptional circumstances that you would not normally expect to encounter (at least according to one school of thought).
An exception tells me "Oops, something went wrong here" not "we succeeded, here's the answer". Many of the exceptions I catch are called "oops":
try { /* ... */ } catch (std::exception &oops) { /* ... */ }
One possible snag might be if your code interacts with someone else's code, which will catch the exception and not pass it on to you. In the context we're talking about, though, I don't see that as a significant problem.
An exception is certainly an easy way to abort the search, and since I don't have an alternative to offer, I'll shut up now ;=)
-- Jim
participants (2)
-
Chris Russell
-
Jim.Hyslop