public override ISolverResult Solve(IAlgorithm tspSolvingAlgorithm)
        {
            var context = SolvingTimeContext.Instance;

            Statistics = new BasicSolverStatistics();
            var resultAccumulator = new SolverResult();

            var bestPath = new Path(new List <int>(), new ConstCostCalculationStrategy(int.MaxValue));

            for (var i = 0; i < MslsRepeatAmount; i++)
            {
                using (context)
                {
                    for (var j = 0; j < InsideAlgorithmRepeatAmount; j++)
                    {
                        var startNode = _randomGenerator.Next(0, CompleteGraph.NodesCount - 1);

                        var pathAccumulator = _internalSolver.Solve(_internalAlgorithm, startNode);

                        var localPath = pathAccumulator.Paths[0];

                        localPath = tspSolvingAlgorithm.Solve(localPath.Nodes.First(), CompleteGraph, localPath);

                        if (localPath.Cost < bestPath.Cost)
                        {
                            bestPath = localPath;
                        }
                    }
                    Statistics.UpdateSolvingResults(bestPath, context.Elapsed);
                    resultAccumulator.AddPath(bestPath);
                }
            }
            return(resultAccumulator);
        }
        public override ISolverResult Solve(IAlgorithm tspSolvingAlgorithm, ISolverResult solverResult)
        {
            Statistics = new BasicSolverStatistics();

            ISet <Path> initialPopulation = new HashSet <Path>(solverResult.Paths);

            var optimalChilderens = new SolverResult();

            _solverStopwatch.Start();
            var localStopwatch = new Stopwatch();

            while (_solverStopwatch.ElapsedMilliseconds < _solvingTime)
            {
                var parents = _selector.Select(initialPopulation);
                var child   = _recombinator.Recombine(parents.Item1, parents.Item2);

                localStopwatch.Start();
                var optimalChild = tspSolvingAlgorithm.Solve(StartNode(child), CompleteGraph, child);
                localStopwatch.Stop();

                optimalChilderens.AddPath(optimalChild);
                initialPopulation = EnhancePopulation(optimalChild, initialPopulation);

                Statistics.UpdateSolvingResults(optimalChild, localStopwatch.Elapsed);
                localStopwatch.Reset();
            }

            _solverStopwatch.Reset();
            return(optimalChilderens);
        }
        public override ISolverResult Solve(IAlgorithm tspSolvingAlgorithm)
        {
            var bestPath     = InitialBestPath;
            var solverResult = new SolverResult();

            for (var j = 0; j < _generatedPaths; j++)
            {
                var localSolverResult = _initializationSolver.Solve(StartNode);

                var localPath = localSolverResult.Paths[0];

                localPath = tspSolvingAlgorithm.Solve(localPath.Nodes.First(), CompleteGraph, localPath);

                solverResult.AddPath(localPath);

                if (localPath.Cost < bestPath.Cost)
                {
                    bestPath = localPath;
                }
            }

            CalculateSimilarities(solverResult, new ForEachSimilarityCalculator());
            CalculateSimilarities(solverResult, new WithBestSimilarityCalculator(bestPath));

            return(solverResult);
        }
        public override ISolverResult Solve(IAlgorithm tspSolvingAlgorithm)
        {
            var context = SolvingTimeContext.Instance;

            Statistics = new BasicSolverStatistics();
            var resultPathAccumulator = new SolverResult();

            for (var i = 0; i < IlsRepeatAmount; i++)
            {
                Path bestPath;
                using (context)
                {
                    var pathAccumulator = _initializationSolver.Solve(_initializationAlgorithm, StartNode);

                    bestPath = pathAccumulator.Paths[0];

                    var timer = new Stopwatch();
                    timer.Start();

                    var newPath = bestPath;

                    while (timer.ElapsedMilliseconds < AlgorithmSolveTimeMs)
                    {
                        for (var j = 0; j < PerturbanceLength; j++)
                        {
                            var move = GetRandomMove(newPath, CompleteGraph);
                            newPath = move.Move(bestPath);
                        }

                        var solvedPath = tspSolvingAlgorithm.Solve(bestPath.Nodes.First(), CompleteGraph, bestPath);

                        if (solvedPath.Cost >= bestPath.Cost)
                        {
                            continue;
                        }

                        bestPath = newPath;
                    }
                }

                resultPathAccumulator.AddPath(bestPath);
                Statistics.UpdateSolvingResults(bestPath, context.Elapsed);
                Console.WriteLine(i + " / 10");
            }
            return(resultPathAccumulator);
        }
        public override ISolverResult Solve(IAlgorithm tspSolvingAlgorithm, ISolverResult solverResult)
        {
            Statistics = new BasicSolverStatistics();

            var newAccumulator = new SolverResult();

            foreach (var path in solverResult.Paths)
            {
                var context = SolvingTimeContext.Instance;

                Path localyBestPath;

                using (context)
                {
                    localyBestPath = tspSolvingAlgorithm.Solve(SelectStartNode(path), CompleteGraph, path);
                }

                newAccumulator.AddPath(localyBestPath);
                Statistics.UpdateSolvingResults(localyBestPath, context.Elapsed);
            }

            return(newAccumulator);
        }