Ejemplo n.º 1
0
        public static long timeOfExecution(int[] tab, AlgorithmDelegate alg)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            alg(tab);
            var elapsedMs = watch.ElapsedMilliseconds;

            return(elapsedMs);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The Euclidean or SteinAlgorithm algorithm calculates the greatest common divisor of any natural numbers.
        /// </summary>
        /// <param name="algorithmDelegate">Delegate algorithm</param>
        /// <param name="numbInts">Array of natural numbers</param>
        /// <returns>Greatest common divisor of any natural numbers</returns>

        private static int CommonAlgorithm(AlgorithmDelegate algorithmDelegate, params int[] numbInts)
        {
            int boof = algorithmDelegate(numbInts[0], numbInts[1]);

            for (int i = 2; i <= numbInts.Length - 1; i++)
            {
                boof = algorithmDelegate(boof, numbInts[i]);
            }
            return(boof);
        }
Ejemplo n.º 3
0
 // Sets the maze generation algorithm for use during calculatemaze
 public void SetAlgorithm(MazeAlgorithmMode mazeAlgo)
 {
     _mazeAlgorithmMode = mazeAlgo;
     switch (mazeAlgo)
     {
     case MazeAlgorithmMode.GrowingTree:
         _mazeAlgorithm = new AlgorithmDelegate(MazeAlgorithm.GrowingTree);
         break;
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Time execution function
        /// </summary>
        /// <param name="algorithmDelegate">Delegate algorithm</param>
        /// <param name="a">First number</param>
        /// <param name="b">Second number</param>
        /// <returns>Time execution</returns>
        public static string ExecutionTimeOfAlgorithm(AlgorithmDelegate algorithmDelegate, int a, int b)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            algorithmDelegate(a, b);
            stopWatch.Stop();
            TimeSpan ts = stopWatch.Elapsed;

            return($"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds / 10:00}");
        }
Ejemplo n.º 5
0
 public SIMONIntelligence(AlgorithmForAI algorithm, SIMONAlgorithm algorithmCls, AsyncCallback learnCallback)
 {
     IntelligenceAlgorithm = algorithm;
     AlgorithmPerformer = algorithmCls;
     AlgorithmInvoker = new AlgorithmDelegate(AlgorithmPerformer.Implementation);
     AlgorithmLearnInvoker = new AlgorithmLearningDelegate(AlgorithmPerformer.Implementation);
     AlgorithmLearnPropInvoker = new AlgorithmLearnPropDelegate(AlgorithmPerformer.Implementation);
     LearnCallbackInvoker = new AsyncCallback(learnCallback);
     LearnPropCallbackInvoker = new AsyncCallback(LearnPropertyAsyncCallback);
     LearnResult = null;
 }
Ejemplo n.º 6
0
        public SIMONIntelligence()
        {
            IntelligenceAlgorithm = AlgorithmForAI.GENETIC;
            AlgorithmPerformer = new SIMONGeneticAlgorithm();

            AlgorithmInvoker = new AlgorithmDelegate(AlgorithmPerformer.Implementation);
            AlgorithmLearnInvoker = new AlgorithmLearningDelegate(AlgorithmPerformer.Implementation);
            AlgorithmLearnPropInvoker = new AlgorithmLearnPropDelegate(AlgorithmPerformer.Implementation);
            LearnCallbackInvoker = new AsyncCallback(LearnAsyncCallback);
            LearnPropCallbackInvoker = new AsyncCallback(LearnPropertyAsyncCallback);
            LearnResult = null;
        }
Ejemplo n.º 7
0
        public static KnapsackSolutions BigTest(List <KnapsackAlgorithmInput> tests, AlgorithmDelegate Algorithm)
        {
            var startTime = System.Diagnostics.Stopwatch.StartNew();

            TimeSpan[] timeArray = new TimeSpan[tests.Count];
            List <KnapsackSolution> solutionPack = new List <KnapsackSolution>();

            foreach (KnapsackAlgorithmInput test in tests)
            {
                solutionPack.Add(Algorithm(test));
            }
            startTime.Stop();
            return(new KnapsackSolutions(solutionPack, startTime.Elapsed));
        }//*/
Ejemplo n.º 8
0
        /// <summary>
        /// Prints out a summary of the algorithm to the console, including execution times.
        /// </summary>
        /// <param name="algorithmDescription">Summary of the algorithm used</param>
        /// <param name="algorithm">Algorithm method (delegate)</param>
        /// <param name="suppressListDisplay"><code>true</code> to dispaly the contents of the shuffled list</param>
        private static void PrintExecutionSummary(string algorithmDescription, AlgorithmDelegate algorithm, bool suppressListDisplay)
        {
            int[] algorithmResults;

            Console.WriteLine("===============================================");
            Console.WriteLine(String.Format("Results for the {0} algorithm:", algorithmDescription));

            // determine length of time required to process algorithm
            DateTime timerStart = DateTime.Now;
            algorithmResults = algorithm(ElementCount);
            TimeSpan timerElapsed = DateTime.Now - timerStart;

            if (suppressListDisplay)
                Utils.PrintArray(algorithmResults);

            Console.WriteLine("---------------------------------------------------------");
            Console.WriteLine("Time required to process the {0} algorithm: {1} ms\r\n", algorithmDescription, timerElapsed.Milliseconds);

            Console.WriteLine("Press any key for the next test");
            Console.ReadKey();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Prints out a summary of the algorithm to the console, including execution times.
        /// </summary>
        /// <param name="algorithmDescription">Summary of the algorithm used</param>
        /// <param name="algorithm">Algorithm method (delegate)</param>
        /// <param name="suppressListDisplay"><code>true</code> to dispaly the contents of the shuffled list</param>
        private static void PrintExecutionSummary(string algorithmDescription, AlgorithmDelegate algorithm, bool suppressListDisplay)
        {
            int[] algorithmResults;

            Console.WriteLine("===============================================");
            Console.WriteLine(String.Format("Results for the {0} algorithm:", algorithmDescription));

            // determine length of time required to process algorithm
            DateTime timerStart = DateTime.Now;

            algorithmResults = algorithm(ElementCount);
            TimeSpan timerElapsed = DateTime.Now - timerStart;

            if (suppressListDisplay)
            {
                Utils.PrintArray(algorithmResults);
            }

            Console.WriteLine("---------------------------------------------------------");
            Console.WriteLine("Time required to process the {0} algorithm: {1} ms\r\n", algorithmDescription, timerElapsed.Milliseconds);

            Console.WriteLine("Press any key for the next test");
            Console.ReadKey();
        }
Ejemplo n.º 10
0
 private void RunOnFew(AlgorithmDelegate del)
 {
     del(new InsertionSort());
     del(new QuickSort());
 }
Ejemplo n.º 11
0
 private void RunOnAll(AlgorithmDelegate del)
 {
     del(new SelectionSort());
     del(new InsertionSort());
     del(new QuickSort());
     del(new ThreeWayQuickSort());
     del(new OptimizedQuickSort(30));
 }