Example #1
0
File: Stat.cs Project: 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();
        }
Example #2
0
        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;
        }
Example #3
0
File: ga.cs Project: 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);
 }
Example #4
0
 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);
     }
 }
Example #5
0
 public Population(int size, landscape e)
 {
     home = e;
     dead = 0;
     indi = new List<Individual>(size*2);
     for (int i = 0; i < size; i++)
     {
         indi.Add(new Individual(home.size()));
         indi[i].setFittness(home);
     }
 }
Example #6
0
File: ga.cs Project: 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);
        }
Example #7
0
 public landscape(landscape e)
 {
     r = new Random();
     int size = e.size();
     x = new int[size];
     y = new int[size];
     for (int i = 0; i < size; i++)
     {
         x[i] = e.getX(i);
         y[i] = e.getY(i);
     }
 }
Example #8
0
        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';
        }
Example #9
0
 public void setLandscape(landscape e)
 {
     home = e;
     updateFittness();
 }
Example #10
0
 public void setFittness(landscape e)
 {
     fittness = 0;
     int b = get(0);
     for (int i = 1; i < genes.Length; i++)
     {
         int a = b;
         b = get(i);
         int dx = e.getX(a) - e.getX(b);
         //dx = dx > 0 ? dx : -dx;
         int dy = e.getY(a) - e.getY(b);
         //dy = dy > 0 ? dy : -dy;
         fittness += (Math.Sqrt((double)((dx * dx) + (dy * dy))));
     }
 }
Example #11
0
File: Stat.cs Project: rustynoob/GA
 public Stat(landscape e, Population p)
 {
     process(e, p);
 }