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/NormalRandomizer.cs

    r1853 r2524  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
    27 using HeuristicLab.Constraints;
    2827using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2928
     
    9897      if (value is IntData)
    9998        RandomizeNormal((IntData)value, n);
    100       else if (value is ConstrainedIntData)
    101         RandomizeNormal((ConstrainedIntData)value, n);
    10299      else if (value is DoubleData)
    103100        RandomizeNormal((DoubleData)value, n);
    104       else if (value is ConstrainedDoubleData)
    105         RandomizeNormal((ConstrainedDoubleData)value, n);
    106101      else throw new InvalidOperationException("Can't handle type " + value.GetType().Name);
    107     }
    108 
    109     /// <summary>
    110     /// Generates a new double random variable based on a continuous, normally distributed random number generator
    111     /// <paramref name="normal"/> and checks some contraints.
    112     /// </summary>
    113     /// <exception cref="InvalidOperationException">Thrown when with the given settings no valid value in
    114     /// 100 tries could be found.
    115     /// </exception>
    116     /// <param name="data">The double object where to assign the new number to and whose constraints
    117     /// must be fulfilled.</param>
    118     /// <param name="normal">The continuous, normally distributed random variable.</param>
    119     public void RandomizeNormal(ConstrainedDoubleData data, NormalDistributedRandom normal) {
    120       for (int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {
    121         double r = normal.NextDouble();
    122         if (IsIntegerConstrained(data)) {
    123           r = Math.Round(r);
    124         }
    125         if (data.TrySetData(r)) {
    126           return;
    127         }
    128       }
    129       throw new InvalidOperationException("Couldn't find a valid value in 100 tries with mu=" + normal.Mu + " sigma=" + normal.Sigma);
    130     }
    131 
    132     /// <summary>
    133     /// Generates a new int random variable based on a continuous, normally distributed random number
    134     /// generator <paramref name="normal"/> and checks some constraints.
    135     /// </summary>
    136     /// <exception cref="InvalidOperationException">Thrown when with the given settings no valid
    137     /// value could be found.</exception>
    138     /// <param name="data">The int object where to assign the new value to and whose constraints must
    139     /// be fulfilled.</param>
    140     /// <param name="normal">The continuous, normally distributed random variable.</param>
    141     public void RandomizeNormal(ConstrainedIntData data, NormalDistributedRandom normal) {
    142       for (int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {
    143         double r = normal.NextDouble();
    144         if (data.TrySetData((int)Math.Round(r))) // since r is a continuous, normally distributed random variable rounding should be OK
    145           return;
    146       }
    147       throw new InvalidOperationException("Couldn't find a valid value");
    148102    }
    149103
     
    167121      data.Data = (int)Math.Round(normal.NextDouble());
    168122    }
    169 
    170 
    171     private bool IsIntegerConstrained(ConstrainedDoubleData data) {
    172       foreach (IConstraint constraint in data.Constraints) {
    173         if (constraint is IsIntegerConstraint) {
    174           return true;
    175         }
    176       }
    177       return false;
    178     }
    179123  }
    180124}
Note: See TracChangeset for help on using the changeset viewer.