/// <summary> /// GCD calculation method. /// </summary> /// <param name="first">The first number.</param> /// <param name="second">The second number.</param> /// <returns> /// Returns the GCD of two numbers. /// </returns> public int Calculate(int first, int second) { Stopwatch watch = Stopwatch.StartNew(); int result = algorithm.Calculate(first, second); watch.Stop(); Milliseconds = watch.ElapsedMilliseconds; return(result); }
/// <summary>The extension method to get the gcd of the array of numbers.</summary> /// <param name="algorithm">The algorithm to extend.</param> /// <param name="numbers">The array of numbers.</param> /// <returns>The gcd of the array of numbers.</returns> /// <exception cref="ArgumentNullException">Thrown when algorithm is null.</exception> public static int Calculate(this IAlgorithm algorithm, params int[] numbers) { CheckValues(algorithm, numbers); int bufGcd = algorithm.Calculate(numbers[0], numbers[1]); for (int i = 2; i < numbers.Length; i++) { bufGcd = algorithm.Calculate(bufGcd, numbers[i]); } return(bufGcd); }
/// <summary>Calculates GCD of three numbers.</summary> /// <param name="algorithm">Algorithm.</param> /// <param name="first">First number.</param> /// <param name="second">Second number.</param> /// <param name="third">Third number.</param> /// <returns>Returns GCD of three numbers.</returns> public static int GcdManyNumbers(this IAlgorithm algorithm, int first, int second, int third) { if (algorithm == null) { throw new ArgumentNullException(nameof(algorithm)); } Validation(first, second, third); int temporaryResult = algorithm.Calculate(first, second); return(algorithm.Calculate(temporaryResult, third)); }
/// <summary> /// method for finding GCD of three numbers. /// </summary> /// <param name="algorithm">algorithm.</param> /// <param name="first">First number.</param> /// <param name="second">Second number.</param> /// <param name="third">Third number.</param> /// <returns>Gcd of numbers.</returns> public static int Calculate(this IAlgorithm algorithm, int first, int second, int third) { CheckValues(first, second, third); int temp; if (first == 0 && second == 0) { temp = 0; } else { temp = algorithm.Calculate(first, second); } return(algorithm.Calculate(temp, third)); }
private void DoRobotWork(ChessPlayer player) { if (game.CurrentPlayer != player) { Thread.Sleep(1000); return; } ChangeAlgorithm(); var playerName = player == ChessPlayer.White ? "[WHITE]" : "[BLACK]"; var stopWatch = new Stopwatch(); UpdateLog($"{playerName}Running algorithm..."); StartStopAlgorithmProgressbar(player, true); stopWatch.Reset(); stopWatch.Start(); var move = player == ChessPlayer.White ? _algorithmLeft.Calculate(game) : _algorithmRight.Calculate(game); stopWatch.Stop(); StartStopAlgorithmProgressbar(player, false); UpdateLog($"{playerName}Algorithm finished in {stopWatch.Elapsed.TotalSeconds:F} seconds and generated move: {move}", 2); game = _mechanism.ApplyMove(game, move); InvokeIfRequired(chessBoardVisualizerPanel1, () => { chessBoardVisualizerPanel1.ChessRepresentation = game; chessBoardVisualizerPanel1.Refresh(); }); InvokeIfRequired(labelGameStatus, () => { labelGameStatus.Text = _mechanism.GetGameState(game).ToString(); }); }
/// <summary> /// Прогон заданий на этом алгориме /// </summary> protected void Calc() { int I = 0; int n = tasks.Count; DateTime dd = DateTime.MinValue; TimeSpan ime = TimeSpan.MinValue; IOutBlackBoxParam data = null; int time = 0; foreach (ITaskPackage task in tasks) { time = 0; alg.EnterParam = task.EnterParams; int BlackBoxesCount = task.BlackBoxes.Count; for (int i = 0; i < BlackBoxesCount; i++) { dd = DateTime.Now; function.Init(task.BlackBoxes[i]); data = alg.Calculate(); ime = DateTime.Now - dd; if (listener != null) { time += ime.Milliseconds; listener.OnEndCalculate(alg, task, data, ime.Milliseconds); } I++; } listener.OnEndTask(alg, task, data, time); } }
/// <summary> /// Прогон заданий на этом алгориме /// </summary> protected void Calc() { int n = tasks.Count; DateTime dd = DateTime.MinValue; TimeSpan ime = TimeSpan.MinValue; IOutBlackBoxParam data = null; foreach (ITaskPackage task in tasks) { alg.EnterParam = task.EnterParams; int BlackBoxesCount = task.BlackBoxes.Count; dd = DateTime.Now; function.Init(task); alg.Refresh(); data = alg.Calculate(); ime = DateTime.Now - dd; if (listener != null) { listener.OnEndTask(alg, task, data, ime.Hours * 60 * 60 * 1000 + ime.Minutes * 60 * 1000 + ime.Seconds * 1000 + ime.Milliseconds); } /* { * time += ime.Milliseconds; * listener.OnEndCalculate(alg, task, data, ime.Milliseconds); * }*/ } }
public double CalculateAverage(IList <double> values) { if (values == null) { throw new ArgumentNullException(nameof(values)); } return(_algorithm.Calculate(values)); }
/// <summary>The extension method to get the gcd of the array of numbers and the required time.</summary> /// <param name="algorithm">The algorithm to extend.</param> /// <param name="milliseconds">The required time in milliseconds.</param> /// <param name="numbers">The array of numbers.</param> /// <returns>The gcd of the array of numbers.</returns> /// <exception cref="ArgumentNullException">Thrown when algorithm is null.</exception> public static int Calculate(this IAlgorithm algorithm, out long milliseconds, params int[] numbers) { CheckValues(algorithm, numbers); var startTime = System.Diagnostics.Stopwatch.StartNew(); int result = algorithm.Calculate(numbers); startTime.Stop(); milliseconds = startTime.ElapsedMilliseconds; return(result); }
/// <summary>The extension method to get the gcd of three numbers and the required time.</summary> /// <param name="algorithm">The algorithm to extend.</param> /// <param name="first">The first value.</param> /// <param name="second">The second value.</param> /// <param name="third">The third value.</param> /// <param name="milliseconds">The required time in milliseconds.</param> /// <returns>The gcd of three values.</returns> /// <exception cref="ArgumentNullException">Thrown when algorithm is null.</exception> public static int Calculate(this IAlgorithm algorithm, int first, int second, int third, out long milliseconds) { CheckValues(algorithm, first, second, third); var startTime = System.Diagnostics.Stopwatch.StartNew(); int result = algorithm.Calculate(first, second, third); startTime.Stop(); milliseconds = startTime.ElapsedMilliseconds; return(result); }
/// <summary> /// method for finding GCD of three numbers and time of working. /// </summary> /// <param name="algorithm">algorithm.</param> /// <param name="milliseconds">time of working.</param> /// <param name="first">First number.</param> /// <param name="second">Second number.</param> /// <param name="third">Third number.</param> /// <returns>Gcd of numbers.</returns> public static int Calculate(this IAlgorithm algorithm, out long milliseconds, int first, int second, int third) { CheckValues(first, second, third); int temp; long localMilliseconds; milliseconds = 0; if (first == 0 && second == 0) { temp = 0; } else { temp = algorithm.Calculate(first, second, out localMilliseconds); milliseconds += localMilliseconds; } return(algorithm.Calculate(temp, third)); }
/// <summary> /// Calculates the GCD. /// </summary> /// <param name="algorithm">The algorithm.</param> /// <param name="milliseconds">The milliseconds.</param> /// <param name="first">The first number.</param> /// <param name="second">The second number.</param> /// <param name="third">The third number.</param> /// <returns>Returns GCD of three numbers.</returns> public static int Calculate(this IAlgorithm algorithm, out long milliseconds, int first, int second, int third) { Stopwatch watch = Stopwatch.StartNew(); int result = algorithm.Calculate(first, second, third); watch.Stop(); milliseconds = watch.ElapsedMilliseconds; return(result); }
/// <summary> /// Calculates the GCD. /// </summary> /// <param name="algorithm">The algorithm.</param> /// <param name="milliseconds">The milliseconds.</param> /// <param name="numbers">The numbers.</param> /// <returns>Returns GCD of several numbers.</returns> public static int Calculate(this IAlgorithm algorithm, out long milliseconds, params int[] numbers) { Stopwatch watch = Stopwatch.StartNew(); int result = algorithm.Calculate(numbers); watch.Stop(); milliseconds = watch.ElapsedMilliseconds; return(result); }
public int Calculate(int first, int second) { stopWatch.Start(); int gcd = algorithm.Calculate(first, second); stopWatch.Stop(); TimeInMilliseconds = stopWatch.TimeInMilliseconds; return(gcd); }
/// <summary> /// Calculates the GCD. /// </summary> /// <param name="algorithm">The algorithm.</param> /// <param name="numbers">The numbers.</param> /// <returns>Returns GCD of several numbers.</returns> public static int Calculate(this IAlgorithm algorithm, params int[] numbers) { int gcd = 0; for (int i = 0; i < numbers.Length; i++) { gcd = algorithm.Calculate(numbers[i], gcd); } return(gcd); }
public async Task <Statistic> GetStatistic(IEnumerable <double> values) { algorithm = _serviceProvider.GetRequiredService <Median>(); var median = await algorithm.Calculate(values); algorithm = _serviceProvider.GetRequiredService <ArethmeticMean>(); var am = await algorithm.Calculate(values); var result = new Statistic { Median = median, ArethmeticMean = am, }; return(result); }
/// <summary> /// returns /// </summary> /// <param name="car"></param> /// <param name="intersection"></param> /// <returns></returns> public static Destination GetDirection(Car car, Intersection intersection) { var road = car.CurrentRoad; var location = MathUtil.Distance(road.Start, car.Location) < MathUtil.Distance(road.End, car.Location) ? road.Start : road.End; return(Algorithm.Calculate(car.Id, new Destination { Location = location, Road = car.CurrentRoad }, car.Destination)); }
/// <summary>Calculates GCD of two numbers.</summary> /// <param name="algorithm">Algorithm.</param> /// <param name="first">First number.</param> /// <param name="second">Second number.</param> /// <param name="ticks">Method's execution time.</param> /// <returns>Returns GCD of two numbers.</returns> public static int GcdManyNumbers(this IAlgorithm algorithm, int first, int second, out long ticks) { if (algorithm == null) { throw new ArgumentNullException(nameof(algorithm)); } Validation(first, second); var timer = new Stopwatch(); timer.Start(); int result = algorithm.Calculate(first, second); timer.Stop(); ticks = timer.ElapsedTicks; return(result); }
/// <summary> /// method for finding GCD of array of numbers. /// </summary> /// <param name="algorithm">algorithm.</param> /// <param name="numbers">Array of numbers.</param> /// <returns>Gcd.</returns> public static int Calculate(this IAlgorithm algorithm, params int[] numbers) { CheckValues(numbers); int gcd = 0; for (int i = 0; i < numbers.Length; i++) { if (numbers[i] == 0) { continue; } gcd = algorithm.Calculate(gcd, numbers[i]); } return(gcd); }
/// <summary> /// method for finding GCD of array of numbers and time of working. /// </summary> /// <param name="algorithm">algorithm.</param> /// <param name="milliseconds">time of working.</param> /// <param name="numbers">array of numbers.</param> /// <returns>Gcd.</returns> public static int Calculate(this IAlgorithm algorithm, out long milliseconds, params int[] numbers) { CheckValues(numbers); long localMilliseconds; milliseconds = 0; int gcd = 0; for (int i = 0; i < numbers.Length; i++) { if (numbers[i] == 0) { continue; } gcd = algorithm.Calculate(gcd, numbers[i], out localMilliseconds); milliseconds += localMilliseconds; } return(gcd); }
static void Main(string[] args) { IServiceProvider serviceProvider = CreateServiceProvider(); IAlgorithm algorithm = serviceProvider.GetService <IAlgorithm>(); int a = -12, b = 120, c = 40, d = -40; Console.WriteLine($"GCD({a}, {b}) = {algorithm.Calculate(a, b).ToString()}."); AlgorithmDecorator gcdAlgorithm = serviceProvider.GetService <AlgorithmDecorator>(); int gcd = gcdAlgorithm.Calculate(a, b); Console.WriteLine($"GCD({a}, {b}) = {gcd}. Algorithms time: {((GCD)gcdAlgorithm).Milliseconds.ToString()} ms."); gcd = gcdAlgorithm.Calculate(a, b, c); Console.WriteLine($"GCD({a}, {b}, {c}) = {gcd}. Algorithms time: {((GCD)gcdAlgorithm).Milliseconds.ToString()} ms."); gcd = gcdAlgorithm.Calculate(a, b, c, d); Console.WriteLine($"GCD({a}, {b}, {c}, {d}) = {gcd}. Algorithms time: {((GCD)gcdAlgorithm).Milliseconds.ToString()} ms."); Console.ReadKey(); }
/// <summary> /// method for finding GCD of three numbers and time of working. /// </summary> /// <param name="algorithm">algorithm.</param> /// <param name="first">First number.</param> /// <param name="second">Second number.</param> /// <param name="milliseconds">time of working.</param> /// <returns>Gcd of numbers.</returns> public static int Calculate(this IAlgorithm algorithm, int first, int second, out long milliseconds) { if ((first == 0) && (second == 0)) { throw new ArgumentException("Two numbers cannot be 0 at the same time."); } if (first == int.MinValue || second == int.MinValue) { throw new ArgumentException("Numbers cannot to be int.MinValue."); } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); int result = algorithm.Calculate(first, second); stopwatch.Stop(); milliseconds = stopwatch.ElapsedTicks; return(result); }
internal double[] CalculateHarmonics(int noOfHarmonics, out string harmonicsTable, out int fundamentalFrequency) { return(idftAlgorithm.Calculate(currentSample, noOfHarmonics, sampleRate, out harmonicsTable, out fundamentalFrequency)); }
public int calculate(int no1, int no2) { return(_Strategy.Calculate(no1, no2)); }
/// <summary> The extension method to get the gcd of two numbers.</summary> /// <param name="algorithm">The algorithm to extend.</param> /// <param name="first">The first number.</param> /// <param name="second">The second number.</param> /// <returns>The gcd of two values.</returns> public static int Calculate(this IAlgorithm algorithm, int first, int second) { CheckValues(algorithm, first, second); return(algorithm.Calculate(first, second)); }
public int Calculate(int first, int second) { return(algorithm.Calculate(first, second)); }
/// <summary> /// Calculates the GCD. /// </summary> /// <param name="algorithm">The algorithm.</param> /// <param name="first">The first number.</param> /// <param name="second">The second number.</param> /// <param name="third">The third number.</param> /// <returns>Returns GCD of three numbers.</returns> public static int Calculate(this IAlgorithm algorithm, int first, int second, int third) { return(algorithm.Calculate(algorithm.Calculate(first, second), third)); }
public List <T> Calculate <T>(T start, T goal, bool checkObj, bool goalCheckObj) where T : ITileMapNode { return(algorithm.Calculate(start, goal, checkObj, goalCheckObj)); }
/// <summary> /// Finds the GCD by euclidean. /// </summary> /// <param name="first">The first number.</param> /// <param name="second">The second number.</param> /// <returns>Returns GCD of two numbers.</returns> public static int FindGcdByEuclidean(int first, int second) => algorithm.Calculate(first, second);