示例#1
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();
        }
示例#2
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;
        }
示例#3
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);
 }
示例#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);
     }
 }
示例#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);
     }
 }
示例#6
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);
        }
示例#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);
     }
 }
示例#8
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';
        }
示例#9
0
 public void setLandscape(landscape e)
 {
     home = e;
     updateFittness();
 }
示例#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))));
     }
 }
示例#11
0
文件: Stat.cs 项目: rustynoob/GA
 public Stat(landscape e, Population p)
 {
     process(e, p);
 }