public List <CandidateState> search(SortAlgorithmType pSortAlgorithmType = SortAlgorithmType.BSF)
        {
            List <ActionStateInterface> visited = new List <ActionStateInterface>();
            CandidateState        candidate     = new CandidateState(this._initialState);
            List <CandidateState> pending       = new List <CandidateState>()
            {
                candidate
            };
            int i = 0;

            while (pending.Any())
            {
                candidate = pSortAlgorithmType == SortAlgorithmType.DSF ? pending.Pop() : pending.Shift();
                i++;

                if (i % 1000 == 0)
                {
                    Console.WriteLine(i);
                }

                if (this._finalState.Any(state => state.Equals(candidate.ActionState)))
                {
                    List <CandidateState> result = new List <CandidateState>();

                    while (candidate != null)
                    {
                        result.Add(candidate);
                        candidate = candidate.ParentCandidateState;
                    }

                    result.Reverse();
                    return(result);
                }
                else
                {
                    visited.Add(candidate.ActionState);

                    List <CandidateState> successors = candidate.getSuccessors();

                    foreach (CandidateState successor in successors)
                    {
                        if (!visited.Any(state => state.Equals(successor.ActionState)))
                        {
                            pending.Add(successor);
                        }
                    }
                }
            }

            return(null);
        }
Example #2
0
        public static ISort <T> Get <T>(SortAlgorithmType type, Action <int, T[]> progressAction) where T : IComparable
        {
            switch (type)
            {
            case SortAlgorithmType.Bogo:
                return(new Bogosort <T>(progressAction));

            case SortAlgorithmType.BruteForce:
                return(new BruteForceSort <T>(progressAction));

            case SortAlgorithmType.Bubble:
                return(new BubbleSort <T>(progressAction));

            case SortAlgorithmType.BubbleSelection:
                return(new BubbleSelectionSort <T>(progressAction));

            case SortAlgorithmType.Selection:
                return(new SelectionSort <T>(progressAction));

            case SortAlgorithmType.Pancake:
                return(new PancakeSort <T>(progressAction));

            case SortAlgorithmType.Stooge:
                return(new StoogeSort <T>(progressAction));

            case SortAlgorithmType.Gnome:
                return(new GnomeSort <T>(progressAction));

            case SortAlgorithmType.Comb:
                return(new CombSort <T>(progressAction));

            case SortAlgorithmType.Insertion:
                return(new InsertionSort <T>(progressAction));

            case SortAlgorithmType.OddEven:
                return(new OddEvenSort <T>(progressAction));

            case SortAlgorithmType.Cocktail:
                return(new CocktailSort <T>(progressAction));

            case SortAlgorithmType.Tree:
                return(new TreeSort <T>(progressAction));

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SortAlgorithmDescription"/> struct.
 /// </summary>
 /// <param name="type">The sort algorithm type.</param>
 /// <param name="label">The label, e.g. "merge sort".</param>
 public SortAlgorithmDescription(SortAlgorithmType type, string label)
 {
     this.Type  = type;
     this.Label = label;
 }
Example #4
0
 /// <summary>
 /// Sorts the input values using specified sort algorithm and reports progress.
 /// </summary>
 /// <param name="values">The input values to sort.</param>
 /// <param name="type">The sort algorithm type.</param>
 /// <param name="progress">The sort algorithm progress callback.</param>
 /// <returns>A completed task.</returns>
 public Task Sort(int[] values, SortAlgorithmType type, Action <SortProgress> progress)
 {
     this.sortAlgorithmMap[type].Sort(values, progress);
     return(Task.CompletedTask);
 }