Esempio n. 1
0
 /// <summary>
 /// Gets the minimum-weight path to a goal using uniform cost search.
 /// </summary>
 /// <typeparam name="TNode">The type of a node.</typeparam>
 /// <typeparam name="TKey">The type of a node key.</typeparam>
 /// <param name="sources">The set of nodes from which to start the search, weighted by their initial cost.</param>
 /// <param name="descriptor">The object describing how to navigate the weighted graph.</param>
 /// <param name="goal">The goal predicate.</param>
 /// <returns>The minimum-weight path, or null if none exists.</returns>
 public static IWeighted <IEnumerable <TNode> > UniformCostSearch <TNode, TKey>(
     this IEnumerable <IWeighted <TNode> > sources,
     IWeightedGraphDescriptor <TNode, TKey> descriptor,
     Func <TNode, bool> goal)
 {
     return(UniformCostSearch(sources, descriptor.Key, descriptor.Next, goal));
 }
Esempio n. 2
0
 /// <summary>
 /// Gets the minimum-weight path to a goal using the A* algorithm.
 /// </summary>
 /// <typeparam name="TNode">The type of a node.</typeparam>
 /// <typeparam name="TKey">The type of a node key.</typeparam>
 /// <param name="sources">The set of nodes from which to start the search, weighted by their initial cost.</param>
 /// <param name="descriptor">The object describing how to navigate the weighted graph.</param>
 /// <param name="goal">The goal predicate.</param>
 /// <param name="heuristic">The heuristic function.</param>
 /// <returns>The minimum-weight path, or null if none exists.</returns>
 public static IWeighted <IEnumerable <TNode> > AStar <TNode, TKey>(
     this IEnumerable <IWeighted <TNode> > sources,
     IWeightedGraphDescriptor <TNode, TKey> descriptor,
     Func <TNode, bool> goal,
     IHeuristic <TNode> heuristic)
 {
     return(AStar(sources, descriptor.Key, descriptor.Next, goal, heuristic));
 }
 public static IGraphDescriptor <TNode, TKey> AsGraphDescriptor <TNode, TKey>(
     this IWeightedGraphDescriptor <TNode, TKey> descriptor)
 {
     return(GraphDescriptor.Create <TNode, TKey>(descriptor.Key, u => descriptor.Next(u).Select(uv => uv.Value)));
 }