private IPath <T> Evolve(IPath <T> path)
        {
            int[] locations = path.GetLocations();
            int[] result    = new int[locations.Length];
            locations.CopyTo(result, locations.Length);
            int from = random.Next(locations.Length - 1);

            Exchange(result, from, from + 1);
            return(problem.CreatePath(result));
        }
Exemplo n.º 2
0
        protected internal void CalculateShortestPath(IProblem <T> problem)
        {
            IList <int> leftToVisit = new List <int>();

            for (int i = 0; i < problem.GetLocationsCount(); i++)
            {
                leftToVisit.Add(i);
            }
            CalculateShortestPath(problem, problem.CreatePath(), leftToVisit);
        }
Exemplo n.º 3
0
        protected internal virtual IPath <T> CalculateShortestPath(IProblem <T> problem)
        {
            IList <int?> leftToVisit = new List <int?>();

            for (int i = 0; i < problem.GetLocationsCount(); i++)
            {
                leftToVisit.Add(i);
            }
            return(CalculateShortestPath(problem, problem.CreatePath(), leftToVisit));
        }
Exemplo n.º 4
0
        public virtual IPath <T> Solve()
        {
            int[] locations = new int[problem.GetLocationsCount()];
            for (int i = 0; i < locations.Length; i++)
            {
                locations[i] = i;
            }
            IPath <T> result = problem.CreatePath(locations);

            problem.SetBestPath(result);
            return(result);
        }
        public virtual IPath <T> Solve()
        {
            IPath <T> start = problem.CreatePath();

            for (int j = 0; j < problem.GetLocationsCount(); j++)
            {
                List <IPath <T> > neighbors = new List <IPath <T> >();
                for (int i = 0; i < problem.GetLocationsCount(); i++)
                {
                    if (!start.Contains(i))
                    {
                        neighbors.Add(start.To(i));
                    }
                }
                problem.CalculateLengths(neighbors);
                neighbors.Sort();
                start = neighbors[0];
            }
            return(start);
        }