示例#1
0
        public CPSetup(int populationSize, string filename = "")
        {
            if (String.IsNullOrEmpty(filename))
            {
                Console.WriteLine("Podaj nazwę pliku z grafem: ");
                var builder = new StringBuilder();
                builder.Append("Data/");
                builder.Append(Console.ReadLine());
                filename = builder.ToString();
            }
            Graph = new Graph(@filename);
            int[] startValues = Graph.OddVertices.ToArray();
            Fitness     = new CPFitness();
            Chromosome  = new CPChromosome(startValues.Length, startValues, populationSize);
            Population  = new Population(populationSize, populationSize, Chromosome);
            Selection   = new EliteSelection();
            Crossover   = new CPCrossover();
            Mutation    = new CPMutation();
            Termination = new FitnessStagnationTermination(50);

            GA             = new GeneticAlgorithm(Population, Fitness, Selection, Crossover, Mutation);
            GA.Termination = Termination;
        }
示例#2
0
        public CPSetup(IPopulation population, ISelection selection, ICrossover crossover, IMutation mutation, ITermination termination,
                       string filename = "")
        {
            if (String.IsNullOrEmpty(filename))
            {
                Console.WriteLine("Podaj nazwę pliku z grafem: ");
                var builder = new StringBuilder();
                builder.Append("Data/");
                builder.Append(Console.ReadLine());
                filename = builder.ToString();
            }
            Graph = new Graph(@filename);
            int[] startValues = Graph.OddVertices.ToArray();
            Fitness     = new CPFitness();
            Chromosome  = new CPChromosome(startValues.Length, startValues, population.MaxSize);
            Population  = population;
            Selection   = selection;
            Crossover   = crossover;
            Mutation    = mutation;
            Termination = termination;

            GA             = new GeneticAlgorithm(Population, Fitness, Selection, Crossover, Mutation);
            GA.Termination = Termination;
        }