/// <summary> /// Initialize and observe an <see cref="HeuristicSearchBase{TFactor, TStep}"/> instance with A* search algorithm. /// </summary> /// <typeparam name="TStep">The type of step of the problem.</typeparam> /// <param name="from">The initial step of the problem.</param> /// <param name="to">The goal step of the problem.</param> /// <param name="expander">The callback that expands specific step to available next steps.</param> /// <param name="comparer">The comparer to test equality of two <typeparamref name="TStep"/> instances.</param> /// <param name="observerFactory">The object that is able to create <see cref="IProgress{T}"/> instances.</param> /// <returns>The instance that is ready to be applied with LINQ expressions.</returns> /// <exception cref="ArgumentNullException"><paramref name="expander"/> is null.</exception> public static HeuristicSearchBase <TStep, TStep> AStar <TStep>(TStep from, TStep to, Func <TStep, int, IEnumerable <TStep> > expander, IEqualityComparer <TStep> comparer, IAlgorithmObserverFactory <TStep> observerFactory) { return(new HeuristicSearchInitial <TStep>(nameof(AStar), from, to, comparer, expander) { AlgorithmObserverFactory = observerFactory }); }
/// <summary> /// Initialize and observe an <see cref="HeuristicSearchBase{TFactor, TStep}"/> instance with user-defined algorithm. /// </summary> /// <typeparam name="TStep">The type of step of the problem.</typeparam> /// <param name="algorithmName">The name of algorithm</param> /// <param name="from">The initial step of the problem.</param> /// <param name="to">The goal step of the problem.</param> /// <param name="expander">The callback that expands specific step to available next steps.</param> /// <param name="comparer">The comparer to test equality of two <typeparamref name="TStep"/> instances.</param> /// <param name="observerFactory">The object that is able to create <see cref="IProgress{T}"/> instances.</param> /// <returns>The instance that is ready to be applied with LINQ expressions.</returns> /// <exception cref="ArgumentNullException"><paramref name="algorithmName"/> or <paramref name="expander"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="algorithmName"/> cannot be found.</exception> public static HeuristicSearchBase <TStep, TStep> Use <TStep>(string algorithmName, TStep from, TStep to, Func <TStep, int, IEnumerable <TStep> > expander, IEqualityComparer <TStep> comparer, IAlgorithmObserverFactory <TStep> observerFactory) { try { if (!algorithms.ContainsKey(algorithmName)) { throw new ArgumentException(nameof(algorithmName)); } } catch (ArgumentNullException e) { throw new ArgumentNullException(nameof(algorithmName), e); } return(new HeuristicSearchInitial <TStep>(algorithmName, from, to, comparer, expander) { AlgorithmObserverFactory = observerFactory }); }