private static void GetSort(string sortName, AlgorithmBase <int> baseSort, IEnumerable <int> items) { var stopwatch = new Stopwatch(); baseSort.Items.AddRange(items); stopwatch.Start(); baseSort.Sort(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("{0}:\nSwopCount:{2} {1}", sortName, stopwatch.Elapsed, baseSort.SwopCount); stopwatch.Stop(); foreach (var item in baseSort.Items) { Console.Write("{0} ", item); } }
public void BaseSortTest() { //arrange var bases = new AlgorithmBase <int>(); bases.Items.AddRange(items); //act bases.Sort(); //assert for (int i = 0; i < items.Count; i++) { Assert.AreEqual(sorted[i], bases.Items[i]); } }
private void Btn_Click(AlgorithmBase <SortedItem> algorithm) { RefreshItems(); for (int i = 0; i < algorithm.Items.Count; i++) { algorithm.Items[i].SetPosition(i); } panel5.Refresh(); algorithm.CompareEvent += AlgorithmCompareEvent; algorithm.SwapEvent += AlgorithmSwapEvent; algorithm.SetEvent += AlgorithmSetEvent; var time = algorithm.Sort(); TimeLabel.Text = "Time: " + time.Seconds; SwapLabel.Text = "Qty swaps: " + algorithm.SwapCount; CompareLabel.Text = "Qty comparisons: " + algorithm.CompareCount; }
public void StartSorting(AlgorithmBase <SortedItem> listForSort) { panel4.Controls.Add(ComparisonLabel); panel4.Controls.Add(SwopLabel); TimeLabel.Text = "Время: "; panel4.Controls.Add(TimeLabel); listForSort.CompareEvent += ListForSort_CompareEvent; listForSort.SwopEvent += ListForSort_SwopEventAsync; panel4.Refresh(); var time = listForSort.Sort(); TimeLabel.Text += $"{time.Seconds}"; //SwopLabel.Text += listForSort.SwopCount; //ComparisonLabel.Text += listForSort.ComparisonCount; }
private void Btn_Click(AlgorithmBase <SortedItem> algorithm) { RefreshItems(); for (int i = 0; i < algorithm.Items.Count; i++)//решение heapSort { algorithm.Items[i].SetPosition(i); } panel3.Refresh(); algorithm.CompareEvent += Algorithm_CompareEvent; algorithm.SwapEvent += Algorithm_SwapEvent; algorithm.SetEvent += Algorithm_SetEvent; var time = algorithm.Sort(); TimeLabel.Text = "Время:" + time.Milliseconds + " ms"; SwapLabel.Text = "Колличество обменов:" + algorithm.SwapCount; CompareLabel.Text = "Колличество сравнений:" + algorithm.ComparisonCount; }
private void BtnClick(AlgorithmBase <SortedItem> algorithm) { RefreshItems(); for (int i = 0; i < algorithm.Items.Count; i++) { algorithm.Items[i].SetPosition(i); } panel3.Refresh(); algorithm.CompareEvent += AlgorithmCompareEvent; algorithm.SwopEvent += AlgorithmSwopEvent; algorithm.SetEvent += AlgoritmSetEvent; var time = algorithm.Sort(); TimeLbl.Text = "Время: " + time.Seconds; SwopLbl.Text = "Количество обменов: " + algorithm.SwopCount; CompareLbl.Text = "Количество сравнений: " + algorithm.ComparisonCount; }
private static double MeasureQuickGraphAlgorithmSpeed <TVertex, TEdge>( AlgorithmBase <IVertexListGraph <TVertex, TEdge> > algorithm, int iterationNum = 10) where TEdge : IEdge <TVertex> { Stopwatch sw = new Stopwatch(); for (int i = 0; i < iterationNum; i++) { sw.Start(); algorithm.Compute(); sw.Stop(); Console.WriteLine("Iteration " + i); } var elapsedMs = sw.ElapsedMilliseconds / (double)iterationNum; Console.WriteLine("QuickGraph: " + elapsedMs + " ms"); return(elapsedMs); }
private async Task <int> RunAlgorithm(int Index) { await Task.FromResult(0); AlgorithmBase algorithm = Context.Algorithms[Index].Algorithm; algorithm.Calculate(); StablePairsEvaluation stablePairsEvaluation = new StablePairsEvaluation(); GroupHappinessEvaluation groupHappinessEvaluation = new GroupHappinessEvaluation(); EgalitarianHappinessEvaluation egalitarianHappinessEvaluation = new EgalitarianHappinessEvaluation(); AlgorithmFinished?.Invoke(this, new AlgorithmEventArgs(Index, algorithm.Evaluate(stablePairsEvaluation), algorithm.Evaluate(groupHappinessEvaluation), algorithm.Evaluate(egalitarianHappinessEvaluation))); return(Index); }
private void BtnSortClick(AlgorithmBase <SortedItem> algorithm) { RefreshItems(); for (int i = 0; i < algorithm.Items.Count; i++) { algorithm.Items[i].SetPosition(i); } panel3.Refresh(); algorithm.CompareEvent += Algoritm_CompareEvent; algorithm.SwapEvent += Algoritm_SwapEvent; var time = algorithm.Sort(); timeLabel.Text = "Время: " + time.Seconds; compareLabel.Text = "Количество сравнений: " + algorithm.ComprisonCount; swapLabel.Text = "Количество обменов " + algorithm.SwapCount; }
private void BtnClick(AlgorithmBase <SortedItem> algorithm) { RefreshItems(); for (int i = 0; i < algorithm.Items.Count; i++) { algorithm.Items[i].SetPosition(i); } algorithm.CompareEvent += AlgorithmCompareEvent; algorithm.SwopEvent += AlgorithmSwopEvent; algorithm.SetEvent += AlgorithmSetEvent; var time = algorithm.Sort(); lblTime.Text = $"Время выполнения: {time.Milliseconds} мс"; lblComparison.Text = $"Количество сравнений: {algorithm.ComparisonCount}"; lblSwop.Text = $"Количество обменов: {algorithm.SwopCount}"; }
private void BtnClick(AlgorithmBase <SortedItem> algorithm) { RefreshItems(); for (int i = 0; i < algorithm.Items.Count; i++) { algorithm.Items[i].SetPos(i); } panel3.Refresh(); algorithm.CompareEvent += Algorithm_CompareEvent; algorithm.SwapEvent += Algorithm_SwapEvent; algorithm.SetEvent += AlgorithmSetEvent; var time = algorithm.Sort(); Time.Text = "Time: " + time.Seconds; Swap.Text = "Number swap: " + algorithm.SwapCount; Compare.Text = "Number comparison: " + algorithm.CompareCount; }
private void BttnSort_Click(AlgorithmBase <SortedItem> algorithm) { RefreshItems(); for (int i = 0; i < algorithm.Items.Count; i++) { algorithm.Items[i].SetPosition(i); } VisualizationPanel.Refresh(); algorithm.CompareEvent += AlgorithmCompareEvent; algorithm.SwopEvent += AlgorithmSwopEvent; algorithm.SetEvent += AlgorithmSetEvent; var time = algorithm.Sort(); TimeLabel.Text = "Time: " + time.Seconds; ComparsionsLabel.Text = "Compare: " + algorithm.ComparsionCount; SwopsLabel.Text = "Swops: " + algorithm.ComparsionCount; }
private void outputError(AlgorithmBase <double[, , ]> alg) { Console.WriteLine("Errors:"); var sample = new ClassifiedSample <double[, , ]>(); foreach (var obj in Data.Data) { var data = obj.Key; var key = new double[data.Length, 1, 1]; for (int i = 0; i < data.Length; i++) { key[i, 0, 0] = data[i]; } sample[key] = obj.Value; } var errors = alg.GetErrors(sample); var ec = errors.Count(); var dc = Data.Data.Count; var pct = Math.Round(100.0F * ec / dc, 2); Console.WriteLine("{0} of {1} ({2}%)", ec, dc, pct); }
/// <summary> /// Initialize algorithm according to type by index=<paramref name="algNum"/> /// </summary> /// <param name="algNum">algorithm type index</param> /// <param name="amount">collection size</param> private void InitializeAlgorithm(int amount = 0) { switch (algorithmType) { case AlgorithmType.BubbleSort: if (myOwncollection == null) { if (amount <= 0) { sortAlgorithm = new BubbleAlgorithm(); } else { sortAlgorithm = new BubbleAlgorithm(amount); } } else { sortAlgorithm = new BubbleAlgorithm(myOwncollection); } break; case AlgorithmType.CocktailSort: if (myOwncollection == null) { if (amount <= 0) { sortAlgorithm = new CoctailAlgorithm(); } else { sortAlgorithm = new CoctailAlgorithm(amount); } } else { sortAlgorithm = new CoctailAlgorithm(myOwncollection); } break; case AlgorithmType.InsertionSort: if (myOwncollection is null) { if (amount <= 0) { sortAlgorithm = new InsertionAlgorithm(); } else { sortAlgorithm = new InsertionAlgorithm(amount); } } else { sortAlgorithm = new InsertionAlgorithm(myOwncollection); } break; case AlgorithmType.ShellSort: if (myOwncollection is null) { if (amount <= 0) { sortAlgorithm = new ShellAlgorithm(); } else { sortAlgorithm = new ShellAlgorithm(amount); } } else { sortAlgorithm = new ShellAlgorithm(myOwncollection); } break; case AlgorithmType.SelectionSort: if (myOwncollection is null) { if (amount <= 0) { sortAlgorithm = new SelectionAlgorithm(); } else { sortAlgorithm = new SelectionAlgorithm(amount); } } else { sortAlgorithm = new SelectionAlgorithm(myOwncollection); } break; case AlgorithmType.GnomeSort: if (myOwncollection is null) { if (amount <= 0) { sortAlgorithm = new GnomeAlgorithm(); } else { sortAlgorithm = new GnomeAlgorithm(amount); } } else { sortAlgorithm = new GnomeAlgorithm(myOwncollection); } break; case AlgorithmType.BinaryTreeSort: if (myOwncollection is null) { if (amount <= 0) { sortAlgorithm = new BinaryTree(); } else { sortAlgorithm = new BinaryTree(amount); } } else { sortAlgorithm = new BinaryTree(myOwncollection); } break; case AlgorithmType.RadixSort: break; case AlgorithmType.MergeSort: break; case AlgorithmType.QuickSort: break; default: throw new WrongAlgExcetion(); } }
private void baseSortButton_Click(object sender, EventArgs e) { var bases = new AlgorithmBase <SortedItem>(items); BtnSortClick(bases); }
/// <summary> /// Constructor of class to hold current selected algorithm engine /// </summary> public SurfaceBuilder() { this.Alg = AlgorithmBase.CreateAlgorithm(AlgorithmBase.Algorithm.BSpline); }
public void InitAlgorithmBase(StepSize size) { StepSize = size; algoBase = new AlgorithmBase(size); CurrentPosition = algoBase.CurrentStep; }
public void Generate(AlgorithmBase algorithm) { algorithm.Apply(this); }
private void SortButton_Click(object sender, EventArgs e) { if (sortedItemsCount > 0) { (sender as Button).Enabled = false; int methods = 1; if (SpeedTrackBar.Value == 0) { SpeedTrackBar.Enabled = false; methods = allMethods.GetLength(0); VisualPanel.Controls.Clear(); } string methodName = ""; for (int methodNumber = 1; methodNumber <= methods; methodNumber++) { Label label = new Label(); AlgorithmBase <SortedItem> algorithm = new AlgorithmBase <SortedItem>(); if (SpeedTrackBar.Value > 0) { foreach (RadioButton radioButton in panel3.Controls.OfType <RadioButton>()) { if (radioButton.Checked) { if (!Int32.TryParse(radioButton.Name.Substring("radioButton".Length), out methodNumber)) { methodNumber = 1; } break; } } } if (panel3.Controls.Find("radioButton" + methodNumber.ToString(), false).Any()) { methodName = panel3.Controls["radioButton" + methodNumber.ToString()].Text; } switch (methodName) { case "Bubble Sort": algorithm = new BubbleSort <SortedItem>(); break; case "Cocktail Sort": algorithm = new CocktailSort <SortedItem>(); break; case "Insertion Sort": algorithm = new InsertionSort <SortedItem>(); break; case "Shell Sort": algorithm = new ShellSort <SortedItem>(); break; case "Tree Sort": algorithm = new Algorithm.DataStructures.Tree <SortedItem>(); break; case "Heap Sort": algorithm = new Algorithm.DataStructures.Heap <SortedItem>(); break; case "Selection Sort": algorithm = new SelectionSort <SortedItem>(); break; case "Gnome Sort": algorithm = new GnomeSort <SortedItem>(); break; case "Radix Sort": algorithm = new RadixSort <SortedItem>(RadixSortCheckBox.Checked); break; case "Merge Sort": algorithm = new MergeSort <SortedItem>(); break; case "Quick Sort": algorithm = new QuickSort <SortedItem>(); break; case "Odd-Even Sort": algorithm = new OddEvenSort <SortedItem>(); break; case "Comb Sort": algorithm = new CombSort <SortedItem>(); break; default: algorithm = new BubbleSort <SortedItem>(); break; } //MessageBox.Show("Вы выбрали метод сортировки " + panel3.Controls["radioButton" + methodNumber.ToString()].Text + " : " + methodNumber.ToString()); if (SpeedTrackBar.Value > 0) { algorithm.CompareEvent += AlgorithmCompareEvent; algorithm.SwapEvent += AlgorithmSwapEvent; algorithm.RemoveEvent += AlgorithmRemoveEvent; } else { int verticalInterval = 15; if (methodNumber > 1 && ((methodNumber - 1) % (VisualPanel.Height / verticalInterval)) == 0) { VisualPanel.Controls.Clear(); } label.Name = "label_" + methodNumber.ToString(); label.Text = "Идет сортировка массива из " + items.Count.ToString() + " элементов по методу " + panel3.Controls["radioButton" + methodNumber.ToString()].Text + " ..."; label.AutoSize = true; label.Location = new Point(5, verticalInterval * ((methodNumber - 1) % (VisualPanel.Height / verticalInterval))); VisualPanel.Controls.Add(label); VisualPanel.Refresh(); } algorithm.AddRange(items); TimeSpan runTime = algorithm.SortAndGetSpan(!reverseSortCheckBox.Checked); if (SpeedTrackBar.Value == 0) { label.Text = "Сортировка " + items.Count.ToString() + " элементов по методу " + panel3.Controls["radioButton" + methodNumber.ToString()].Text + " завершена."; } else if (methodName == "Heap Sort") { VisualPanel.Controls.Clear(); sortedItemsCount = 0; for (int i = 0; i < algorithm.Items.Count; i++) { SortedItem item = new SortedItem(VisualPanel, ++sortedItemsCount, algorithm.Items[i].Value); VisualPanel.Refresh(); } VisualPanel.Refresh(); } ResultTableLayoutPanel.GetControlFromPosition(methodNumber, 3).Text = runTime.Seconds.ToString() + "." + runTime.Milliseconds.ToString(); ResultTableLayoutPanel.GetControlFromPosition(methodNumber, 4).Text = algorithm.ComparisonCount.ToString(); ResultTableLayoutPanel.GetControlFromPosition(methodNumber, 5).Text = algorithm.SwapCount.ToString(); VisualPanel.Refresh(); } SpeedTrackBar.Enabled = true; if (SpeedTrackBar.Value == 0) { for (int i = 1; i <= 3; i++) { ResultTableLayoutPanel.Controls["TestsRadioButton_" + i.ToString()].Enabled = true; } } } }
private void ShowInfoAboutSort(AlgorithmBase <int> algorithm, TimeSpan time) { MessageBox.Show($"Отсортировано за: {time.Milliseconds.ToString()} мс.\n" + $"Количество сравнений: {algorithm.CompareCount}\n" + $"Количество обменов:{algorithm.SwapCount}"); }
private bool SetAlgorithmData() { foreach (RadioButton rb in AlgorithmGroupBox.Controls.OfType <RadioButton>()) { if (rb.Checked) { selectedAlgorithm = rb.AccessibleName; break; } } switch (selectedAlgorithm) { case "Bubble Sort": algorithm = new BubbleSort(); algorithm.SetComplexity(4); break; case "Merge Sort": algorithm = new MergeSort(); algorithm.SetComplexity(2); break; case "Insertion Sort": algorithm = new InsertionSort(); algorithm.SetComplexity(4); break; case "Heap Sort": algorithm = new HeapSort(); algorithm.SetComplexity(0); break; case "Bogo Sort": algorithm = new BogoSort(); algorithm.timeComplexity = "O(n*n!)"; algorithm.spaceComplexity = "O(1)"; MessageBox.Show("Please Note: Within the 'Bogo Sort', the light blue colouring is used for displaying the original set of elements before the new iteration of sort is shown in black.", "Notice"); break; case "Selection Sort": algorithm = new SelectionSort(); algorithm.SetComplexity(4); break; case "Quick Sort": algorithm = new QuickSort(); algorithm.SetComplexity(1); break; case "Cocktail Sort": algorithm = new CocktailSort(); algorithm.SetComplexity(4); break; case "Radix Sort LSD": algorithm = new RadixSort(); algorithm.SetComplexity(3); break; case "Shell Sort": algorithm = new ShellSort(); algorithm.SetComplexity(4); break; case "Comb Sort": algorithm = new CombSort(); algorithm.SetComplexity(4); break; case "Gnome Sort": algorithm = new GnomeSort(); algorithm.SetComplexity(4); break; case "OddEven Sort": algorithm = new OddEvenSort(); algorithm.SetComplexity(4); break; case "Cycle Sort": algorithm = new CycleSort(); algorithm.SetComplexity(4); break; case "Tree Sort": algorithm = new TreeSort(); algorithm.SetComplexity(2); break; case "Pancake Sort": algorithm = new PancakeSort(); algorithm.SetComplexity(4); break; case null: MessageBox.Show("Please select an algorithm", "Error"); return(false); } return(true); }
public static IEnumerable <Type> GetKnownTypes() { return(AlgorithmBase.GetKnownTypes()); }