Esempio n. 1
0
        public void RandomSolutionShouldBeFeasible()
        {
            HeuristicsFactory.Register("SA", () => new SimulatedAnnealing());
            MemeticAlgorithm algorithm  = new MemeticAlgorithm();
            Parameters       parameters = new Parameters
            {
                PopulationSize       = 30,
                Selection            = new RouletteSelection(),
                CrossoverOperators   = new List <CrossoverOperator>(),
                MutationOperators    = new List <MutationOperator>(),
                CrossoverProbability = 0.75f,
                MutationProbability  = 0.05f,
                Fitness                    = new FitnessFunction(4.0f, 1.0f),
                ChromosomeFactory          = new SolutionFactory(),
                EliteChildrenCount         = 3,
                GeneCount                  = problem.Customers.Count,
                FitnessStrategy            = MemeticLibrary.Fitness.FitnessStrategy.MINIMIZE,
                ConvergenceLimit           = 1.0f,
                PreservedChromosomesNumber = 10,
                MaxIterations              = 5000
            };

            parameters.CrossoverOperators.Add(new PartiallyMatchedCrossover());
            parameters.MutationOperators.Add(new SwapOperator());
            algorithm.Run(problem, parameters);
        }
 private void Register()
 {
     SelectionFactory.Register("roulette", () => new RouletteSelection());
     CrossoverOperatorFactory.Register("OX", () => new OrderCrossover());
     CrossoverOperatorFactory.Register("CX", () => new CycleCrossover());
     CrossoverOperatorFactory.Register("PMX", () => new PartiallyMatchedCrossover());
     CrossoverOperatorFactory.Register("UOX", () => new UniformBasedOrderCrossover());
     MutationOperatorFactory.Register("swap", () => new SwapOperator());
     MutationOperatorFactory.Register("insertion", () => new InsertionOperator());
     MutationOperatorFactory.Register("inversion", () => new InversionOperator());
     MutationOperatorFactory.Register("displacement", () => new DisplacementOperator());
     HeuristicsFactory.Register("SA", () => new SimulatedAnnealing());
 }