示例#1
0
        private ISolver EvolutionaryMakerParametrized(int population, int parentCandidates, double mutationRate, double crossoverRate, double mutationProbability, double crossoverProbability, string desc)
        {
            Evolutionary solver = new Evolutionary()
            {
                ParallelAllowed = true,
                ParallelOptions = new ParallelOptions()
                {
                    MaxDegreeOfParallelism = 15
                },
                ScoringFunction               = new Scorer(),
                DiagnosticMessages            = true,
                PropagateRandomSeed           = true,
                TimeLimit                     = new TimeSpan(0, 15, 0),
                PopulationCount               = population,
                CandidatesForParent           = parentCandidates,
                MutationRate                  = mutationRate,
                CrossoverRate                 = crossoverRate,
                NumberOfMutationsToBreakCount = mutationProbability,
                ProportionOfBreaksCrossed     = crossoverProbability,
                GenerationImproverGenerator   = LocalSearchForEvolutionaryImprovement,
                Description                   = desc,
            };

            return(solver);
        }
示例#2
0
        private ISolver EvolutionaryBest()
        {
            Evolutionary solver = new Evolutionary()
            {
                ParallelAllowed = true,
                ParallelOptions = new ParallelOptions()
                {
                    MaxDegreeOfParallelism = 15
                },
                ScoringFunction     = new Scorer(),
                DiagnosticMessages  = true,
                PropagateRandomSeed = true,
                BreakAfterLoopsWithoutImprovement = 2,
                TimeLimit                     = new TimeSpan(1, 30, 0),
                PopulationCount               = 38,
                CandidatesForParent           = 4,
                MutationRate                  = 0.394736842105263,
                CrossoverRate                 = 0.657894736842105,
                NumberOfMutationsToBreakCount = 0.000790520968624,
                ProportionOfBreaksCrossed     = 0.083086983070447,
                GenerationImproverGenerator   = LocalSearchForEvolutionaryImprovement,
                Description                   = "evolutionary_best_2",
            };

            return(solver);
        }
示例#3
0
        private static ISolver EvolutionarySolver()
        {
            Evolutionary solver = new Evolutionary()
            {
                Description         = "evolutionary2",
                ScoringFunction     = new Scorer(),
                DiagnosticMessages  = true,
                PropagateRandomSeed = true,
                ParallelAllowed     = true,
                Seed = 10,
                GenerationImproverGenerator = LocalSearchForEvolutionaryImprovement,
                GenerationCreatorGenerator  = LocalSearchEvolutionaryInitial,
            };

            return(solver);
        }
示例#4
0
        private static void runEvolutionary(string fileName, Method method)
        {
            FileReader   fileReader = new FileReader(new NetworkModel());
            NetworkModel network    = fileReader.ReadFile(fileName);

            int   maxMutationNumber, maxNumberOfContinuousNonBetterSolutions, maxTime, population, maxNumberOfGenerations, seed;
            float pCross, pMutate, percentOfBestChromosomes;

            Console.WriteLine("Podaj maksymaln¹ liczbê mutacji");
            Int32.TryParse(Console.ReadLine(), out maxMutationNumber);

            Console.WriteLine("Podaj maksymaln¹ liczbê prób szukania lepszego rozwi¹zania:");
            Int32.TryParse(Console.ReadLine(), out maxNumberOfContinuousNonBetterSolutions);

            Console.WriteLine("Podaj maksymalny czas[s]");
            Int32.TryParse(Console.ReadLine(), out maxTime);

            Console.WriteLine("Podaj populacjê:");
            Int32.TryParse(Console.ReadLine(), out population);

            Console.WriteLine("Podaj liczbê generacji:");
            Int32.TryParse(Console.ReadLine(), out maxNumberOfGenerations);

            Console.WriteLine("Podaj pstwo krzy¿owañ:[np.0,6]");
            float.TryParse(Console.ReadLine(), out pCross);

            Console.WriteLine("Podaj pstwo mutacji:[np.0,6]");
            float.TryParse(Console.ReadLine(), out pMutate);

            Console.WriteLine("Podaj ziarno:[np.100]");
            Int32.TryParse(Console.ReadLine(), out seed);

            Console.WriteLine("Podaj procent najlepszych chromosomow[np. 70]:");
            float.TryParse(Console.ReadLine(), out percentOfBestChromosomes);

            var evolutionary = new Evolutionary(pCross, pMutate, maxTime, population, percentOfBestChromosomes, maxNumberOfGenerations,
                                                maxMutationNumber, maxNumberOfContinuousNonBetterSolutions, seed, network);

            if (method == Method.DAP)
            {
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();

                var result = evolutionary.RunDAP();

                stopWatch.Stop();
                Console.WriteLine($"Liczba iteracji: {evolutionary.CurrentGeneration}");
                Console.WriteLine($"Czas uzyskania rozwi¹zania: {stopWatch.Elapsed}");
                Console.WriteLine($"Przeci¹¿enie DAP: {result.CapacityExceededLinksNumber}");
                Console.WriteLine("Najlepsze rozwi¹zanie: ");
                var demandId = result.XesDictionary.ElementAt(0).Key.DemandId;
                Console.WriteLine("");
                Console.Write($"[{demandId}]");

                foreach (var item in result.XesDictionary)
                {
                    if (item.Key.DemandId != demandId)
                    {
                        Console.WriteLine("");
                        Console.Write($"[{item.Key.DemandId}]");
                        demandId = item.Key.DemandId;
                    }
                    Console.Write($"{item.Key.PathId} -> {item.Value};");
                }
                FileWriter writer = new FileWriter();
                writer.WriteToFile(result, "DAP_" + fileName);
            }
            else
            {
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();

                var result = evolutionary.RunDDAP();

                stopWatch.Stop();
                Console.WriteLine($"Liczba iteracji: {evolutionary.CurrentGeneration}");
                Console.WriteLine($"Czas uzyskania rozwi¹zania: {stopWatch.Elapsed}");
                Console.WriteLine($"Koszt DDAP: {result.NetworkCost}");
                int demandId;
                if (result.XesDictionary.Count > 0)
                {
                    demandId = result.XesDictionary.ElementAt(0).Key.DemandId;
                }
                else
                {
                    demandId = 1;
                }
                Console.WriteLine("");
                Console.Write($"[{demandId}]");

                foreach (var item in result.XesDictionary)
                {
                    if (item.Key.DemandId != demandId)
                    {
                        Console.WriteLine("");
                        Console.Write($"[{item.Key.DemandId}]");
                        demandId = item.Key.DemandId;
                    }
                    Console.Write($"{item.Key.PathId} -> {item.Value};");
                }
                FileWriter writer = new FileWriter();
                writer.WriteToFile(result, "DDAP_" + fileName);
            }
        }