Changeset 469 for trunk/sources
- Timestamp:
- 08/08/08 19:56:19 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Random
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Random/NormalRandomAdder.cs
r426 r469 88 88 89 89 public override void Visit(ConstrainedDoubleData data) { 90 91 90 for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) { 92 91 double newValue = data.Data + normal.NextDouble(); 93 94 92 if(IsIntegerConstrained(data)) { 95 93 newValue = Math.Round(newValue); … … 99 97 } 100 98 } 101 102 99 throw new InvalidProgramException("Coudn't find a valid value"); 103 100 } … … 112 109 return; 113 110 } 114 115 111 throw new InvalidProgramException("Couldn't find a valid value."); 116 112 } -
trunk/sources/HeuristicLab.Random/NormalRandomizer.cs
r426 r469 79 79 for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) { 80 80 double r = normal.NextDouble(); 81 82 81 if(IsIntegerConstrained(data)) { 83 82 r = Math.Round(r); 84 83 } 85 86 84 if(data.TrySetData(r)) { 87 85 return; … … 92 90 93 91 public override void Visit(ConstrainedIntData data) { 94 95 92 for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) { 96 93 double r = normal.NextDouble(); 97 if(data.TrySetData((int)Math.Round(r))) 94 if(data.TrySetData((int)Math.Round(r))) // since r is a continuous normally distributed random variable rounding should be OK 98 95 return; 99 96 } 100 101 97 throw new InvalidProgramException("Couldn't find a valid value"); 102 98 } -
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) { -
trunk/sources/HeuristicLab.Random/UniformRandomizer.cs
r426 r469 46 46 AddVariableInfo(new VariableInfo("Value", "The value to manipulate (type is one of: IntData, ConstrainedIntData, DoubleData, ConstrainedDoubleData)", typeof(IObjectData), VariableKind.In)); 47 47 AddVariableInfo(new VariableInfo("Random", "The random generator to use", typeof(MersenneTwister), VariableKind.In)); 48 AddVariableInfo(new VariableInfo("Min", "Lower bound of the uniform distribution ", typeof(DoubleData), VariableKind.None));48 AddVariableInfo(new VariableInfo("Min", "Lower bound of the uniform distribution (inclusive)", typeof(DoubleData), VariableKind.None)); 49 49 GetVariableInfo("Min").Local = true; 50 50 AddVariable(new Variable("Min", new DoubleData(0.0))); 51 51 52 AddVariableInfo(new VariableInfo("Max", "Upper bound of the uniform distribution ", typeof(DoubleData), VariableKind.None));52 AddVariableInfo(new VariableInfo("Max", "Upper bound of the uniform distribution (exclusive)", typeof(DoubleData), VariableKind.None)); 53 53 GetVariableInfo("Max").Local = true; 54 54 AddVariable(new Variable("Max", new DoubleData(1.0))); … … 82 82 83 83 public override void Visit(IntData data) { 84 data.Data = (int)Math. Round(mt.NextDouble() * (max - min) + min);84 data.Data = (int)Math.Floor(mt.NextDouble() * (max - min) + min); 85 85 } 86 86 87 87 public override void Visit(ConstrainedDoubleData data) { 88 89 88 for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) { 90 89 double r = mt.NextDouble() * (max - min) + min; 91 92 90 if(IsIntegerConstrained(data)) { 93 r = Math. Round(r);91 r = Math.Floor(r); 94 92 } 95 96 93 if(data.TrySetData(r)) { 97 94 return; 98 95 } 99 96 } 100 101 97 throw new InvalidProgramException("Couldn't find a valid value"); 102 98 } 103 99 104 100 public override void Visit(ConstrainedIntData data) { 105 106 101 for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) { 107 int r = (int)Math.Round(mt.NextDouble() * (max - min) + min); 108 102 int r = (int)Math.Floor(mt.NextDouble() * (max - min) + min); 109 103 if(data.TrySetData(r)) { 110 104 return;
Note: See TracChangeset
for help on using the changeset viewer.