Changeset 12293
- Timestamp:
- 04/07/15 15:38:56 (10 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/Dialogs/DefineArithmeticProgressionDialog.cs
r12012 r12293 23 23 using System.ComponentModel; 24 24 using System.Globalization; 25 using System.Linq;26 25 using System.Windows.Forms; 27 26 using HeuristicLab.Common; … … 31 30 private bool allowOnlyInteger; 32 31 33 public d oubleMinimum { get; private set; }34 public d oubleMaximum { get; private set; }35 public d oubleStep { get; private set; }32 public decimal Minimum { get; private set; } 33 public decimal Maximum { get; private set; } 34 public decimal Step { get; private set; } 36 35 37 public IEnumerable<d ouble> Values {38 get { return EnumerateProgression().Reverse(); }36 public IEnumerable<decimal> Values { 37 get { return SequenceGenerator.GenerateSteps(Minimum, Maximum, Step, includeEnd: true); } 39 38 } 40 39 … … 48 47 this.allowOnlyInteger = allowOnlyInteger; 49 48 } 50 public DefineArithmeticProgressionDialog(bool allowOnlyInteger, d ouble minimum, double maximum, doublestep)49 public DefineArithmeticProgressionDialog(bool allowOnlyInteger, decimal minimum, decimal maximum, decimal step) 51 50 : this(allowOnlyInteger) { 52 51 Minimum = minimum; … … 63 62 private void textBox_Validating(object sender, CancelEventArgs e) { 64 63 var textBox = (TextBox)sender; 65 d oublevalue = 0;64 decimal value = 0; 66 65 if (allowOnlyInteger) { 67 66 int intValue; … … 75 74 } 76 75 } else { 77 if (!d ouble.TryParse(textBox.Text, NumberStyles.Float, CultureInfo.CurrentCulture.NumberFormat, out value)) {76 if (!decimal.TryParse(textBox.Text, NumberStyles.Float, CultureInfo.CurrentCulture.NumberFormat, out value)) { 78 77 errorProvider.SetError(textBox, "Please enter a valid double value."); 79 78 e.Cancel = true; … … 90 89 return Minimum <= Maximum && Step >= 0; 91 90 } 92 93 private IEnumerable<double> EnumerateProgression() {94 double value = Maximum;95 bool minimumIncluded = false;96 int i = 1;97 while (value >= Minimum) {98 if (value.IsAlmost(Minimum)) {99 yield return Minimum;100 minimumIncluded = true;101 } else yield return value;102 103 if (Step == 0) break; // a step size of 0 will only output maximum and minimum104 if (allowOnlyInteger) {105 value = (int)Maximum - i * (int)Step;106 } else {107 value = Maximum - i * Step;108 }109 i++;110 }111 if (!minimumIncluded) {112 yield return Minimum;113 }114 }115 91 } 116 92 } -
trunk/sources/HeuristicLab.Optimizer/3.3/CreateExperimentDialog.cs
r12012 r12293 264 264 var parameter = (IValueParameter)generateButton.Tag; 265 265 bool integerOnly = intParameters.ContainsKey(parameter); 266 d oublemin = 0, max = 1, step = 1;266 decimal min = 0, max = 1, step = 1; 267 267 #region Try to calculate some meaningful values 268 268 if (integerOnly) { … … 276 276 int len = doubleParameters[parameter].Length; 277 277 if (len > 0) { 278 min = doubleParameters[parameter].Min();279 max = doubleParameters[parameter].Max();280 step = len >= 2 ? Math.Abs(( doubleParameters[parameter][len - 1] - doubleParameters[parameter][len - 2])) : 1;278 min = (decimal)doubleParameters[parameter].Min(); 279 max = (decimal)doubleParameters[parameter].Max(); 280 step = len >= 2 ? Math.Abs(((decimal)doubleParameters[parameter][len - 1] - (decimal)doubleParameters[parameter][len - 2])) : 1m; 281 281 } 282 282 } … … 292 292 } else { 293 293 doubleParameters[parameter].Reset -= new EventHandler(ValuesArray_Reset); 294 doubleParameters[parameter] = new DoubleArray(values. ToArray());294 doubleParameters[parameter] = new DoubleArray(values.Select(x => (double)x).ToArray()); 295 295 doubleParameters[parameter].Reset += new EventHandler(ValuesArray_Reset); 296 296 stringConvertibleArrayView.Content = doubleParameters[parameter];
Note: See TracChangeset
for help on using the changeset viewer.