Example #1
0
 /// <summary>
 /// make a clone of the given individual
 /// </summary>
 /// <param name="source"></param>
 public void Copy(selfoptInstance source)
 {
     for (int p = 0; p < parameter.Length; p++)
     {
         parameter[p].Copy(source.parameter[p]);
     }
     score = source.score;
 }
Example #2
0
        private void init(int no_of_instances, int parameters_per_instance)
        {
            this.parameters_per_instance = parameters_per_instance;
            instance = new selfoptInstance[no_of_instances];
            for (int i = 0; i < no_of_instances; i++)
                instance[i] = new selfoptInstance(parameters_per_instance);

            parameterName = new String[parameters_per_instance];

            // store a few best scores
            bestScoreHistory = new float[1000];
            scoreHistory = new float[1000];

            // create an array to keep track of phase space scores
            phase_space_scores = new float[50, 50, 2];
        }
Example #3
0
        /// <summary>
        /// perform crossover between two parent individuals
        /// </summary>
        /// <param name="parent1"></param>
        /// <param name="parent2"></param>
        /// <param name="mutation_rate"></param>
        /// <param name="rnd"></param>
        public void copysexual(selfoptInstance parent1, selfoptInstance parent2, float mutation_rate, Random rnd)
        {
            //copy from first parent
            Copy(parent1);

            //copy half the parameters randomly from second parent
            for (int p = 0; p < parameter.Length / 2; p++)
            {
                int idx = rnd.Next(parameter.Length - 1);
                parameter[idx].Copy(parent2.parameter[idx]);
            }

            //mutate
            score = 1;
            Mutate(rnd, mutation_rate);
            score = 0;
        }
Example #4
0
        private void init(int no_of_instances, int parameters_per_instance)
        {
            this.parameters_per_instance = parameters_per_instance;
            instance = new selfoptInstance[no_of_instances];
            for (int i = 0; i < no_of_instances; i++)
            {
                instance[i] = new selfoptInstance(parameters_per_instance);
            }

            parameterName = new String[parameters_per_instance];

            // store a few best scores
            bestScoreHistory = new float[1000];
            scoreHistory     = new float[1000];

            // create an array to keep track of phase space scores
            phase_space_scores = new float[50, 50, 2];
        }
Example #5
0
 /// <summary>
 /// sort into score order, best first
 /// </summary>
 private void Sort()
 {
     for (int i = 0; i < instance.Length - 1; i++)
     {
         for (int j = i + 1; j < instance.Length; j++)
         {
             if (((smallerScoresAreBetter) && (instance[i].score > instance[j].score)) ||
                 ((!smallerScoresAreBetter) && (instance[i].score < instance[j].score)))
             {
                 selfoptInstance temp = instance[i];
                 instance[i] = instance[j];
                 instance[j] = temp;
             }
         }
     }
     best_index = 0;
     best_score = instance[best_index].score;
 }
Example #6
0
        /// <summary>
        /// proceed to the next generation
        /// </summary>
        private void update()
        {
            // sort by score
            Sort();

            // replace lower scoring instances, using sexual reproduction
            for (int i = instance.Length / 2; i < instance.Length; i++)
            {
                selfoptInstance parent1 = instance[rnd.Next(instance.Length / 2)];
                selfoptInstance parent2 = instance[rnd.Next(instance.Length / 2)];
                instance[i].copysexual(parent1, parent2, mutationRate, rnd);
            }

            //set the current instance to be evaluated
            current_instance_index = instance.Length / 2;

            // increment generations
            generation++;
        }
Example #7
0
        /// <summary>
        /// perform crossover between two parent individuals
        /// </summary>
        /// <param name="parent1"></param>
        /// <param name="parent2"></param>
        /// <param name="mutation_rate"></param>
        /// <param name="rnd"></param>
        public void copysexual(selfoptInstance parent1, selfoptInstance parent2, float mutation_rate, Random rnd)
        {
            //copy from first parent
            Copy(parent1);

            //copy half the parameters randomly from second parent
            for (int p = 0; p < parameter.Length / 2; p++)
            {
                int idx = rnd.Next(parameter.Length - 1);
                parameter[idx].Copy(parent2.parameter[idx]);
            }

            //mutate
            score = 1;
            Mutate(rnd, mutation_rate);
            score = 0;
        }
Example #8
0
 /// <summary>
 /// make a clone of the given individual
 /// </summary>
 /// <param name="source"></param>
 public void Copy(selfoptInstance source)
 {
     for (int p = 0; p < parameter.Length; p++)
         parameter[p].Copy(source.parameter[p]);
     score = source.score;
 }