public AutoevolutionaryInformation Create(List <Gen> gens) { return(new AutoevolutionaryInformation( FitnessMatcherFabrik.Create(gens.Skip(AutoEvolutionaryInformationGeneticDescriptor.Count + MutationManager.GetInstance().GetMutationTypes() + CrossOverManager.GetInstance().GetCrossOverTypes()).ToList()), gens[0].Value, gens[1].Value, gens[2].Value, gens.Skip(3).Take(MutationManager.GetInstance().GetMutationTypes()).Select(o => o.Value).ToList(), gens.Skip(3 + MutationManager.GetInstance().GetMutationTypes()).Take(CrossOverManager.GetInstance().GetCrossOverTypes()).Select(o => o.Value).ToList())); }
static void Main(string[] args) { byte[] fileContet; using (WebClient client = new WebClient()) { fileContet = client.DownloadData("http://people.sc.fsu.edu/~jburkardt/datasets/tsp/p01_d.txt"); } String input = Encoding.UTF8.GetString(fileContet).Trim(); int i = 0, j = 0; string[] rows = input.Split('\n'); float [,] distancesVector = new float[rows.Length, rows.Length]; float maxPathLength = 0; foreach (var row in rows) { j = 0; foreach (var col in Regex.Split(row.Trim(), @"\s+")) { distancesVector[i, j] = float.Parse(col.Trim()); if (distancesVector[i, j] > maxPathLength) { maxPathLength = distancesVector[i, j]; } j++; } i++; } int nodes = rows.Length; //MutationManager.GetInstance().Register(new ClassicMutationResolver()); //MutationManager.GetInstance().Register(new SwapMutationResolver()); MutationManager.GetInstance().Register(new DividedMutation(nodes, new SwapMutationResolver(), new ClassicMutationResolver())); CrossOverManager.GetInstance().Register(new DividedCrossOver(nodes, new PMXCrossOver(), new ClassicCrossOverResolver())); CrossOverManager.GetInstance().Register(new DividedCrossOver(nodes, new CycleCrossOver(), new ClassicCrossOverResolver())); var fitnessMatcherFabrik = new AutoevolutionaryFitnessMatcherDefaultImplementationFabrik(); var GAInfo = new AutoevolutionaryGeneticAlgorithmParameters <TravelSalesmanIndividual, AutoevolutionaryFitnessMatcherDefaultImplementation> { IndividualFabrik = new TravelSalesmanPathIndividualFabrik(nodes), ScenarioGeneratior = new TravelSalesmanScenarioGenerator(distancesVector, nodes, maxPathLength), EvolutionaryInformationFabrik = new AutoEvolutionaryInformationFabrik <AutoevolutionaryFitnessMatcherDefaultImplementation>(fitnessMatcherFabrik), MaxPopulation = 100, InitialLives = 3, AprovedPorcentage = 0.5f, ApariateTournamentCount = 5, DeathTournamentCount = 6, ForeingersByGeneration = 10 }; var GA = new AutoEvolutionaryGeneticAlgorithm <TravelSalesmanIndividual, AutoevolutionaryFitnessMatcherDefaultImplementation>(GAInfo); //Console.Out.WriteLine(Arrays.PrettyPrintMatrix<float>(scenarioGenerator.DistancesVector)); for (int g = 0; g < 5000; g++) { GA.AdvanceGenerations(1); var bestIndividual = GA.Population.MaxBy(o => o.getNormalizedFitness()); Console.Out.WriteLine("Generation: " + GA.GenerationNumber); Console.Out.WriteLine("AVG apariate dominance porcentage: " + GA.Population.Average(o => o.EvolutionInformtaion.CrossOverGenDominancePorcentage)); Console.Out.WriteLine("Best apariate dominance porcentage: " + bestIndividual.EvolutionInformtaion.CrossOverGenDominancePorcentage); Console.Out.WriteLine("AVG mutate amplitude: " + GA.Population.Average(o => o.EvolutionInformtaion.MutateGenAmplitudePorcentage)); Console.Out.WriteLine("Best mutate amplitude: " + bestIndividual.EvolutionInformtaion.MutateGenAmplitudePorcentage); Console.Out.WriteLine("AVG mutate choose prob: " + GA.Population.Average(o => o.EvolutionInformtaion.MutateGenChooseProbability)); Console.Out.WriteLine("Best mutate choose prob: " + bestIndividual.EvolutionInformtaion.MutateGenChooseProbability); Console.Out.WriteLine("Best mutation type prob: " + bestIndividual.EvolutionInformtaion.MutationTypeProbability[0]); Console.Out.WriteLine("Best crossover type prob: " + bestIndividual.EvolutionInformtaion.CrossOverTypeProbability[0] + ", " + bestIndividual.EvolutionInformtaion.CrossOverTypeProbability[1]); Console.Out.WriteLine("Actual Population: " + GA.Population.Count); Console.Out.WriteLine("Best path: " + String.Join(",", bestIndividual.Individual.travelOrder)); Console.Out.WriteLine("Best fitness: " + bestIndividual.getNormalizedFitness()); TravelSalesmanFitness fitness = (TravelSalesmanFitness)(bestIndividual.Fitness); Console.Out.WriteLine("Best fitness: " + fitness.TotalDistance); } while (true) { Thread.Sleep(1000); } }
public Genome Mutate(int type, float choose_probability, float amplitude_porcentage) { return(new Genome(Descriptors, MutationManager.GetInstance().Mutate(type, Gens, choose_probability, amplitude_porcentage))); }
public int GetGenCount() { return(AutoEvolutionaryInformationGeneticDescriptor.Count + MutationManager.GetInstance().GetMutationTypes() + CrossOverManager.GetInstance().GetCrossOverTypes() + FitnessMatcherFabrik.GetGenCount()); }
public List <GenDescriptor> GetGeneticDescriptor() { var descriptor = AutoEvolutionaryInformationGeneticDescriptor.ToList(); descriptor.AddRange(Enumerable.Repeat(new GenDescriptor("Mutation type prob", 0, 1, 0.001f), MutationManager.GetInstance().GetMutationTypes())); descriptor.AddRange(Enumerable.Repeat(new GenDescriptor("Apariation type prob", 0, 1, 0.001f), CrossOverManager.GetInstance().GetCrossOverTypes())); descriptor.AddRange(FitnessMatcherFabrik.GetGeneticDescriptor()); return(descriptor); }