Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/RangeConstraints/PercentValueRange.cs @ 4997

Last change on this file since 4997 was 4997, checked in by cneumuel, 13 years ago

#1215 worked on metaoptimization

File size: 1.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Data;
6using HeuristicLab.Common;
7
8namespace HeuristicLab.Problems.MetaOptimization {
9  public class PercentValueRange : Range<PercentValue> {
10
11    public PercentValueRange(PercentValue lowerBound, PercentValue upperBound, PercentValue stepSize) : base(lowerBound, upperBound, stepSize) { }
12    public PercentValueRange() { }
13    protected PercentValueRange(PercentValueRange original, Cloner cloner) : base(original, cloner) { }
14    public override IDeepCloneable Clone(Cloner cloner) {
15      return new PercentValueRange(this, cloner);
16    }
17
18    public override PercentValue GetRandomValue() {
19      Random rand = new Random(); // todo: use common random
20      double val;
21      do {
22        val = Math.Round((rand.NextDouble() * (UpperBound.Value - LowerBound.Value) + LowerBound.Value) / StepSize.Value, 0) * StepSize.Value;
23      } while (val < LowerBound.Value || val > UpperBound.Value);
24      return new PercentValue(val);
25    }
26  }
27}
Note: See TracBrowser for help on using the repository browser.