Ejemplo n.º 1
0
        public static void Main()
        {
            Console.WriteLine("Starting...");

            var services             = new OpenApiCommandLineServices(FilePath);
            ISolutionFactory factory = services.GetService <ISolutionFactory>();

            factory.CreateSolution(PostAction.OpenInExplorer);

            Console.WriteLine("Complete!");
        }
Ejemplo n.º 2
0
        private Solution Crossover(Solution Parent1, Solution Parent2)
        {
            string[] childSolution  = new string[Parent1.path.Length];
            Random   rand           = new Random();
            int      crossoverPoint = rand.Next(0, Parent1.path.Length);

            //up to the crossover point
            for (int i = 0; i < crossoverPoint; i++)
            {
                childSolution[i] = Parent1.path[i];
            }
            //from crossover point to the end of the other parent.
            for (int j = crossoverPoint; j < Parent1.path.Length; j++)
            {
                childSolution[j] = Parent2.path[j];
            }

            Solution child = solutionFactory.CreateSolution(childSolution);

            mutater.Mutate(child);
            return(child);
        }
Ejemplo n.º 3
0
        public void CreateInitialGeneration()
        {
            CreateCities();
            breeder.SetSolutionUtils(breedingFactory.CreateSolutionUtils(cities));

            Solution[]    initialGeneration = new Solution[population];
            StringBuilder sb   = new StringBuilder();
            Random        rand = new Random();

            string[] path = new string[population + 1];


            //Create object
            for (int i = 0; i < population; i++)
            {
                path = new string[cityCount + 1];
                // create path string
                for (int location = 0; location <= cityCount; location++)
                {
                    int cityVisited = rand.Next(0, cityCount);
                    if (cityVisited < 10)
                    {
                        sb.Append($"0{cityVisited.ToString()}");
                        path[location] = sb.ToString();
                        sb.Clear();
                    }
                    else
                    {
                        sb.Append(cityVisited.ToString());
                        path[location] = sb.ToString();
                        sb.Clear();
                    }
                }
                Solution solutionObj = solutionFactory.CreateSolution(path);
                initialGeneration[i] = solutionObj;
            }

            this.generation = initialGeneration;
        }