Changeset 469 for trunk/sources/HeuristicLab.Random/UniformRandomAdder.cs
- Timestamp:
- 08/08/08 19:56:19 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Random/UniformRandomAdder.cs
r2 r469 43 43 public UniformRandomAdder() { 44 44 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)); 46 46 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)); 48 48 GetVariableInfo("Min").Local = true; 49 49 AddVariable(new Variable("Min", new DoubleData(-1.0))); 50 50 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)); 52 52 GetVariableInfo("Max").Local = true; 53 53 AddVariable(new Variable("Max", new DoubleData(1.0))); … … 84 84 85 85 public override void Visit(ConstrainedDoubleData data) { 86 87 86 for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) { 88 89 87 double newValue = data.Data + mt.NextDouble() * (max - min) + min; 90 91 88 if(IsIntegerConstrained(data)) { 92 newValue = Math. Round(newValue);89 newValue = Math.Floor(newValue); 93 90 } 94 95 91 if(data.TrySetData(newValue)) { 96 92 return; 97 93 } 98 94 } 99 100 95 throw new InvalidProgramException("Couldn't find a valid value"); 101 96 } … … 103 98 public override void Visit(ConstrainedIntData data) { 104 99 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); 107 101 if(data.TrySetData(newValue)) { 108 102 return; … … 117 111 118 112 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); 120 114 } 121 115 private bool IsIntegerConstrained(ConstrainedDoubleData data) {
Note: See TracChangeset
for help on using the changeset viewer.