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)); } } }
public SimpleGA(Population population) { this.population = population; this.matingPool = new Individual[population.Size]; Initialize(); }
public void Scale(Population population) { for (int i = 0; i < population.Size; i++) { population.Individuals[i].Fitness = population.Individuals[i].Objective; } }
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; }
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; } } }
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(); }
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); }
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); } }
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); }
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'; }
public virtual void Update(Population population) { this.population = population; }
public Stat(landscape e, Population p) { process(e, p); }