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)

Location:
trunk/sources/HeuristicLab.Random/3.3
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Random/3.3/HeuristicLab.Random-3.3.csproj

    r1691 r2524  
    9696  </ItemGroup>
    9797  <ItemGroup>
    98     <ProjectReference Include="..\..\HeuristicLab.Constraints\3.3\HeuristicLab.Constraints-3.3.csproj">
    99       <Project>{19C1E42A-4B48-4EFD-B697-899016F1C198}</Project>
    100       <Name>HeuristicLab.Constraints-3.3</Name>
    101     </ProjectReference>
    10298    <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj">
    10399      <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project>
  • trunk/sources/HeuristicLab.Random/3.3/NormalRandomAdder.cs

    r1853 r2524  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
    27 using HeuristicLab.Constraints;
    2827using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2928
     
    106105      if (value is IntData)
    107106        AddNormal((IntData)value, normal);
    108       else if (value is ConstrainedIntData)
    109         AddNormal((ConstrainedIntData)value, normal);
    110       else if (value is ConstrainedDoubleData)
    111         AddNormal((ConstrainedDoubleData)value, normal);
    112107      else if (value is DoubleData)
    113108        AddNormal((DoubleData)value, normal);
     
    125120
    126121    /// <summary>
    127     /// Generates a new double random number and adds it to the value of the given <paramref name="data"/>
    128     /// checking its constraints.
    129     /// </summary>
    130     /// <exception cref="InvalidProgramException">Thrown when with the current settings no valid value
    131     /// could be found.</exception>
    132     /// <param name="data">The double object where to add the random number and whose constraints
    133     /// to fulfill.</param>
    134     /// <param name="normal">The continuous, normally distributed random variable.</param>
    135     public void AddNormal(ConstrainedDoubleData data, NormalDistributedRandom normal) {
    136       for (int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {
    137         double newValue = data.Data + normal.NextDouble();
    138         if (IsIntegerConstrained(data)) {
    139           newValue = Math.Round(newValue);
    140         }
    141         if (data.TrySetData(newValue)) {
    142           return;
    143         }
    144       }
    145       throw new InvalidProgramException("Coudn't find a valid value");
    146     }
    147 
    148     /// <summary>
    149122    /// Generates a new int random number and adds it to value of the given <paramref name="data"/>.
    150123    /// </summary>
     
    154127      data.Data = (int)Math.Round(data.Data + normal.NextDouble());
    155128    }
    156 
    157     /// <summary>
    158     /// Generates a new int random number and adds it to the value of the given <paramref name="data"/>
    159     /// checking its constraints.
    160     /// </summary>
    161     /// <exception cref="InvalidProgramException">Thrown when with the current settings no valid value
    162     /// could be found.</exception>
    163     /// <param name="data">The int object where to add the generated value and whose contraints to check.</param>
    164     /// <param name="normal">The continuous, normally distributed random variable.</param>
    165     public void AddNormal(ConstrainedIntData data, NormalDistributedRandom normal) {
    166       for (int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {
    167         if (data.TrySetData((int)Math.Round(data.Data + normal.NextDouble())))
    168           return;
    169       }
    170       throw new InvalidProgramException("Couldn't find a valid value.");
    171     }
    172 
    173     private bool IsIntegerConstrained(ConstrainedDoubleData data) {
    174       foreach (IConstraint constraint in data.Constraints) {
    175         if (constraint is IsIntegerConstraint) {
    176           return true;
    177         }
    178       }
    179       return false;
    180     }
    181129  }
    182130}
  • 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}
  • trunk/sources/HeuristicLab.Random/3.3/UniformRandomAdder.cs

    r1530 r2524  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
    27 using HeuristicLab.Constraints;
    2827
    2928namespace HeuristicLab.Random {
     
    9190      if (value is IntData)
    9291        AddUniform((IntData)value, mt, min, max);
    93       else if (value is ConstrainedIntData)
    94         AddUniform((ConstrainedIntData)value, mt, min, max);
    9592      else if (value is DoubleData)
    9693        AddUniform((DoubleData)value, mt, min, max);
    97       else if (value is ConstrainedDoubleData)
    98         AddUniform((ConstrainedDoubleData)value, mt, min, max);
    9994      else throw new InvalidOperationException("Can't handle type " + value.GetType().Name);
    100     }
    101 
    102     /// <summary>
    103     /// Adds a new double random variable being restricted to some constraints to the value of the given
    104     /// <paramref name="data"/>.
    105     /// </summary>
    106     /// <exception cref="InvalidProgramException">Thrown when no valid value can be found.</exception>
    107     /// <param name="data">The data where to add the new variable and where to assign the new value to.</param>
    108     /// <param name="mt">The random number generator.</param>
    109     /// <param name="min">The left border of the interval in which the next random number has to lie.</param>
    110     /// <param name="max">The right border (exclusive) of the interval in which the next random number
    111     /// has to lie.</param>
    112     public void AddUniform(ConstrainedDoubleData data, MersenneTwister mt, double min, double max) {
    113       for (int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {
    114         double newValue = data.Data + mt.NextDouble() * (max - min) + min;
    115         if (IsIntegerConstrained(data)) {
    116           newValue = Math.Floor(newValue);
    117         }
    118         if (data.TrySetData(newValue)) {
    119           return;
    120         }
    121       }
    122       throw new InvalidProgramException("Couldn't find a valid value");
    123     }
    124 
    125     /// <summary>
    126     /// Adds a new int random variable being restricted to some constraints to the value of the given
    127     /// <paramref name="data"/>.
    128     /// </summary>
    129     /// <exception cref="InvalidProgramException">Thrown when no valid value could be found.</exception>
    130     /// <param name="data">The data where to add the random value and where to assign the new value to.</param>
    131     /// <param name="mt">The random number generator.</param>
    132     /// <param name="min">The left border of the interval in which the next random number has to lie.</param>
    133     /// <param name="max">The right border (exclusive) of the interval in which the next random number
    134     /// has to lie.</param>
    135     public void AddUniform(ConstrainedIntData data, MersenneTwister mt, double min, double max) {
    136       for (int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {
    137         int newValue = (int)Math.Floor(data.Data + mt.NextDouble() * (max - min) + min);
    138         if (data.TrySetData(newValue)) {
    139           return;
    140         }
    141       }
    142       throw new InvalidProgramException("Couldn't find a valid value");
    14395    }
    14496
     
    168120      data.Data = (int)Math.Floor(data.Data + mt.NextDouble() * (max - min) + min);
    169121    }
    170     private bool IsIntegerConstrained(ConstrainedDoubleData data) {
    171       foreach (IConstraint constraint in data.Constraints) {
    172         if (constraint is IsIntegerConstraint) {
    173           return true;
    174         }
    175       }
    176       return false;
    177     }
    178122  }
    179123}
  • 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.