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);
        }
 private void CalculateSimilarities(ISolverResult solverResult, ISimilarityCalculator similarityCalculator)
 {
     foreach (var strategy in _calculatedSimilarities)
     {
         SimilairityValues[$"{strategy.GetType().Name}|{similarityCalculator.GetType().Name}"] =
             similarityCalculator.CalculatePathsSimilarities(strategy, solverResult)
             .Zip(solverResult.Paths, (similarity, path) => new SimilaritySolverResult(similarity, path.Cost))
             .ToList();
     }
 }
예제 #3
0
        private ISolverResult Solve(IAlgorithm tspSolvingAlgorithm, int startNode, ISolverResult solverResult)
        {
            Path bestPath;

            var context = SolvingTimeContext.Instance;

            using (context)
            {
                bestPath = tspSolvingAlgorithm.Solve(startNode, CompleteGraph);
            }

            Statistics.UpdateSolvingResults(bestPath, context.Elapsed);
            solverResult.AddPath(bestPath);

            return(solverResult);
        }
        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);
        }
예제 #5
0
 public virtual ISolverResult Solve(IAlgorithm tspSolvingAlgorithm, ISolverResult solverResult)
 {
     throw new NotImplementedException();
 }
예제 #6
0
        public IEnumerable <double> CalculatePathsSimilarities(ISimilarityCalculationStrategy calculationStrategy, ISolverResult solverResult)
        {
            var count  = solverResult.Paths.Count;
            var result = new List <double>(Enumerable.Range(0, count).Select(value => value * 0d));

            for (var i = 0; i < count; i++)
            {
                for (var j = 0; j < count; j++)
                {
                    result[i] += (i != j) ? calculationStrategy.CalculateSimilarity(solverResult.Paths[i], solverResult.Paths[j]) : 0;
                }

                result[i] /= (count - 1);
            }
            return(result);
        }
 public IEnumerable <double> CalculatePathsSimilarities(ISimilarityCalculationStrategy calculationStrategy, ISolverResult solverResult)
 {
     return(solverResult.Paths
            .Select(path => calculationStrategy.CalculateSimilarity(_bestPath, path))
            .ToList());
 }