Ejemplo n.º 1
0
 public void setValue(float a_value) {
   if (m_wholeNumbers) {
     m_value_float = Math.round(a_value);
   } else {
     m_value_float = a_value;
   }
 }
Ejemplo n.º 2
0
 public void setValue(double a_value) {
   if (m_wholeNumbers) {
     m_value_double = Math.round(a_value);
   } else {
     m_value_double = a_value;
   }
 }
Ejemplo n.º 3
0
 protected void setRandomValue(double a_value) {
   RandomGenerator randomGen = getGPConfiguration().getRandomGenerator();
   m_value_double = randomGen.nextDouble() * (m_upperBounds - m_lowerBounds) + m_lowerBounds;
   if (m_wholeNumbers) {
     m_value_double = Math.round(m_value_double);
   }
 }
Ejemplo n.º 4
0
 protected void setRandomValue(float a_value) {
   RandomGenerator randomGen = getGPConfiguration().getRandomGenerator();
   m_value_float =
       (float) (randomGen.nextFloat() * (m_upperBounds - m_lowerBounds) + m_lowerBounds);
   if (m_wholeNumbers) {
     m_value_float = Math.round(m_value_float);
   }
 }
Ejemplo n.º 5
0
 public CommandGene applyMutation(int index, double a_percentage)
     throws InvalidConfigurationException {
   // If percentage is very high: do mutation not relying on
   // current value but on a random value.
   // ------------------------------------------------------
   if (a_percentage > 0.85d) {
     setRandomValue();
   } else {
     Class retType = getReturnType();
     if (retType == CommandGene.FloatClass) {
       float newValuef;
       float rangef = ((float) m_upperBounds - (float) m_lowerBounds) * (float) a_percentage;
       if (m_value_float >= (m_upperBounds - m_lowerBounds) / 2) {
         newValuef =
             m_value_float - getGPConfiguration().getRandomGenerator().nextFloat() * rangef;
       } else {
         newValuef =
             m_value_float + getGPConfiguration().getRandomGenerator().nextFloat() * rangef;
       }
       // Ensure value is within bounds.
       // ------------------------------
       if (m_lowerBounds - newValuef > DELTA || newValuef - m_upperBounds > DELTA) {
         setRandomValue(m_value_float);
       } else {
         setValue(newValuef);
       }
     } else if (retType == CommandGene.DoubleClass) {
       double newValueD;
       double rangeD = (m_upperBounds - m_lowerBounds) * a_percentage;
       if (m_value_double >= (m_upperBounds - m_lowerBounds) / 2) {
         newValueD =
             m_value_double - getGPConfiguration().getRandomGenerator().nextFloat() * rangeD;
       } else {
         newValueD =
             m_value_double + getGPConfiguration().getRandomGenerator().nextFloat() * rangeD;
       }
       // Ensure value is within bounds.
       // ------------------------------
       if (m_lowerBounds - newValueD > DELTA || newValueD - m_upperBounds > DELTA) {
         setRandomValue(m_value_float);
       } else {
         setValue(newValueD);
       }
     } else if (retType == CommandGene.IntegerClass) {
       int newValueI;
       double range = (m_upperBounds - m_lowerBounds) * a_percentage;
       if (m_value_int >= (m_upperBounds - m_lowerBounds) / 2) {
         newValueI =
             m_value_int
                 - (int) Math.round(getGPConfiguration().getRandomGenerator().nextInt() * range);
       } else {
         newValueI =
             m_value_int
                 + (int) Math.round(getGPConfiguration().getRandomGenerator().nextFloat() * range);
       }
       // Ensure value is within bounds.
       // ------------------------------
       if (newValueI < m_lowerBounds || newValueI > m_upperBounds) {
         setRandomValue(m_value_int);
       } else {
         setValue(newValueI);
       }
     } else if (retType == CommandGene.LongClass) {
       long newValueL;
       double range = (m_upperBounds - m_lowerBounds) * a_percentage;
       if (m_value_long >= (m_upperBounds - m_lowerBounds) / 2) {
         newValueL =
             m_value_long
                 - Math.round(getGPConfiguration().getRandomGenerator().nextInt() * range);
       } else {
         newValueL =
             m_value_long
                 + Math.round(getGPConfiguration().getRandomGenerator().nextFloat() * range);
       }
       // Ensure value is within bounds.
       // ------------------------------
       if (newValueL < m_lowerBounds || newValueL > m_upperBounds) {
         setRandomValue(m_value_long);
       } else {
         setValue(newValueL);
       }
     }
   }
   return this;
 }
Ejemplo n.º 6
0
 protected void setRandomValue(long a_value) {
   RandomGenerator randomGen = getGPConfiguration().getRandomGenerator();
   m_value_long =
       Math.round(randomGen.nextDouble() * (m_upperBounds - m_lowerBounds) + m_lowerBounds);
 }