Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.Error.WriteLine("You have to at least specify the data file path");
                return;
            }

            var mutation  = new UniformMutation(MutationProbability);
            var selection = new KTournamentSelection(TournamentSize);
            var crossover = new ArithmeticCrossover();

            var fitnessFunction = new FitnessFunction(args[0]);

            IGeneticAlgorithm <DecimalArrayChromosome> geneticAlgorithm;

            if (args.Length == 2 && args[1].ToLower() == "gen")
            {
                geneticAlgorithm = new GenerationGeneticAlgorithm(mutation, selection, crossover, fitnessFunction,
                                                                  IterationLimit, FitnessTerminator, PopulationSize);
            }
            else
            {
                geneticAlgorithm = new EliminationGeneticAlgorithm(mutation, selection, crossover, fitnessFunction,
                                                                   IterationLimit, FitnessTerminator, PopulationSize);
            }

            var optimum = geneticAlgorithm.FindOptimum();

            Console.WriteLine();
            Console.WriteLine(optimum);
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            var dataset = new Dataset.Dataset(DatasetFilePath);
            var ann     = new ANN(Architecture);

            var fitness = new FitnessFunction(ann, dataset);

            var mutation   = new GaussMutation(MutationThreshold, MutationProbability, Sigma1, Sigma2);
            var selection  = new KTournamentSelection <DoubleArrayChromosome>(TournamentSize);
            var crossovers = new List <ICrossover <DoubleArrayChromosome> >()
            {
                new ArithmeticCrossover(),
                new HeuristicCrossover(),
                new UniformCrossover()
            };

            var geneticAlgorithm =
                new EliminationGeneticAlgorithm(mutation, selection, crossovers, fitness, IterationLimit, ErrorLimit, PopulationSize);

            var optimum = geneticAlgorithm.FindOptimum();
            var correctClassification = 0;

            foreach (var sample in dataset)
            {
                var classification = ann.CalculateOutput(sample.Input, optimum.Values);
                var correct        = true;

                for (int i = 0; i < classification.Length; i++)
                {
                    classification[i] = classification[i] < 0.5 ? 0 : 1;
                    if (Math.Abs(classification[i] - sample.Classification[i]) > 10e-9)
                    {
                        correct = false;
                    }
                }

                Console.WriteLine(classification[0] + " " + classification[1] + " " + classification[2] +
                                  " <=> " + sample.Classification[0] + " " + sample.Classification[1] + " " + sample.Classification[2] + " ");

                if (correct)
                {
                    correctClassification++;
                }
            }

            Console.WriteLine("Correct => " + correctClassification + ", Total => " + dataset.Count());

            ann.WriteNeuronLayerParametersToFile(ParametersFilePath, 1, optimum.Values);
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            FitnessFunction.Rides         = ParseData(out int fleetSize, out int bonus, out int steps);
            Chromosome.FleetSize          = fleetSize;
            FitnessFunction.NumberOfSteps = steps;
            FitnessFunction.Bonus         = bonus;

            var mutation        = new UniformMutation(MutationProbability);
            var selection       = new KTournamentSelection(TournamentSize);
            var crossover       = new UniformCrossover();
            var fitnessFunction = new FitnessFunction();

            var geneticAlgorithm = new EliminationGeneticAlgorithm(mutation, selection, crossover, fitnessFunction,
                                                                   IterationLimit, FitnessTerminator, PopulationSize, FitnessFunction.Rides.Count);

            var optimum = geneticAlgorithm.FindOptimum();

            WriteOutput(optimum);
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            var busStops = new List <BusStop>();
            var students = new List <Student>();

            ParseFromFile(busStops, students);

            var mutation        = new StudentBusMutation(MutationProbability);
            var selection       = new KTournamentSelection(TournamentSize);
            var crossover       = new StudentBusCrossover();
            var fitnessFunction = new FitnessFunction.FitnessFunction();

            var geneticAlgorithm = new EliminationGeneticAlgorithm(mutation, selection, crossover, fitnessFunction,
                                                                   IterationLimit, FitnessTerminator, PopulationSize, students, busStops, InstanceFilePath);

            var optimum = geneticAlgorithm.FindOptimum();

            Console.WriteLine();
            Console.WriteLine(optimum.Fitness);

            optimum.Students = optimum.Students.OrderBy(x => x.Id).ToList();

            HelperMethods.WriteToFile(optimum.ToString(), InstanceResultFilePath);
        }