Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/23/09 15:17:08 (14 years ago)
Author:
swagner
Message:

Removed plugin HeuristicLab.Constraints (#804)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Random/3.3/UniformRandomizer.cs

    r1853 r2524  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
    27 using HeuristicLab.Constraints;
    2827using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2928
     
    105104      if (value is DoubleData)
    106105        RandomizeUniform((DoubleData)value, mt, min, max);
    107       else if (value is ConstrainedDoubleData)
    108         RandomizeUniform((ConstrainedDoubleData)value, mt, min, max);
    109106      else if (value is IntData)
    110107        RandomizeUniform((IntData)value, mt, min, max);
    111       else if (value is ConstrainedIntData)
    112         RandomizeUniform((ConstrainedIntData)value, mt, min, max);
    113108      else throw new ArgumentException("Can't handle type " + value.GetType().Name);
    114109    }
     
    137132        data.Data = (int)Math.Floor(mt.NextDouble() * (max - min) + min);
    138133      }
    139 
    140       /// <summary>
    141       /// Generates a new double random number, being restricted to some constraints.
    142       /// </summary>
    143       /// <exception cref="InvalidOperationException">Thrown when no valid value could be found.</exception>
    144       /// <param name="data">The double object which the new value is assigned to and whose constraints
    145       /// must be fulfilled.</param>
    146       /// <param name="mt">The random number generator.</param>
    147       /// <param name="min">The left border of the interval in which the next random number has to lie.</param>
    148       /// <param name="max">The right border (exclusive) of the interval in which the next random number
    149       /// has to lie.</param>
    150       public void RandomizeUniform(ConstrainedDoubleData data, MersenneTwister mt, double min, double max) {
    151         for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {
    152           double r = mt.NextDouble() * (max - min) + min;
    153           if(IsIntegerConstrained(data)) {
    154             r = Math.Floor(r);
    155           }
    156           if(data.TrySetData(r)) {
    157             return;
    158           }
    159         }
    160         throw new InvalidOperationException("Couldn't find a valid value");
    161       }
    162       /// <summary>
    163       /// Generates a new int random number, being restricted to some constraints.
    164       /// </summary>
    165       /// <exception cref="InvalidOperationException">Thrown when no valid value could be found.</exception>
    166       /// <param name="data">The int object which the new value is assigned to and whose constraints
    167       /// must be fulfilled.</param>
    168       /// <param name="mt">The random number generator.</param>
    169       /// <param name="min">The left border of the interval in which the next random number has to lie.</param>
    170       /// <param name="max">The right border (exclusive) of the interval in which the next random number
    171       /// has to lie.</param>
    172       public void RandomizeUniform(ConstrainedIntData data, MersenneTwister mt, double min, double max) {
    173         for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {
    174           int r = (int)Math.Floor(mt.NextDouble() * (max - min) + min);
    175           if(data.TrySetData(r)) {
    176             return;
    177           }
    178         }
    179         throw new InvalidOperationException("Couldn't find a valid value");
    180       }
    181 
    182       private bool IsIntegerConstrained(ConstrainedDoubleData data) {
    183         foreach(IConstraint constraint in data.Constraints) {
    184           if(constraint is IsIntegerConstraint) {
    185             return true;
    186           }
    187         }
    188         return false;
    189       }
    190134    }
    191135}
Note: See TracChangeset for help on using the changeset viewer.