Changeset 1153
- Timestamp:
- 01/16/09 11:24:03 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Random/HeuristicLabRandomPlugin.cs
r582 r1153 26 26 27 27 namespace HeuristicLab.Random { 28 /// <summary> 29 /// Plugin class for HeuristicLab.Random plugin. 30 /// </summary> 28 31 [ClassInfo(Name = "HeuristicLab.Random-3.2")] 29 32 [PluginFile(Filename = "HeuristicLab.Random-3.2.dll", Filetype = PluginFileType.Assembly)] -
trunk/sources/HeuristicLab.Random/MersenneTwister.cs
r2 r1153 39 39 40 40 namespace HeuristicLab.Random { 41 /// <summary> 42 /// A 623-Dimensionally Equidistributed Uniform Pseudo-Random Number Generator. 43 /// </summary> 41 44 public class MersenneTwister : ItemBase, IRandom { 42 45 private const int n = 624, m = 397; … … 47 50 private bool init = false; 48 51 52 /// <summary> 53 /// Initializes a new instance of <see cref="MersenneTwister"/>. 54 /// </summary> 49 55 public MersenneTwister() { 50 56 if (!init) seed((uint)DateTime.Now.Ticks); 51 57 init = true; 52 58 } 59 /// <summary> 60 /// Initializes a new instance of <see cref="MersenneTwister"/> 61 /// with the given seed <paramref name="s"/>. 62 /// </summary> 63 /// <param name="s">The seed with which to initialize the random number generator.</param> 53 64 public MersenneTwister(uint s) { 54 65 seed(s); 55 66 init = true; 56 67 } 68 /// <summary> 69 /// Initializes a new instance of <see cref="MersenneTwister"/> with the given seed array. 70 /// </summary> 71 /// <param name="array">The seed array with which to initialize the random number generator.</param> 57 72 public MersenneTwister(uint[] array) { 58 73 seed(array); … … 60 75 } 61 76 77 /// <summary> 78 /// Clones the current instance (deep clone). 79 /// </summary> 80 /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param> 81 /// <returns>The cloned object as <see cref="MersenneTwister"/>.</returns> 62 82 public override object Clone(IDictionary<Guid, object> clonedObjects) { 63 83 MersenneTwister clone = new MersenneTwister(); … … 69 89 } 70 90 91 /// <summary> 92 /// Resets the current random number generator. 93 /// </summary> 71 94 public void Reset() { 72 95 lock (locker) 73 96 seed((uint)DateTime.Now.Ticks); 74 97 } 98 /// <summary> 99 /// Resets the current random number generator with the given seed <paramref name="s"/>. 100 /// </summary> 101 /// <param name="s">The seed with which to reset the current instance.</param> 75 102 public void Reset(int s) { 76 103 lock (locker) … … 78 105 } 79 106 107 /// <summary> 108 /// Gets a new random number. 109 /// </summary> 110 /// <returns>A new int random number.</returns> 80 111 public int Next() { 81 112 lock (locker) { … … 83 114 } 84 115 } 116 /// <summary> 117 /// Gets a new random number being smaller than the given <paramref name="maxVal"/>. 118 /// </summary> 119 /// <exception cref="ArgumentException">Thrown when the given maximum value is 120 /// smaller or equal to zero.</exception> 121 /// <param name="maxVal">The maximum value of the generated random number.</param> 122 /// <returns>A new int random number.</returns> 85 123 public int Next(int maxVal) { 86 124 lock (locker) { … … 93 131 } 94 132 } 133 /// <summary> 134 /// Gets a new random number being in the given interval <paramref name="minVal"/> and 135 /// <paramref name="maxVal"/>. 136 /// </summary> 137 /// <param name="minVal">The minimum value of the generated random number.</param> 138 /// <param name="maxVal">The maximum value of the generated random number.</param> 139 /// <returns>A new int random number.</returns> 95 140 public int Next(int minVal, int maxVal) { 96 141 lock (locker) { … … 100 145 } 101 146 } 147 /// <summary> 148 /// Gets a new double random variable. 149 /// </summary> 150 /// <returns></returns> 102 151 public double NextDouble() { 103 152 lock (locker) { … … 107 156 108 157 #region Persistence Methods 158 /// <summary> 159 /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>. 160 /// </summary> 161 /// <remarks>The state(s) are saved as child node with the tag <c>State</c>, each state separaated with 162 /// a semicolon. Also the elements <c>p</c> and the <c>init</c> flag are saved as child nodes with 163 /// tag names <c>P</c> and <c>Init</c> respectively.</remarks> 164 /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param> 165 /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param> 166 /// <param name="persistedObjects">A dictionary of all already persisted objects. (Needed to avoid cycles.)</param> 167 /// <returns>The saved <see cref="XmlNode"/>.</returns> 109 168 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) { 110 169 XmlNode node = base.GetXmlNode(name, document, persistedObjects); … … 130 189 return node; 131 190 } 191 /// <summary> 192 /// Loads the persisted random number generator from the specified <paramref name="node"/>. 193 /// </summary> 194 /// <remarks>The elements of the current instance must be saved in a special way, see 195 /// <see cref="GetXmlNode"/>.</remarks> 196 /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param> 197 /// <param name="restoredObjects">The dictionary of all already restored objects. (Needed to avoid cycles.)</param> 132 198 public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) { 133 199 base.Populate(node, restoredObjects); … … 143 209 144 210 #region Seed Methods 211 /// <summary> 212 /// Initializes current instance with random seed. 213 /// </summary> 214 /// <param name="s">A starting seed.</param> 145 215 public void seed(uint s) { 146 216 state[0] = s & 0xFFFFFFFFU; … … 151 221 p = n; 152 222 } 223 /// <summary> 224 /// Initializes current instance with random seed. 225 /// </summary> 226 /// <param name="array">A starting seed array.</param> 153 227 public void seed(uint[] array) { 154 228 seed(19650218U); -
trunk/sources/HeuristicLab.Random/NormalDistributedRandom.cs
r344 r1153 38 38 private double mu; 39 39 40 /// <summary> 41 /// Gets or sets the value for µ. 42 /// </summary> 40 43 public double Mu { 41 44 get { return mu; } … … 44 47 private double sigma; 45 48 49 /// <summary> 50 /// Gets or sets the value for sigma. 51 /// </summary> 46 52 public double Sigma { 47 53 get { return sigma; } … … 440 446 }; 441 447 448 /// <summary> 449 /// Initializes a new instance of <see cref="NormalDistributedRandom"/> with µ = 0 and sigma = 1 450 /// and a new random number generator. 451 /// </summary> 442 452 public NormalDistributedRandom() { 443 453 this.mu = 0.0; … … 446 456 } 447 457 458 /// <summary> 459 /// Initializes a new instance of <see cref="NormalDistributedRandom"/> with the given parameters. 460 /// <note type="caution"> No CopyConstructor! The random number generator is not copied!</note> 461 /// </summary> 462 /// <param name="uniformRandom">The random number generator.</param> 463 /// <param name="mu">The value for µ.</param> 464 /// <param name="sigma">The value for sigma.</param> 448 465 public NormalDistributedRandom(IRandom uniformRandom, double mu, double sigma) { 449 466 this.mu = mu; … … 454 471 #region IRandom Members 455 472 473 /// <inheritdoc cref="IRandom.Reset()"/> 456 474 public void Reset() { 457 475 uniform.Reset(); 458 476 } 459 477 478 /// <inheritdoc cref="IRandom.Reset(int)"/> 460 479 public void Reset(int seed) { 461 480 uniform.Reset(seed); 462 481 } 463 482 483 /// <summary> 484 /// TODO: The method is not implemented. 485 /// </summary> 486 /// <returns>TODO</returns> 464 487 public int Next() { 465 488 throw new Exception("The method or operation is not implemented."); 466 489 } 467 490 491 /// <summary> 492 /// TODO: The method is not implemented. 493 /// </summary> 494 /// <param name="maxVal">TODO</param> 495 /// <returns>TODO</returns> 468 496 public int Next(int maxVal) { 469 497 throw new Exception("The method or operation is not implemented."); 470 498 } 471 499 500 /// <summary> 501 /// TODO: The method is not implemented. 502 /// </summary> 503 /// <param name="minVal">TODO</param> 504 /// <param name="maxVal">TODO</param> 505 /// <returns>TODO</returns> 472 506 public int Next(int minVal, int maxVal) { 473 507 throw new Exception("The method or operation is not implemented."); 474 508 } 475 509 510 /// <summary> 511 /// Generates a new double random number. 512 /// </summary> 513 /// <returns>A double random number.</returns> 476 514 public double NextDouble() { 477 515 double signFactor = uniform.Next()%2==0?1.0:-1.0; … … 512 550 513 551 #region persistence 552 /// <summary> 553 /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>. 554 /// </summary> 555 /// <remarks>The value of µ and sigma are saved as child nodes with tag names <c>Mu</c> and <c>Sigma</c>, 556 /// also the random number generator is saved as a child node with tag name <c>UniformRandom</c>.</remarks> 557 /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param> 558 /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param> 559 /// <param name="persistedObjects">A dictionary of all already persisted objects. (Needed to avoid cycles.)</param> 560 /// <returns>The saved <see cref="XmlNode"/>.</returns> 514 561 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 515 562 XmlNode node = base.GetXmlNode(name, document, persistedObjects); … … 528 575 } 529 576 577 /// <summary> 578 /// Loads the persisted normally distributed random variable from the specified <paramref name="node"/>. 579 /// </summary> 580 /// <remarks>The elements of the current instance must be saved in a special way, see 581 /// <see cref="GetXmlNode"/>.</remarks> 582 /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param> 583 /// <param name="restoredObjects">The dictionary of all already restored objects. (Needed to avoid cycles.)</param> 530 584 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 531 585 base.Populate(node, restoredObjects); … … 536 590 } 537 591 592 /// <summary> 593 /// Clones the current instance (deep clone). 594 /// </summary> 595 /// <remarks>Deep clone through <see cref="Auxiliary.Clone"/> method of helper class 596 /// <see cref="Auxiliary"/>.</remarks> 597 /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param> 598 /// <returns>The cloned object as <see cref="NormalDistributedRandom"/>.</returns> 538 599 public override object Clone(IDictionary<Guid, object> clonedObjects) { 539 600 NormalDistributedRandom clone = new NormalDistributedRandom((IRandom)Auxiliary.Clone(uniform, clonedObjects), mu, sigma); -
trunk/sources/HeuristicLab.Random/NormalRandomAdder.cs
r763 r1153 28 28 29 29 namespace HeuristicLab.Random { 30 /// <summary> 31 /// Normally distributed random number generator that adds the generated value to the existing value 32 /// in the specified scope. 33 /// </summary> 30 34 public class NormalRandomAdder : OperatorBase { 31 35 private static int MAX_NUMBER_OF_TRIES = 100; 32 36 37 /// <inheritdoc select="summary"/> 33 38 public override string Description { 34 39 get { … … 40 45 } 41 46 47 /// <summary> 48 /// Gets or sets the value for µ. 49 /// </summary> 50 /// <remarks>Gets or sets the variable with the name <c>Mu</c> through the method 51 /// <see cref="OperatorBase.GetVariable"/> of class <see cref="OperatorBase"/>.</remarks> 42 52 public double Mu { 43 53 get { return ((DoubleData)GetVariable("Mu").Value).Data; } 44 54 set { ((DoubleData)GetVariable("Mu").Value).Data = value; } 45 55 } 56 /// <summary> 57 /// Gets or sets the value for sigma. 58 /// </summary> 59 /// <remarks>Gets or sets the variable with the name <c>Sigma</c> through the method 60 /// <see cref="OperatorBase.GetVariable"/> of class <see cref="OperatorBase"/>.</remarks> 46 61 public double Sigma { 47 62 get { return ((DoubleData)GetVariable("Sigma").Value).Data; } … … 49 64 } 50 65 66 /// <summary> 67 /// Initializes a new instance of <see cref="NormalRandomAdder"/> with five variable infos 68 /// (<c>Mu</c>, <c>Sigma</c>, <c>Value</c>, <c>ShakingFactor</c> and <c>Random</c>). 69 /// </summary> 51 70 public NormalRandomAdder() { 52 71 AddVariableInfo(new VariableInfo("Mu", "Parameter mu of the normal distribution", typeof(DoubleData), VariableKind.None)); … … 63 82 } 64 83 84 /// <summary> 85 /// Generates a new normally distributed random number and adds it to the specified value in the 86 /// given <paramref name="scope"/>. 87 /// </summary> 88 /// <param name="scope">The scope where to add the generated random number.</param> 89 /// <returns>null.</returns> 65 90 public override IOperation Apply(IScope scope) { 66 91 IObjectData value = GetVariableValue<IObjectData>("Value", scope, false); … … 87 112 else throw new InvalidOperationException("Can't handle type " + value.GetType().Name); 88 113 } 114 /// <summary> 115 /// Generates a new double random number and adds it to the value of 116 /// the given <paramref name="data"/>. 117 /// </summary> 118 /// <param name="data">The double object where to add the random number.</param> 119 /// <param name="normal">The continuous, normally distributed random variable.</param> 89 120 public void AddNormal(DoubleData data, NormalDistributedRandom normal) { 90 121 data.Data += normal.NextDouble(); 91 122 } 92 123 124 /// <summary> 125 /// Generates a new double random number and adds it to the value of the given <paramref name="data"/> 126 /// checking its constraints. 127 /// </summary> 128 /// <exception cref="InvalidProgramException">Thrown when with the current settings no valid value 129 /// could be found.</exception> 130 /// <param name="data">The double object where to add the random number and whose constraints 131 /// to fulfill.</param> 132 /// <param name="normal">The continuous, normally distributed random variable.</param> 93 133 public void AddNormal(ConstrainedDoubleData data, NormalDistributedRandom normal) { 94 134 for (int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) { … … 104 144 } 105 145 146 /// <summary> 147 /// Generates a new int random number and adds it to value of the given <paramref name="data"/>. 148 /// </summary> 149 /// <param name="data">The int object where to add the random number.</param> 150 /// <param name="normal">The continuous, normally distributed random variable.</param> 106 151 public void AddNormal(IntData data, NormalDistributedRandom normal) { 107 152 data.Data = (int)Math.Round(data.Data + normal.NextDouble()); 108 153 } 109 154 155 /// <summary> 156 /// Generates a new int random number and adds it to the value of the given <paramref name="data"/> 157 /// checking its constraints. 158 /// </summary> 159 /// <exception cref="InvalidProgramException">Thrown when with the current settings no valid value 160 /// could be found.</exception> 161 /// <param name="data">The int object where to add the generated value and whose contraints to check.</param> 162 /// <param name="normal">The continuous, normally distributed random variable.</param> 110 163 public void AddNormal(ConstrainedIntData data, NormalDistributedRandom normal) { 111 164 for (int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) { -
trunk/sources/HeuristicLab.Random/NormalRandomizer.cs
r763 r1153 28 28 29 29 namespace HeuristicLab.Random { 30 /// <summary> 31 /// Normally distributed random number generator. 32 /// </summary> 30 33 public class NormalRandomizer : OperatorBase { 31 34 private static int MAX_NUMBER_OF_TRIES = 100; 32 35 36 /// <inheritdoc select="summary"/> 33 37 public override string Description { 34 38 get { return "Initializes the value of variable 'Value' to a random value normally distributed with 'Mu' and 'Sigma'."; } 35 39 } 36 40 41 /// <summary> 42 /// Gets or sets the value for µ. 43 /// </summary> 44 /// <remarks>Gets or sets the variable with the name <c>Mu</c> through the method 45 /// <see cref="OperatorBase.GetVariable"/> of class <see cref="OperatorBase"/>.</remarks> 37 46 public double Mu { 38 47 get { return ((DoubleData)GetVariable("Mu").Value).Data; } 39 48 set { ((DoubleData)GetVariable("Mu").Value).Data = value; } 40 49 } 50 /// <summary> 51 /// Gets or sets the value for sigma. 52 /// </summary> 53 /// <remarks>Gets or sets the variable with the name <c>Sigma</c> through the method 54 /// <see cref="OperatorBase.GetVariable"/> of class <see cref="OperatorBase"/>.</remarks> 41 55 public double Sigma { 42 56 get { return ((DoubleData)GetVariable("Sigma").Value).Data; } … … 44 58 } 45 59 60 /// <summary> 61 /// Initializes a new instance of <see cref="NormalRandomizer"/> with four variable infos 62 /// (<c>Mu</c>, <c>Sigma</c>, <c>Value</c> and <c>Random</c>). 63 /// </summary> 46 64 public NormalRandomizer() { 47 65 AddVariableInfo(new VariableInfo("Mu", "Parameter mu of the normal distribution", typeof(DoubleData), VariableKind.None)); … … 57 75 } 58 76 77 /// <summary> 78 /// Generates a new normally distributed random variable and assigns it to the specified variable 79 /// in the given <paramref name="scope"/>. 80 /// </summary> 81 /// <param name="scope">The scope where to assign the new random value to.</param> 82 /// <returns>null.</returns> 59 83 public override IOperation Apply(IScope scope) { 60 84 IObjectData value = GetVariableValue<IObjectData>("Value", scope, false); … … 81 105 } 82 106 107 /// <summary> 108 /// Generates a new double random variable based on a continuous, normally distributed random number generator 109 /// <paramref name="normal"/> and checks some contraints. 110 /// </summary> 111 /// <exception cref="InvalidOperationException">Thrown when with the given settings no valid value in 112 /// 100 tries could be found. 113 /// </exception> 114 /// <param name="data">The double object where to assign the new number to and whose constraints 115 /// must be fulfilled.</param> 116 /// <param name="normal">The continuous, normally distributed random variable.</param> 83 117 public void RandomizeNormal(ConstrainedDoubleData data, NormalDistributedRandom normal) { 84 118 for (int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) { … … 94 128 } 95 129 130 /// <summary> 131 /// Generates a new int random variable based on a continuous, normally distributed random number 132 /// generator <paramref name="normal"/> and checks some constraints. 133 /// </summary> 134 /// <exception cref="InvalidOperationException">Thrown when with the given settings no valid 135 /// value could be found.</exception> 136 /// <param name="data">The int object where to assign the new value to and whose constraints must 137 /// be fulfilled.</param> 138 /// <param name="normal">The continuous, normally distributed random variable.</param> 96 139 public void RandomizeNormal(ConstrainedIntData data, NormalDistributedRandom normal) { 97 140 for (int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) { 98 141 double r = normal.NextDouble(); 99 if (data.TrySetData((int)Math.Round(r))) // since r is a continuous normally distributed random variable rounding should be OK142 if (data.TrySetData((int)Math.Round(r))) // since r is a continuous, normally distributed random variable rounding should be OK 100 143 return; 101 144 } … … 103 146 } 104 147 148 /// <summary> 149 /// Generates a new double random number based on a continuous, normally distributed random number 150 /// generator <paramref name="normal"/>. 151 /// </summary> 152 /// <param name="data">The double object where to assign the new value to.</param> 153 /// <param name="normal">The continuous, normally distributed random variable.</param> 105 154 public void RandomizeNormal(DoubleData data, NormalDistributedRandom normal) { 106 155 data.Data = normal.NextDouble(); 107 156 } 108 157 158 /// <summary> 159 /// Generates a new int random number based on a continuous, normally distributed random number 160 /// generator <paramref name="normal"/>. 161 /// </summary> 162 /// <param name="data">The int object where to assign the new value to.</param> 163 /// <param name="normal">The continuous, normally distributed random variable.</param> 109 164 public void RandomizeNormal(IntData data, NormalDistributedRandom normal) { 110 165 data.Data = (int)Math.Round(normal.NextDouble()); -
trunk/sources/HeuristicLab.Random/RandomInjector.cs
r77 r1153 29 29 30 30 namespace HeuristicLab.Random { 31 /// <summary> 32 /// Injects a random variable in a given scope. 33 /// </summary> 31 34 public class RandomInjector : OperatorBase { 35 /// <inheritdoc select="summary"/> 32 36 public override string Description { 33 37 get { return @"TODO\r\nOperator description still missing ..."; } 34 38 } 35 39 40 /// <summary> 41 /// Initializes a new instance of <see cref="RandomInjector"/> with three variable infos 42 /// (<c>SetSeedRandomly</c>, <c>Seed</c> and <c>Random</c>.) 43 /// </summary> 36 44 public RandomInjector() 37 45 : base() { … … 48 56 } 49 57 58 /// <summary> 59 /// Injects a new random variable in the given <paramref name="scope"/> . 60 /// </summary> 61 /// <param name="scope">The scope where to inject the variable.</param> 62 /// <returns>null.</returns> 50 63 public override IOperation Apply(IScope scope) { 51 64 bool setRandomly = GetVariableValue<BoolData>("SetSeedRandomly", scope, true).Data; -
trunk/sources/HeuristicLab.Random/UniformRandomAdder.cs
r763 r1153 28 28 29 29 namespace HeuristicLab.Random { 30 /// <summary> 31 /// Uniformly distributed random number generator that adds the generated value to the existing one. 32 /// </summary> 30 33 public class UniformRandomAdder : OperatorBase { 31 34 32 35 private static int MAX_NUMBER_OF_TRIES = 100; 33 36 37 /// <inheritdoc select="summary"/> 34 38 public override string Description { 35 39 get { … … 43 47 } 44 48 49 /// <summary> 50 /// Initializes a new instance of <see cref="UniformRandomAdder"/> with five variable infos 51 /// (<c>Value</c>, <c>ShakingFactor</c>, <c>Random</c>, <c>Min</c> and <c>Max</c>), having an interval 52 /// of -1.0 to 1.0. 53 /// </summary> 45 54 public UniformRandomAdder() { 46 55 AddVariableInfo(new VariableInfo("Value", "The value to manipulate (type is one of: IntData, ConstrainedIntData, DoubleData, ConstrainedDoubleData)", typeof(IObjectData), VariableKind.In)); … … 56 65 } 57 66 67 /// <summary> 68 /// Generates a new uniformly distributed random number and adds it to the value in the given 69 /// <paramref name="scope"/>. 70 /// </summary> 71 /// <param name="scope">The current scope where to add the generated random number.</param> 72 /// <returns>null.</returns> 58 73 public override IOperation Apply(IScope scope) { 59 74 IObjectData value = GetVariableValue<IObjectData>("Value", scope, false); … … 85 100 } 86 101 87 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> 88 112 public void AddUniform(ConstrainedDoubleData data, MersenneTwister mt, double min, double max) { 89 113 for (int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) { … … 99 123 } 100 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> 101 135 public void AddUniform(ConstrainedIntData data, MersenneTwister mt, double min, double max) { 102 136 for (int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) { … … 109 143 } 110 144 145 /// <summary> 146 /// Generates a new double random variable and adds it to the value of 147 /// the given <paramref name="data"/>. 148 /// </summary> 149 /// <param name="data">The double object where to add the random value.</param> 150 /// <param name="mt">The random number generator.</param> 151 /// <param name="min">The left border of the interval in which the next random number has to lie.</param> 152 /// <param name="max">The right border (exclusive) of the interval in which the next random number 153 /// has to lie.</param> 111 154 public void AddUniform(DoubleData data, MersenneTwister mt, double min, double max) { 112 155 data.Data = data.Data + mt.NextDouble() * (max - min) + min; 113 156 } 114 157 158 /// <summary> 159 /// Generates a new int random variable and adds it to the value of the given 160 /// <paramref name="data"/>. 161 /// </summary> 162 /// <param name="data">The int object where to add the random value.</param> 163 /// <param name="mt">The random number generator.</param> 164 /// <param name="min">The left border of the interval in which the next random number has to lie.</param> 165 /// <param name="max">The right border (exclusive) of the interval in which the next random number 166 /// has to lie.</param> 115 167 public void AddUniform(IntData data, MersenneTwister mt, double min, double max) { 116 168 data.Data = (int)Math.Floor(data.Data + mt.NextDouble() * (max - min) + min); -
trunk/sources/HeuristicLab.Random/UniformRandomizer.cs
r763 r1153 28 28 29 29 namespace HeuristicLab.Random { 30 /// <summary> 31 /// Uniformly distributed random number generator. 32 /// </summary> 30 33 public class UniformRandomizer : OperatorBase { 31 34 private static int MAX_NUMBER_OF_TRIES = 100; 35 /// <inheritdoc select="summary"/> 32 36 public override string Description { 33 37 get { return "Initializes the value of variable 'Value' to a random value uniformly distributed between 'Min' and 'Max' (exclusive)"; } 34 38 } 35 39 40 /// <summary> 41 /// Gets or sets the maximum value of the random number generator (exclusive). 42 /// </summary> 43 /// <remarks>Gets or sets the variable with name <c>Max</c> through the 44 /// <see cref="OperatorBase.GetVariable"/> method of class <see cref="OperatorBase"/>.</remarks> 36 45 public double Max { 37 46 get { return ((DoubleData)GetVariable("Max").Value).Data; } 38 47 set { ((DoubleData)GetVariable("Max").Value).Data = value; } 39 48 } 49 /// <summary> 50 /// Gets or sets the minimum value of the random number generator. 51 /// </summary> 52 /// <remarks>Gets or sets the variable with name <c>Min</c> through the 53 /// <see cref="OperatorBase.GetVariable"/> method of class <see cref="OperatorBase"/>.</remarks> 40 54 public double Min { 41 55 get { return ((DoubleData)GetVariable("Min").Value).Data; } … … 43 57 } 44 58 59 /// <summary> 60 /// Initializes a new instance of <see cref="UniformRandomizer"/> with four variable infos 61 /// (<c>Value</c>, <c>Random</c>, <c>Max</c> and <c>Min</c>), being a random number generator 62 /// between 0.0 and 1.0. 63 /// </summary> 45 64 public UniformRandomizer() { 46 65 AddVariableInfo(new VariableInfo("Value", "The value to manipulate (type is one of: IntData, ConstrainedIntData, DoubleData, ConstrainedDoubleData)", typeof(IObjectData), VariableKind.In)); … … 55 74 } 56 75 76 /// <summary> 77 /// Generates a new uniformly distributed random variable. 78 /// </summary> 79 /// <param name="scope">The scope where to apply the random number generator.</param> 80 /// <returns>null.</returns> 57 81 public override IOperation Apply(IScope scope) { 58 82 IObjectData value = GetVariableValue<IObjectData>("Value", scope, false); … … 65 89 } 66 90 91 /// <summary> 92 /// Generates a new random number depending on the type of the <paramref name="value"/>. 93 /// </summary> 94 /// <exception cref="ArgumentException">Thrown when an unhandleable type appears.</exception> 95 /// <param name="value">The object whose data should be a new randomly generated number.</param> 96 /// <param name="mt">The MersenneTwister to generate a new random number.</param> 97 /// <param name="min">The left border of the interval in which the next random number has to lie.</param> 98 /// <param name="max">The right border (exclusive) of the interval in which the next random number 99 /// has to lie.</param> 67 100 private void RandomizeUniform(IObjectData value, MersenneTwister mt, double min, double max) { 68 101 // Dispatch manually based on dynamic type, … … 79 112 } 80 113 81 114 /// <summary> 115 /// Generates a new double random number. 116 /// </summary> 117 /// <param name="data">The double object which the new value is assigned to.</param> 118 /// <param name="mt">The random number generator.</param> 119 /// <param name="min">The left border of the interval in which the next random number has to lie.</param> 120 /// <param name="max">The right border (exclusive) of the interval in which the next random number 121 /// has to lie.</param> 82 122 public void RandomizeUniform(DoubleData data, MersenneTwister mt, double min, double max) { 83 123 data.Data = mt.NextDouble() * (max - min) + min; 84 124 } 85 125 126 /// <summary> 127 /// Generates a new int random number. 128 /// </summary> 129 /// <param name="data">The int object which the new value is assigned to.</param> 130 /// <param name="mt">The random number generator.</param> 131 /// <param name="min">The left border of the interval in which the next random number has to lie.</param> 132 /// <param name="max">The right border (exclusive) of the interval in which the next random number 133 /// has to lie.</param> 86 134 public void RandomizeUniform(IntData data, MersenneTwister mt, double min, double max) { 87 135 data.Data = (int)Math.Floor(mt.NextDouble() * (max - min) + min); 88 136 } 89 137 138 /// <summary> 139 /// Generates a new double random number, being restricted to some constraints. 140 /// </summary> 141 /// <exception cref="InvalidOperationException">Thrown when no valid value could be found.</exception> 142 /// <param name="data">The double object which the new value is assigned to and whose constraints 143 /// must be fulfilled.</param> 144 /// <param name="mt">The random number generator.</param> 145 /// <param name="min">The left border of the interval in which the next random number has to lie.</param> 146 /// <param name="max">The right border (exclusive) of the interval in which the next random number 147 /// has to lie.</param> 90 148 public void RandomizeUniform(ConstrainedDoubleData data, MersenneTwister mt, double min, double max) { 91 149 for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) { … … 100 158 throw new InvalidOperationException("Couldn't find a valid value"); 101 159 } 102 160 /// <summary> 161 /// Generates a new int random number, being restricted to some constraints. 162 /// </summary> 163 /// <exception cref="InvalidOperationException">Thrown when no valid value could be found.</exception> 164 /// <param name="data">The int object which the new value is assigned to and whose constraints 165 /// must be fulfilled.</param> 166 /// <param name="mt">The random number generator.</param> 167 /// <param name="min">The left border of the interval in which the next random number has to lie.</param> 168 /// <param name="max">The right border (exclusive) of the interval in which the next random number 169 /// has to lie.</param> 103 170 public void RandomizeUniform(ConstrainedIntData data, MersenneTwister mt, double min, double max) { 104 171 for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) { -
trunk/sources/HeuristicLab.SGA/HeuristicLabSGAPlugin.cs
r582 r1153 26 26 27 27 namespace HeuristicLab.SGA { 28 /// <summary> 29 /// Plugin class for HeuristicLab.SGA plugin. 30 /// </summary> 28 31 [ClassInfo(Name = "HeuristicLab.SGA-3.2")] 29 32 [PluginFile(Filename = "HeuristicLab.SGA-3.2.dll", Filetype = PluginFileType.Assembly)] -
trunk/sources/HeuristicLab.SGA/SGA.cs
r65 r1153 33 33 34 34 namespace HeuristicLab.SGA { 35 /// <summary> 36 /// Class for the heuristic optimization technique "simple genetic algorithm". 37 /// </summary> 35 38 public class SGA : ItemBase, IEditable { 36 39 #region Create Operators 40 /// <summary> 41 /// Creates operators for the current instance. 42 /// </summary> 43 /// <param name="engine">The engine where to add the operators.</param> 37 44 public static void Create(IEngine engine) { 38 45 engine.OperatorGraph.Clear(); … … 355 362 #region Properties 356 363 private IEngine myEngine; 364 /// <summary> 365 /// Gets the engine of the current instance. 366 /// </summary> 357 367 public IEngine Engine { 358 368 get { return myEngine; } 359 369 } 360 370 private BoolData mySetSeedRandomly; 371 /// <summary> 372 /// Gets or sets the flag whether to set the seed randomly or not. 373 /// </summary> 361 374 public bool SetSeedRandomly { 362 375 get { return mySetSeedRandomly.Data; } … … 364 377 } 365 378 private IntData mySeed; 379 /// <summary> 380 /// Gets or sets the value of the seed of the current instance. 381 /// </summary> 366 382 public int Seed { 367 383 get { return mySeed.Data; } … … 370 386 private IntData myPopulationSize; 371 387 private IntData myParents; 388 /// <summary> 389 /// Gets or sets the population size of the current instance. 390 /// </summary> 391 /// <remarks>The number of parents is set to two times the population size.</remarks> 372 392 public int PopulationSize { 373 393 get { return myPopulationSize.Data; } … … 378 398 } 379 399 private IntData myMaximumGenerations; 400 /// <summary> 401 /// Gets or sets the number of maximum generations. 402 /// </summary> 380 403 public int MaximumGenerations { 381 404 get { return myMaximumGenerations.Data; } … … 383 406 } 384 407 private DoubleData myMutationRate; 408 /// <summary> 409 /// Gets or sets the mutation rate of the current instance. 410 /// </summary> 385 411 public double MutationRate { 386 412 get { return myMutationRate.Data; } … … 388 414 } 389 415 private IntData myElites; 416 /// <summary> 417 /// Gets or sets the elites of the current instance. 418 /// </summary> 390 419 public int Elites { 391 420 get { return myElites.Data; } … … 394 423 private CombinedOperator mySGA; 395 424 private IOperator myVariableInjection; 425 /// <summary> 426 /// Gets or sets the problem injector of the current instance. 427 /// </summary> 396 428 public IOperator ProblemInjector { 397 429 get { return myVariableInjection.SubOperators[0]; } … … 404 436 } 405 437 private IOperator myPopulationInitialization; 438 /// <summary> 439 /// Gets or sets the solution generator of the current instance. 440 /// </summary> 406 441 public IOperator SolutionGenerator { 407 442 get { return myPopulationInitialization.SubOperators[0]; } … … 413 448 } 414 449 } 450 /// <summary> 451 /// Gets or sets the evaluator of the current instance. 452 /// </summary> 415 453 public IOperator Evaluator { 416 454 get { return myPopulationInitialization.SubOperators[1]; } … … 424 462 } 425 463 private IOperator mySGAMain; 464 /// <summary> 465 /// Gets or sets the selection operator of the current instance. 466 /// </summary> 426 467 public IOperator Selector { 427 468 get { return mySGAMain.SubOperators[0]; } … … 433 474 } 434 475 } 476 /// <summary> 477 /// Gets or sets the crossover operator of the current instance. 478 /// </summary> 435 479 public IOperator Crossover { 436 480 get { return mySGAMain.SubOperators[1]; } … … 442 486 } 443 487 } 488 /// <summary> 489 /// Gets or sets the mutation operator of the current instance. 490 /// </summary> 444 491 public IOperator Mutator { 445 492 get { return mySGAMain.SubOperators[2]; } … … 453 500 #endregion 454 501 502 /// <summary> 503 /// Initializes a new instance of <see cref="SGA"/>. 504 /// </summary> 455 505 public SGA() { 456 506 myEngine = new SequentialEngine.SequentialEngine(); … … 459 509 } 460 510 511 /// <summary> 512 /// Creates a new instance of the <see cref="SGAEditor"/> class. 513 /// </summary> 514 /// <returns>The created instance of the <see cref="SGAEditor"/>.</returns> 461 515 public override IView CreateView() { 462 516 return new SGAEditor(this); 463 517 } 518 /// <summary> 519 /// Creates a new instance of the <see cref="SGAEditor"/> class. 520 /// </summary> 521 /// <returns>The created instance of the <see cref="SGAEditor"/>.</returns> 464 522 public virtual IEditor CreateEditor() { 465 523 return new SGAEditor(this); 466 524 } 467 525 526 /// <summary> 527 /// Clones the current instance (deep clone). 528 /// </summary> 529 /// <remarks>Deep clone through <see cref="Auxiliary.Clone"/> method of helper class 530 /// <see cref="Auxiliary"/>.</remarks> 531 /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param> 532 /// <returns>The cloned object as <see cref="SGA"/>.</returns> 468 533 public override object Clone(IDictionary<Guid, object> clonedObjects) { 469 534 SGA clone = new SGA(); … … 506 571 507 572 #region Persistence Methods 573 /// <summary> 574 /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>. 575 /// </summary> 576 /// <remarks>The engine of the current instance is saved as a child node with the tag name 577 /// <c>Engine</c>.</remarks> 578 /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param> 579 /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param> 580 /// <param name="persistedObjects">A dictionary of all already persisted objects. (Needed to avoid cycles.)</param> 581 /// <returns>The saved <see cref="XmlNode"/>.</returns> 508 582 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) { 509 583 XmlNode node = base.GetXmlNode(name, document, persistedObjects); … … 511 585 return node; 512 586 } 587 /// <summary> 588 /// Loads the persisted instance from the specified <paramref name="node"/>. 589 /// </summary> 590 /// <remarks>The elements of the current instance must be saved in a special way, see 591 /// <see cref="GetXmlNode"/>.</remarks> 592 /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param> 593 /// <param name="restoredObjects">The dictionary of all already restored objects. (Needed to avoid cycles.)</param> 513 594 public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) { 514 595 base.Populate(node, restoredObjects); -
trunk/sources/HeuristicLab.SGA/SGAEditor.cs
r65 r1153 31 31 32 32 namespace HeuristicLab.SGA { 33 /// <summary> 34 /// Visual representation of the <see cref="SGA"/> class. 35 /// </summary> 33 36 public partial class SGAEditor : EditorBase { 34 37 private ChooseOperatorDialog chooseOperatorDialog; 35 38 39 /// <summary> 40 /// Gets or sets the <see cref="SGA"/> item to represent visually. 41 /// </summary> 42 /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="EditorBase"/>. 43 /// No own data storage present!</remarks> 36 44 public SGA SGA { 37 45 get { return (SGA)Item; } … … 39 47 } 40 48 49 /// <summary> 50 /// Initializes a new instance of <see cref="SGAEditor"/>. 51 /// </summary> 41 52 public SGAEditor() { 42 53 InitializeComponent(); 43 54 } 55 /// <summary> 56 /// Initializes a new instance of <see cref="SGAEditor"/> with the given <paramref name="sga"/>. 57 /// </summary> 58 /// <param name="sga">The simple genetic algorithm to represent visually.</param> 44 59 public SGAEditor(SGA sga) 45 60 : this() { … … 47 62 } 48 63 64 /// <summary> 65 /// Removes the eventhandlers from the underlying <see cref="IEngine"/> of the <see cref="SGA"/>. 66 /// </summary> 67 /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="EditorBase"/>.</remarks> 49 68 protected override void RemoveItemEvents() { 50 69 SGA.Engine.ExceptionOccurred -= new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred); … … 53 72 base.RemoveItemEvents(); 54 73 } 74 /// <summary> 75 /// Adds eventhandlers to the underlying <see cref="IEngine"/> of the <see cref="SGA"/>. 76 /// </summary> 77 /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="EditorBase"/>.</remarks> 55 78 protected override void AddItemEvents() { 56 79 base.AddItemEvents(); … … 61 84 } 62 85 86 /// <summary> 87 /// Updates all controls with the latest data of the model. 88 /// </summary> 89 /// <remarks>Calls <see cref="EditorBase.UpdateControls"/> of base class <see cref="EditorBase"/>.</remarks> 63 90 protected override void UpdateControls() { 64 91 base.UpdateControls(); -
trunk/sources/HeuristicLab.Selection.OffspringSelection/HeuristicLabSelectionOffspringSelectionPlugin.cs
r582 r1153 26 26 27 27 namespace HeuristicLab.Selection.OffspringSelection { 28 /// <summary> 29 /// Plugin class for HeuristicLab.Selection.OffspringSelection plugin. 30 /// </summary> 28 31 [ClassInfo(Name = "HeuristicLab.Selection.OffspringSelection-3.2")] 29 32 [PluginFile(Filename = "HeuristicLab.Selection.OffspringSelection-3.2.dll", Filetype = PluginFileType.Assembly)] -
trunk/sources/HeuristicLab.Selection.OffspringSelection/OffspringAnalyzer.cs
r806 r1153 27 27 28 28 namespace HeuristicLab.Selection.OffspringSelection { 29 /// <summary> 30 /// Analyzes the offspring in a given scope whether it is successful or not. 31 /// </summary> 29 32 public class OffspringAnalyzer : OperatorBase { 33 /// <inheritdoc select="summary"/> 30 34 public override string Description { 31 35 get { return @"TODO\r\nOperator description still missing ..."; } 32 36 } 33 37 38 /// <summary> 39 /// Initializes a new instance of <see cref="OffspringAnalyzer"/> with six variable infos 40 /// (<c>Maximization</c>, <c>Quality</c>, <c>ParentQualities</c>, <c>SuccessfulChild</c>, 41 /// <c>ComparisonFactor</c> and <c>ParentsCount</c>). 42 /// </summary> 34 43 public OffspringAnalyzer() { 35 44 AddVariableInfo(new VariableInfo("Maximization", "Problem is a maximization problem", typeof(BoolData), VariableKind.In)); … … 48 57 } 49 58 59 /// <summary> 60 /// Analyzes the offspring in the given scope whether the children are successful or not. 61 /// </summary> 62 /// <exception cref="InvalidOperationException">Thrown when <c>ParentsCount</c> smaller than 1.</exception> 63 /// <exception cref="InvalidOperationException">Thrown when the number of children is not constant or 64 /// smaller than 1.</exception> 65 /// <param name="scope">The scope whose offspring should be analyzed.</param> 66 /// <returns>The next operation or null.</returns> 50 67 public override IOperation Apply(IScope scope) { 51 68 bool maximize = GetVariableValue<BoolData>("Maximization", scope, true).Data; -
trunk/sources/HeuristicLab.Selection.OffspringSelection/OffspringSelector.cs
r301 r1153 27 27 28 28 namespace HeuristicLab.Selection.OffspringSelection { 29 /// <summary> 30 /// Selects successful and also according to the selection pressure some unsuccessful children. 31 /// </summary> 29 32 public class OffspringSelector : OperatorBase { 33 /// <inheritdoc select="summary"/> 30 34 public override string Description { 31 35 get { return @"TODO\r\nOperator description still missing ..."; } 32 36 } 33 37 38 /// <summary> 39 /// Initializes a new instance of <see cref="OffspringSelector"/> with seven variable infos 40 /// (<c>SuccessfulChild</c>, <c>SelectionPressureLimit</c>, <c>SuccessRatioLimit</c>, 41 /// <c>SelectionPressure</c>, <c>SuccessRatio</c>, <c>GoodChildren</c> and <c>BadChildren</c>). 42 /// </summary> 34 43 public OffspringSelector() { 35 44 AddVariableInfo(new VariableInfo("SuccessfulChild", "True if the child was successful", typeof(BoolData), VariableKind.In)); … … 42 51 } 43 52 53 /// <summary> 54 /// Selects successful children and also some bad ones depending on the selection 55 /// pressure out of a population. 56 /// </summary> 57 /// <param name="scope">The current scope of the parents and the children.</param> 58 /// <returns>The next operation or null.</returns> 44 59 public override IOperation Apply(IScope scope) { 45 60 double selectionPressureLimit = GetVariableValue<DoubleData>("SelectionPressureLimit", scope, true).Data;
Note: See TracChangeset
for help on using the changeset viewer.