Ejemplo n.º 1
0
 public static IPopulationFactory Instance()
 {
     if (_instance == null)
     {
         _instance = new PopulationFactory();
     }
     return(_instance);
 }
Ejemplo n.º 2
0
        public GeneticSolver(IPopulationFactory populationFactory, IFitness fitness, int maxEpoch = 10, int stagnantGenerationsNumber = 30, int maxFitness = int.MaxValue)
        {
            _populationFactory = populationFactory;
            _fitness           = fitness;

            StagnantGenerationsNumber = stagnantGenerationsNumber;
            MaxFitness = maxFitness;
            MaxEpoch   = maxEpoch;
        }
 public EvolutionService(IProblemService problemService, IPopulationFactory populationFactory,
                         ICrossoverOperator crossoverOperator,
                         IMutationOperator mutationOperator)
 {
     _problemService    = problemService;
     _populationFactory = populationFactory;
     _crossoverOperator = crossoverOperator;
     _mutationOperator  = mutationOperator;
 }
Ejemplo n.º 4
0
 public GeneticAlgorithm(
     IPopulationFactory <TGeneSequence> populationFactory,
     ITermination <TGeneSequence> termination,
     IFitnessEvaluator <TGeneSequence> fitnessEvaluator,
     ISelection <TGeneSequence> preservationSelection,
     ISelection <TGeneSequence> parentSelection,
     ICrossover <TGeneSequence> crossover,
     IMutation <TGeneSequence> mutation,
     int initialPopulation)
 {
     _populationFactory     = populationFactory;
     _termination           = termination;
     _fitnessEvaluator      = fitnessEvaluator;
     _preservationSelection = preservationSelection;
     _parentSelection       = parentSelection;
     _crossover             = crossover;
     _mutation          = mutation;
     _initialPopulation = initialPopulation;
 }
Ejemplo n.º 5
0
 public TournamentSelection(IEnvironmentService environmentService, IPopulationFactory populationFactory)
 {
     _environmentService = environmentService;
     _populationFactory  = populationFactory;
 }
Ejemplo n.º 6
0
 public EnvironmentService(IStudentDataService <int> studentDataService, IPopulationFactory populationFactory)
 {
     _studentDataService = studentDataService;
     _populationFactory  = populationFactory;
 }
Ejemplo n.º 7
0
        public void PopulationFactoryTest()
        {
            Console.WriteLine("PopulationFactoryTest");

            int dimP = 3;

            string [] namesP = new string [3] {
                "x0", "x1", "x2"
            };
            double [] minsP = new double [3] {
                0.0, 0.0, 0.0
            };
            double [] maxsP = new double [3] {
                100.0, 100.0, 100.0
            };
            IBlauSpace sP = BlauSpace.create(dimP, namesP, minsP, maxsP);
            Product    d  = new Product(sP);

            for (int i = 0; i < 3; i++)
            {
                int       dim   = 1;
                string [] names = new string [1];
                names[0] = "x" + i;
                double [] mins = new double [1] {
                    0.00
                };
                double [] maxs = new double [1] {
                    100.0
                };
                IBlauSpace    s    = BlauSpace.create(dim, names, mins, maxs);
                double        mean = 10.0 * (i + 1.0);
                double        std  = i + 1.0;
                IDistribution di   = new Distribution_Gaussian(s, mean, std);
                d.Add(di);
            }

            d.DistributionComplete();

            IPopulationFactory pf = PopulationFactory.Instance();
            int POPSIZE           = 100;

            AgentDummy_Factory adf = new AgentDummy_Factory(d);

            IPopulation pop = pf.create(adf, POPSIZE);

            Assert.AreEqual(pop.Size, POPSIZE);

            SingletonLogger.Instance().DebugLog(typeof(agent_tests), "distribution: " + d);
            SingletonLogger.Instance().DebugLog(typeof(agent_tests), "pop: \n" + pop);

            int count = 0;

            foreach (IAgent ag in pop)
            {
                for (int x = 0; x < 3; x++)
                {
                    double diff = Math.Abs(ag.Coordinates.getCoordinate(x) - (10.0 * (x + 1.0)));
                    Assert.AreEqual((diff > 5.0 * (x + 1.0)), false);
                }
                count++;
            }
            Assert.AreEqual(count, POPSIZE);

            for (int j = 0; j < count; j++)
            {
                IAgent agj = pop.getAgent(j);
                Assert.Throws <Exception>(delegate { pop.addAgent(agj); });
            }

            for (int j = 0; j < count; j++)
            {
                IAgent agj = pop.getAgent(0);
                pop.removeAgent(agj);
                Assert.AreEqual(pop.Size, POPSIZE - 1);
                Assert.Throws <Exception>(delegate { pop.removeAgent(agj); });
                pop.addAgent(agj);
            }
        }