Opened 7 years ago

Last modified 7 years ago

#11804 new Library Submissions

Contribution: edge-disjoint k-shortest paths

Reported by: Irek Szcześniak <irek@…> Owned by: Jeremiah Willcock
Milestone: To Be Determined Component: graph
Version: Boost 1.57.0 Severity: Not Applicable
Keywords: Cc:

Description

Hi,

I want to contribute a function that calculates edge-disjoint k-shortest paths.

The algorithm searches for a shortest path. Then it disables the edges of the shortest path, and repeats the search. On so on, until no path can be found.

I'm attaching the source file and a unit test.

There are two things that bug me in the code:

  • the predecessor map is hardcoded as:

boost::vector_property_map<edge_descriptor> pred(num_vertices(g));

while perhaps it should depend on the graph type,

  • the formatting of this call is ugly:

boost::dijkstra_shortest_paths

(fg, s,

visitor(make_dijkstra_visitor(record_edge_predecessors(pred, on_edge_relaxed()))));

I would appreciate it, if someone could give me a hint on these two problems.

I would also appreciate very much any comments and improvements.

Thanks!

Attachments (13)

edge_disjoint_ksp.hpp (3.8 KB ) - added by Irek Szcześniak <irek@…> 7 years ago.
the implementation
edge_disjoint_ksp.cc (3.3 KB ) - added by Irek Szcześniak <irek@…> 7 years ago.
the unit test
edge_disjoint_ksp.2.hpp (3.8 KB ) - added by Irek Szcześniak <irek@…> 7 years ago.
the implementation - v2
edge_disjoint_ksp.2.cc (3.3 KB ) - added by Irek Szcześniak <irek@…> 7 years ago.
the unit test - v2
edge_disjoint_ksp.3.hpp (7.3 KB ) - added by Irek Szcześniak <irek@…> 7 years ago.
edge_disjoint_ksp.3.cc (3.7 KB ) - added by Irek Szcześniak <irek@…> 7 years ago.
the unit test - v3
edge_disjoint_ksp.4.hpp (4.1 KB ) - added by Irek Szcześniak <irek@…> 7 years ago.
the implementation - v4
custom_dijkstra_call.hpp (3.8 KB ) - added by Irek Szcześniak <irek@…> 7 years ago.
the implementation of the custom dijkstra call - v1
exclude_filter.hpp (1.1 KB ) - added by Irek Szcześniak <irek@…> 7 years ago.
the implementation of the exclude filter - v1
edge_disjoint_ksp.5.hpp (3.9 KB ) - added by Irek Szcześniak <irek@…> 7 years ago.
the implementation - v5
custom_dijkstra_call.2.hpp (3.8 KB ) - added by Irek Szcześniak <irek@…> 7 years ago.
the implementation of the custom dijkstra call - v2
edge_disjoint_ksp.6.hpp (3.9 KB ) - added by Irek Szcześniak <irek@…> 7 years ago.
the implementation - v6
edge_disjoint_ksp.4.cc (2.8 KB ) - added by Irek Szcześniak <irek@…> 7 years ago.
the unit test - v4

Download all attachments as: .zip

Change History (22)

by Irek Szcześniak <irek@…>, 7 years ago

Attachment: edge_disjoint_ksp.hpp added

the implementation

by Irek Szcześniak <irek@…>, 7 years ago

Attachment: edge_disjoint_ksp.cc added

the unit test

by Irek Szcześniak <irek@…>, 7 years ago

Attachment: edge_disjoint_ksp.2.hpp added

the implementation - v2

by Irek Szcześniak <irek@…>, 7 years ago

Attachment: edge_disjoint_ksp.2.cc added

the unit test - v2

comment:1 by Irek Szcześniak <irek@…>, 7 years ago

I attached the second version of the implementation and the unit test. Now the function returns its results in a list, not in a multiset anymore.

comment:2 by Irek Szcześniak <irek@…>, 7 years ago

The reasoning for the used data types:

  • the excluded edges are stored in a set in edksp_filter, to make sure that the edge lookup is fast,
  • the path is a list (and not a vector), because the length of the path is not known up front (building a path as a vector could resize the vector), and the paths are not expected to be heavily used to merit the use of a vector,
  • for the same reasons as for a path, the found paths are returned in a list, not a vector.

by Irek Szcześniak <irek@…>, 7 years ago

Attachment: edge_disjoint_ksp.3.hpp added

by Irek Szcześniak <irek@…>, 7 years ago

Attachment: edge_disjoint_ksp.3.cc added

the unit test - v3

comment:3 by Irek Szcześniak <irek@…>, 7 years ago

I attached the third version of the implementation and the unit test. This revision has a number of changes:

  • bug fix: the Dijkstra call is using the right property map (wm), and not the graph's built in,
  • new feature: the user is allowed to provide an optional argument K, which limits the search to at most K shortest paths,
  • performance improvement: the Dijkstra search is stopped as soon as the shortest path to the destination vertex is found,
  • added more comments,
  • moved the call to Dijkstra to a separate function, and made the call well-formatted (i.e., it's not very long).

by Irek Szcześniak <irek@…>, 7 years ago

Attachment: edge_disjoint_ksp.4.hpp added

the implementation - v4

by Irek Szcześniak <irek@…>, 7 years ago

Attachment: custom_dijkstra_call.hpp added

the implementation of the custom dijkstra call - v1

by Irek Szcześniak <irek@…>, 7 years ago

Attachment: exclude_filter.hpp added

the implementation of the exclude filter - v1

comment:4 by Irek Szcześniak <irek@…>, 7 years ago

Made the implementation more generic by allowing a user to provide the vector index map. I also moved the implementation of the exclude filter and the custom dijkstra call to separate files.

comment:5 by Irek Szcześniak <irek@…>, 7 years ago

Thanks to Daniel Hofmann for his advice on how to better call the Dijkstra function, i.e. to use the iterator_property_map, and to let the user provide the vector index map. Many thanks!

by Irek Szcześniak <irek@…>, 7 years ago

Attachment: edge_disjoint_ksp.5.hpp added

the implementation - v5

by Irek Szcześniak <irek@…>, 7 years ago

Attachment: custom_dijkstra_call.2.hpp added

the implementation of the custom dijkstra call - v2

comment:6 by Irek Szcześniak <irek@…>, 7 years ago

In revisions just added (edge_disjoint_ksp.5.hpp and custom_dijkstra_call.2.hpp), I only cleaned up the inclusion of header files.

comment:7 by Irek Szcześniak <irek@…>, 7 years ago

I would appreciate some advice on what I should do next to contribute this code. Please let me know.

comment:8 by anonymous, 7 years ago

Compile the unit test like this:

g++ -std=c++11 edge_disjoint_ksp.cc -l boost_unit_test_framework -l boost_test_exec_monitor -o edge_disjoint_ksp

by Irek Szcześniak <irek@…>, 7 years ago

Attachment: edge_disjoint_ksp.6.hpp added

the implementation - v6

by Irek Szcześniak <irek@…>, 7 years ago

Attachment: edge_disjoint_ksp.4.cc added

the unit test - v4

comment:9 by Irek Szcześniak <irek@…>, 7 years ago

I added a simplified implementation and a modified unit test. This implementation does not use the exclude_filter.hpp, which I implemented. Instead, we use the filter provided by the filtered_graph.

Note: See TracTickets for help on using tickets.