Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/08/08 19:56:19 (16 years ago)
Author:
gkronber
Message:

fixed #238 by using floor instead of round when we use a uniform-distribution in combination with integer variables

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Random/UniformRandomAdder.cs

    r2 r469  
    4343    public UniformRandomAdder() {
    4444      AddVariableInfo(new VariableInfo("Value", "The value to manipulate (type is one of: IntData, ConstrainedIntData, DoubleData, ConstrainedDoubleData)", typeof(IObjectData), VariableKind.In));
    45       AddVariableInfo(new VariableInfo("ShakingFactor", "Determines the force of the shaking factor.", typeof(DoubleData), VariableKind.In));
     45      AddVariableInfo(new VariableInfo("ShakingFactor", "Determines the force of the shaking factor", typeof(DoubleData), VariableKind.In));
    4646      AddVariableInfo(new VariableInfo("Random", "The random generator to use", typeof(MersenneTwister), VariableKind.In));
    47       AddVariableInfo(new VariableInfo("Min", "Lower bound of the uniform distribution.", typeof(DoubleData), VariableKind.None));
     47      AddVariableInfo(new VariableInfo("Min", "Lower bound of the uniform distribution (inclusive)", typeof(DoubleData), VariableKind.None));
    4848      GetVariableInfo("Min").Local = true;
    4949      AddVariable(new Variable("Min", new DoubleData(-1.0)));
    5050
    51       AddVariableInfo(new VariableInfo("Max", "Upper bound of the uniform distribution", typeof(DoubleData), VariableKind.None));
     51      AddVariableInfo(new VariableInfo("Max", "Upper bound of the uniform distribution (exclusive)", typeof(DoubleData), VariableKind.None));
    5252      GetVariableInfo("Max").Local = true;
    5353      AddVariable(new Variable("Max", new DoubleData(1.0)));
     
    8484
    8585      public override void Visit(ConstrainedDoubleData data) {
    86 
    8786        for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {
    88 
    8987          double newValue = data.Data + mt.NextDouble() * (max - min) + min;
    90 
    9188          if(IsIntegerConstrained(data)) {
    92             newValue = Math.Round(newValue);
     89            newValue = Math.Floor(newValue);
    9390          }
    94 
    9591          if(data.TrySetData(newValue)) {
    9692            return;
    9793          }
    9894        }
    99 
    10095        throw new InvalidProgramException("Couldn't find a valid value");
    10196      }
     
    10398      public override void Visit(ConstrainedIntData data) {
    10499        for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {
    105           int newValue = (int)Math.Round(data.Data + mt.NextDouble() * (max - min) + min);
    106 
     100          int newValue = (int)Math.Floor(data.Data + mt.NextDouble() * (max - min) + min);
    107101          if(data.TrySetData(newValue)) {
    108102            return;
     
    117111
    118112      public override void Visit(IntData data) {
    119         data.Data = (int)Math.Round(data.Data + mt.NextDouble() * (max - min) + min);
     113        data.Data = (int)Math.Floor(data.Data + mt.NextDouble() * (max - min) + min);
    120114      }
    121115      private bool IsIntegerConstrained(ConstrainedDoubleData data) {
Note: See TracChangeset for help on using the changeset viewer.