コード例 #1
0
ファイル: Selection.cs プロジェクト: harnold/cobe
        public virtual void Update(Population population)
        {
            this.population = population;

            if (partialSums == null || population.Size != partialSums.Length)
                partialSums = new double[population.Size];

            if (population.GA.Maximize) {

                partialSums[0] =
                    population.Individuals[0].Fitness / population.FitnessSum;

                for (int i = 1; i < population.Size; i++) {
                    partialSums[i] = partialSums[i-1]
                        + (population.Individuals[i].Fitness
                           / population.FitnessSum);
                }

            } else {

                double inverseFitnessSum = 0.0;

                for (int i = 0; i < population.Size; i++)
                    inverseFitnessSum += 1.0 / population.Individuals[i].Fitness;

                partialSums[0] =
                    1.0 / (population.Individuals[0].Fitness * inverseFitnessSum);

                for (int i = 1; i < population.Size; i++) {
                    partialSums[i] = partialSums[i-1]
                        + (1.0 / (population.Individuals[i].Fitness
                                  * inverseFitnessSum));
                }
            }
        }
コード例 #2
0
ファイル: SimpleGA.cs プロジェクト: harnold/cobe
        public SimpleGA(Population population)
        {
            this.population = population;
            this.matingPool = new Individual[population.Size];

            Initialize();
        }
コード例 #3
0
ファイル: Scaling.cs プロジェクト: harnold/cobe
 public void Scale(Population population)
 {
     for (int i = 0; i < population.Size; i++) {
         population.Individuals[i].Fitness =
             population.Individuals[i].Objective;
     }
 }
コード例 #4
0
ファイル: Form1.cs プロジェクト: rustynoob/GA
        private void button2_Click(object sender, EventArgs e)
        {
            if (seed == null) return;
            int sampleSize = (int)SampSize.Value;
            int mutate = (int)MapDivrg.Value;
            List<List<List<Stat>>> stats = new List<List<List<Stat>>>();
            for (int j = 0; j < sampleSize; j++)
            {
                stats.Add(new List<List<Stat>>());
                for (int i = 0; i < mutate; i++)
                {
                    Population pop = new Population(seed);
                    landscape map = new landscape(seed.home);
                    map.mutate(i + 1);
                    pop.setLandscape(map);
                    GA tempGA = new GA(pop);
                    stats[j].Add(tempGA.evolve());
                }
            }
            string output = "";

            for (int i = 0; i < stats[0].Count; i++){

                for (int j = 0; j < sampleSize; j++)
                {
                    output += stats[j][i].Count + ",";
                }
                output += Environment.NewLine;
            }
            fit.Text = output;
        }
コード例 #5
0
ファイル: Scaling.cs プロジェクト: harnold/cobe
        public void Scale(Population population)
        {
            Individual[] individuals = population.Individuals;
            double mean = population.ObjectiveMean;
            double min  = population.ObjectiveMin;
            double max  = population.ObjectiveMax;

            double slope = 1.0;

            if (population.GA.Maximize) {
                if (max > mean)
                    slope = (k * mean - mean) / (max - mean);
            } else {
                if (mean > min)
                    slope = (1/k * mean - mean) / (min - mean);
            }

            if (truncate) {

                for (int i = 0; i < population.Size; i++) {
                    individuals[i].Fitness =
                        slope * (individuals[i].Objective - mean) + mean;
                    if (individuals[i].Fitness < 0.0)
                        individuals[i].Fitness = 0.0;
                }

            } else {

                for (int i = 0; i < population.Size; i++) {
                    individuals[i].Fitness =
                        slope * (individuals[i].Objective - mean) + mean;
                }
            }
        }
コード例 #6
0
ファイル: Stat.cs プロジェクト: rustynoob/GA
        public void process(landscape e, Population p)
        {
            p.sort();
            min = p.getFittness(0);
            max = p.getFittness(p.size()-1);
            mean = 0;
            count = p.size();

            for (int i = 0; i < p.size(); i++)
            {
                double fittness = p.getFittness(i);
                mean += fittness;
                /*
                if (fittness < min)
                {
                    min = fittness;
                }
                if (fittness > max)
                {
                    max = fittness;
                }
                 * */
            }
            med = p.getFittness(p.size() / 2);
            mean /= (double)p.size();
        }
コード例 #7
0
ファイル: ga.cs プロジェクト: rustynoob/GA
 public GA(Population Pop)
 {
     if (r == null) r = new Random();
     world = new landscape(Pop.home);
     pop = new Population(Pop);
     generation = 0;
     targetSize = Pop.size();
     stats = new List<Stat>(maxGeneration);
 }
コード例 #8
0
ファイル: Population.cs プロジェクト: rustynoob/GA
 public Population(Population p)
 {
     dead = p.dead;
     home = p.home;
     indi = new List<Individual>(p.indi.Count);
     for (int i = 0; i < p.indi.Count; i++)
     {
         indi.Add(p.get(i));
         indi[i].setFittness(home);
     }
 }
コード例 #9
0
ファイル: ga.cs プロジェクト: rustynoob/GA
        public GA()
        {
            System.Diagnostics.Debug.WriteLine("Initilizing invalid GA");

            if(r == null)r = new Random();
            world = new landscape(12);
            pop = new Population(50, world);
            generation = 0;
            targetSize = pop.size();
            stats = new List<Stat>(maxGeneration);
        }
コード例 #10
0
ファイル: Form1.cs プロジェクト: rustynoob/GA
        private void run_Click_1(object sender, EventArgs e)
        {
            int time;

            landscape env = new landscape((int)CityCount.Value);
            Population pop = new Population((int)setPopSize.Value, env);
            ga = new GA(pop);

            ga.mutationFactor = (int)setMutFact.Value;

            seed = ga.pop;
            time = ga.evolve().Count;
            fit.Text = "" + time +'\n';
        }
コード例 #11
0
ファイル: Selection.cs プロジェクト: harnold/cobe
 public virtual void Update(Population population)
 {
     this.population = population;
 }
コード例 #12
0
ファイル: Stat.cs プロジェクト: rustynoob/GA
 public Stat(landscape e, Population p)
 {
     process(e, p);
 }