-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from stdgraph/dijkstra_visitor
Revise to add Dijkstra shortest paths and distances with visitor
- Loading branch information
Showing
8 changed files
with
202 additions
and
108 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
template <index_adjacency_list G, | ||
ranges::random_access_range Distances, | ||
class WF = std::function<ranges::range_value_t<Distances>(edge_reference_t<G>)>, | ||
class Visitor = dijkstra_visitor_base<G>, | ||
class Compare = less<ranges::range_value_t<Distances>>, | ||
class Combine = plus<ranges::range_value_t<Distances>>> | ||
requires is_arithmetic_v<ranges::range_value_t<Distances>> && // | ||
basic_edge_weight_function<G, WF, ranges::range_value_t<Distances>, Compare, Combine> && | ||
dijkstra_visitor<G, Visitor> | ||
void dijkstra_shortest_distances( | ||
G& g, | ||
const vertex_id_t<G> source, | ||
Distances& distances, | ||
WF&& weight = | ||
[](edge_reference_t<G> uv) { return ranges::range_value_t<Distances>(1); }, | ||
Visitor&& visitor = dijkstra_visitor_base<G>(), | ||
Compare&& compare = less<ranges::range_value_t<Distances>>(), | ||
Combine&& combine = plus<ranges::range_value_t<Distances>>()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
template <index_adjacency_list G, | ||
ranges::random_access_range Distances, | ||
ranges::random_access_range Predecessors, | ||
class WF = std::function<ranges::range_value_t<Distances>(edge_reference_t<G>)>, | ||
class Visitor = dijkstra_visitor_base<G>, | ||
class Compare = less<ranges::range_value_t<Distances>>, | ||
class Combine = plus<ranges::range_value_t<Distances>>> | ||
requires is_arithmetic_v<ranges::range_value_t<Distances>> && // | ||
convertible_to<vertex_id_t<G>, ranges::range_value_t<Predecessors>> && | ||
basic_edge_weight_function<G, WF, ranges::range_value_t<Distances>, Compare, Combine> && | ||
dijkstra_visitor<G, Visitor> | ||
void dijkstra_shortest_paths( | ||
G& g, | ||
const vertex_id_t<G> source, | ||
Distances& distances, | ||
Predecessors& predecessor, | ||
WF&& weight = | ||
[](edge_reference_t<G> uv) { return ranges::range_value_t<Distances>(1); }, | ||
Visitor&& visitor = dijkstra_visitor_base<G>(), | ||
Compare&& compare = less<ranges::range_value_t<Distances>>(), | ||
Combine&& combine = plus<ranges::range_value_t<Distances>>()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
template <adjacency_list G> | ||
class dijkstra_visitor_base { | ||
public: | ||
using graph_type = G; | ||
using vertex_desc_type = vertex_descriptor<vertex_id_t<G>, vertex_reference_t<G>, void>; | ||
using sourced_edge_desc_type = edge_descriptor<vertex_id_t<G>, true, edge_reference_t<G>, void>; | ||
|
||
// vertex visitor functions | ||
constexpr void on_initialize_vertex(vertex_desc_type&& vdesc) {} | ||
constexpr void on_discover_vertex(vertex_desc_type&& vdesc) {} | ||
constexpr void on_examine_vertex(vertex_desc_type&& vdesc) {} | ||
constexpr void on_finish_vertex(vertex_desc_type&& vdesc) {} | ||
|
||
// edge visitor functions | ||
constexpr void on_examine_edge(sourced_edge_desc_type&& edesc) {} | ||
constexpr void on_edge_relaxed(sourced_edge_desc_type&& edesc) {} | ||
constexpr void on_edge_not_relaxed(sourced_edge_desc_type&& edesc) {} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
template <class G, class Visitor> // for exposition only | ||
concept dijkstra_visitor = | ||
requires(Visitor& v, Visitor::vertex_desc_type& vdesc, Visitor::sourced_edge_desc_type& edesc) { | ||
{ v.on_initialize_vertex(vdesc) }; | ||
{ v.on_discover_vertex(vdesc) }; | ||
{ v.on_examine_vertex(vdesc) }; | ||
{ v.on_finish_vertex(vdesc) }; | ||
|
||
{ v.on_examine_edge(edesc) }; | ||
{ v.on_edge_relaxed(edesc) }; | ||
{ v.on_edge_not_relaxed(edesc) }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.