Esempio n. 1
0
        public double berechneFitness(Individuum ind)
        {
            if (ind.gens.Count < 3)
            {
                throw new Exception("Genanzahl im individuum  kleiner 3. ("+ind.gens.Count+")");
            }

            double x1 = ind.gens[0].getDouble();
            double x2 = ind.gens[1].getDouble();
            double x3 = ind.gens[2].getDouble();

            return berechneGleichungen(x1, x2, x3);
        }
Esempio n. 2
0
        public void recombine()
        {
            int sequencePointer;
            Individuum parent1;
            Individuum parent2;
            Individuum child1; // = new Individuum();
            Individuum child2; // = new Individuum();

            for(int i=0; i < 0.35 * oldPopulation.Count; i++)
            {
                sequencePointer = random.Next(Gen.getSize());
                child1 = new Individuum();
                child2 = new Individuum();
                parent1 = oldPopulation[random.Next(oldPopulation.Count)];
                parent2 = oldPopulation[random.Next(oldPopulation.Count)];

                for (int j = 0; j < parent1.gens.Count; j++)
                {
                    child1.gens[j].sequence.Clear();
                    child2.gens[j].sequence.Clear();
                    if (sequencePointer > 0)
                    {
                        child1.gens[j].sequence.InsertRange(0, parent1.gens[j].sequence.GetRange(0, sequencePointer));
                        child2.gens[j].sequence.InsertRange(0, parent2.gens[j].sequence.GetRange(0, sequencePointer));
                    }
                    child1.gens[j].sequence.InsertRange(sequencePointer, parent2.gens[j].sequence.GetRange(sequencePointer, Gen.getSize() - sequencePointer));
                    child2.gens[j].sequence.InsertRange(sequencePointer, parent1.gens[j].sequence.GetRange(sequencePointer, Gen.getSize() - sequencePointer));
                }

                newPopulation.Add(child1);
                newPopulation.Add(child2);

                //Ausgabe
                System.Console.WriteLine("Pointer: " + sequencePointer);
                for (int j = 0; j < Individuum.GetNumberOfGens(); j++)
                {
                    System.Console.WriteLine("Parent1: " + string.Join(", ", parent1.gens[j].sequence.ToArray()));
                    System.Console.WriteLine("Parent2: " + string.Join(", ", parent2.gens[j].sequence.ToArray()));
                    System.Console.WriteLine("Child1: " + string.Join(", ", child1.gens[j].sequence.ToArray()));
                    System.Console.WriteLine("Child2: " + string.Join(", ", child2.gens[j].sequence.ToArray()));
                    System.Console.WriteLine("-------------------------------");
                }
            }
        }