Opened 11 years ago

Closed 11 years ago

#5659 closed Bugs (fixed)

The closed_plus structure should accept a custom infinity value.

Reported by: Thomas Sewell <thomas.sewell@…> Owned by: Jeremiah Willcock
Milestone: To Be Determined Component: graph
Version: Boost 1.46.1 Severity: Problem
Keywords: Cc:

Description

I'm trying to run dijkstra_shortest_paths with a custom distance type (my graph supports two metrics, I want to find the length in metric A of the shortest paths according to metric B).

I've been struggling to understand why I was getting dependencies on MyDistType(int). It turns out that overloading + on MyDistType is only half the story. The default combine operator for distances comes from closed_plus, which assumes an infinity value can be constructed by std::numeric_limits<D>::max(). This function seems to degrade to trying the constructor T(n) for some int n (probably INT_MAX) if it isn't a known numeric type, leading to bizarre errors (buried under piles of template goop).

This patch gives instances of closed_plus a parameter to store the custom infinity value, defaulting to the one from std::numeric_limits. It also passes the correct default value in dijkstra_shortest_paths. I haven't checked whether any of the other algorithms that use closed_plus can potentially have non-standard infinity values.

Hope you agree this is an improvement.

Yours,

Thomas.

Attachments (1)

diff (1.7 KB ) - added by Thomas Sewell <thomas.sewell@…> 11 years ago.
diff

Download all attachments as: .zip

Change History (4)

by Thomas Sewell <thomas.sewell@…>, 11 years ago

Attachment: diff added

diff

in reply to:  description comment:1 by Thomas Sewell <thomas.sewell@…>, 11 years ago

An alternative fix, of course, would be to make it clear in the documentation of dijkstra_shortest_paths and similar that if you supply your own distance_inf then you *must* supply your own distance_combine, and/or to mandate that with a compile-time assertion in the named parameters interpreter.

comment:2 by Jeremiah Willcock, 11 years ago

Owner: changed from Andrew Sutton to Jeremiah Willcock
Status: newassigned

comment:3 by Jeremiah Willcock, 11 years ago

Resolution: fixed
Status: assignedclosed

(In [72960]) Applied patch from #5659, plus made similar changes to other algorithms that have inf parameters; did not add inf parameters to algorithms that did not already have them; fixes #5659

Note: See TracTickets for help on using tickets.