Skip to content

Commit

Permalink
Update comments on graph searches.
Browse files Browse the repository at this point in the history
  • Loading branch information
renggli committed Sep 3, 2023
1 parent 3d7654b commit 5a8f72d
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions lib/src/graph/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@ import 'strategy.dart';

extension SearchGraphExtension<V, E> on Graph<V, E> {
/// Performs a search for the shortest path between [source] and [target].
///
/// - [edgeCost] is a function that returns the cost to traverse an edge
/// between two vertices. If no function is provided, the cost is assumed
/// to be constant with a weight of _1_.
///
/// - [costEstimate] is a function that returns the remaining cost from the
/// provided vertex. If an estimate is provided a faster _A*-Search_ is
/// performed, otherwise a _Dijkstra Search_.
///
Path<V>? shortestPath(
V source,
V target, {
num Function(Edge<V, E> edge)? edgeCost,
num Function(V target)? costEstimate,
num Function(V vertex)? costEstimate,
StorageStrategy<V>? vertexStrategy,
}) =>
shortestPathAll(
Expand All @@ -25,11 +34,20 @@ extension SearchGraphExtension<V, E> on Graph<V, E> {
vertexStrategy: vertexStrategy,
).firstOrNull;

/// Performs a search for the shortest paths between [source] and [target],
/// where the target is specified as a predicate over the vertices.
/// Performs a search for the shortest paths between [source] and the
/// [targetPredicate] predicate.
///
/// - [edgeCost] is a function that returns the cost to traverse an edge
/// between two vertices. If no function is provided, the cost is assumed
/// to be constant with a weight of _1_.
///
/// - [costEstimate] is a function that returns the remaining cost from the
/// provided vertex. If an estimate is provided a faster _A*-Search_ is
/// performed, otherwise a _Dijkstra Search_.
///
Iterable<Path<V>> shortestPathAll(
V source,
Predicate1<V> target, {
Predicate1<V> targetPredicate, {
num Function(Edge<V, E> edge)? edgeCost,
num Function(V target)? costEstimate,
StorageStrategy<V>? vertexStrategy,
Expand All @@ -42,14 +60,14 @@ extension SearchGraphExtension<V, E> on Graph<V, E> {
return costEstimate == null
? DijkstraSearchIterable<V>(
startVertices: [source],
targetPredicate: target,
targetPredicate: targetPredicate,
successorsOf: successorsOf,
edgeCost: vertexEdgeCost,
vertexStrategy: vertexStrategy,
)
: AStarSearchIterable<V>(
startVertices: [source],
targetPredicate: target,
targetPredicate: targetPredicate,
successorsOf: successorsOf,
costEstimate: costEstimate,
edgeCost: vertexEdgeCost,
Expand Down

0 comments on commit 5a8f72d

Please sign in to comment.