Changeset 16613
- Timestamp:
- 02/17/19 22:56:09 (6 years ago)
- Location:
- branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3/Analyzers/BestMovingPeaksBenchmarkSolutionAnalyzer.cs
r16611 r16613 102 102 else i = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index; 103 103 104 if (bestKnownQuality == null ||105 max && qualities[i].Value > bestKnownQuality.Value106 || !max && qualities[i].Value < bestKnownQuality.Value) {107 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);108 BestKnownSolutionParameter.ActualValue = (RealVector)realVectors[i].Clone();109 }110 111 104 RealVector best = (RealVector)realVectors[i].Clone(); 112 105 RealVector bestKnown = (RealVector)BestKnownSolutionParameter.ActualValue.Clone(); -
branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3/MovingPeaksBenchmarkProblem.cs
r16609 r16613 71 71 get { return (FixedValueParameter<IntValue>)Parameters["MovingPeaksRandomSeed"]; } 72 72 } 73 public FixedValueParameter<DoubleValue> MinPeakWidthParameter { 74 get { return (FixedValueParameter<DoubleValue>)Parameters["MinPeakWidth"]; } 75 } 76 public FixedValueParameter<DoubleValue> MaxPeakWidthParameter { 77 get { return (FixedValueParameter<DoubleValue>)Parameters["MaxPeakWidth"]; } 78 } 79 public FixedValueParameter<DoubleValue> MinPeakHeightParameter { 80 get { return (FixedValueParameter<DoubleValue>)Parameters["MinPeakHeight"]; } 81 } 82 public FixedValueParameter<DoubleValue> MaxPeakHeightParameter { 83 get { return (FixedValueParameter<DoubleValue>)Parameters["MaxPeakHeight"]; } 84 } 73 85 public FixedValueParameter<IntValue> PeakMovementIntervalParameter { 74 86 get { return (FixedValueParameter<IntValue>)Parameters["PeakMovementInterval"]; } … … 109 121 public IntValue MovingPeaksRandomSeed { 110 122 get { return MovingPeaksRandomSeedParameter.Value; } 123 } 124 public DoubleValue MinPeakWidth { 125 get { return MinPeakWidthParameter.Value; } 126 } 127 public DoubleValue MaxPeakWidth { 128 get { return MaxPeakWidthParameter.Value; } 129 } 130 public DoubleValue MinPeakHeight { 131 get { return MinPeakHeightParameter.Value; } 132 } 133 public DoubleValue MaxPeakHeight { 134 get { return MaxPeakHeightParameter.Value; } 111 135 } 112 136 public IntValue PeakMovementInterval { … … 140 164 { 09.0, 19.0, 27.0, 67.0, 24.0 }, 141 165 { 66.0, 87.0, 65.0, 19.0, 43.0 }, 142 { 76.0, 32.0, 43.0, 54.0, 65.0 } 166 { 76.0, 32.0, 43.0, 54.0, 65.0 }, 167 { 25.0, 51.0, 17.0, 25.0, 16.0 }, 168 { 19.0, 93.0, 06.0, 35.0, 15.0 }, 169 { 88.0, 44.0, 37.0, 77.0, 74.0 }, 170 { 37.0, 74.0, 55.0, 09.0, 53.0 }, 171 { 42.0, 22.0, 93.0, 84.0, 35.0 } 143 172 }; 144 var defaultWidths = new double[] { 0.1, 0.1, 0.1, 0.1, 0.1};145 var defaultHeights = new double[] { 50.0, 50.0, 50.0, 50.0, 50.0 };173 var defaultWidths = new double[] { -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0 }; 174 var defaultHeights = new double[] { 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0 }; 146 175 var defaultBestKnown = new double[] { 08.0, 64.0, 67.0, 55.0, 04.0 }; 147 176 148 177 Parameters.Add(new ValueParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension.", new DoubleMatrix(defaultBounds))); 149 178 Parameters.Add(new ValueParameter<IntValue>("ProblemSize", "The dimension of the problem.", new IntValue(5))); 150 Parameters.Add(new ValueParameter<IntValue>("Peaks", "The number of peaks.", new IntValue( 5)));179 Parameters.Add(new ValueParameter<IntValue>("Peaks", "The number of peaks.", new IntValue(10))); 151 180 Parameters.Add(new ValueParameter<DoubleMatrix>("InitialPeakLocations", "Initial coordinates of each peaks.", new DoubleMatrix(defaultPeaks))); 152 181 Parameters.Add(new ValueParameter<DoubleArray>("InitialPeakWidths", "Initial width of each peak.", new DoubleArray(defaultWidths))); 153 182 Parameters.Add(new ValueParameter<DoubleArray>("InitialPeakHeights", "Initial height of each peak.", new DoubleArray(defaultHeights))); 154 183 Parameters.Add(new FixedValueParameter<IntValue>("MovingPeaksRandomSeed", "The random seed for initializing the PRNG for changing the peaks.", new IntValue(666))); 155 Parameters.Add(new FixedValueParameter<IntValue>("PeakMovementInterval", "The interval in evaluated solutions in which peaks are moved.", new IntValue(1000))); 156 Parameters.Add(new FixedValueParameter<DoubleValue>("PeakMovementStrength", "The length of the random vector used for changing peak locations.", new DoubleValue(1.0))); 184 Parameters.Add(new FixedValueParameter<DoubleValue>("MinPeakWidth", "The minimum width of each peak.", new DoubleValue(1.0))); 185 Parameters.Add(new FixedValueParameter<DoubleValue>("MaxPeakWidth", "The maximum width of each peak.", new DoubleValue(12.0))); 186 Parameters.Add(new FixedValueParameter<DoubleValue>("MinPeakHeight", "The minimum height of each peak.", new DoubleValue(30.0))); 187 Parameters.Add(new FixedValueParameter<DoubleValue>("MaxPeakHeight", "The maximum height of each peak.", new DoubleValue(70.0))); 188 Parameters.Add(new FixedValueParameter<IntValue>("PeakMovementInterval", "The interval in evaluated solutions in which peaks are moved.", new IntValue(5000))); 189 Parameters.Add(new FixedValueParameter<DoubleValue>("PeakMovementStrength", "The length of the random vector used for changing peak locations.", new DoubleValue(1.5))); 157 190 Parameters.Add(new OptionalValueParameter<RealVector>("BestKnownSolution", "The location of the highest peak.", new RealVector(defaultBestKnown))); 158 191 -
branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3/MovingPeaksBenchmarkProblemEvaluator.cs
r16611 r16613 45 45 double offlineErrorSum; 46 46 47 #region Parameters 48 public ILookupParameter<DoubleMatrix> BoundsParameter { 49 get { return (ILookupParameter<DoubleMatrix>)Parameters["Bounds"]; } 50 } 47 51 public IValueLookupParameter<DoubleMatrix> PeakLocationsParameter { 48 52 get { return (IValueLookupParameter<DoubleMatrix>)Parameters["PeakLocations"]; } … … 57 61 get { return (ILookupParameter<IntValue>)Parameters["MovingPeaksRandomSeed"]; } 58 62 } 63 public ILookupParameter<DoubleValue> MinPeakWidthParameter { 64 get { return (ILookupParameter<DoubleValue>)Parameters["MinPeakWidth"]; } 65 } 66 public ILookupParameter<DoubleValue> MaxPeakWidthParameter { 67 get { return (ILookupParameter<DoubleValue>)Parameters["MaxPeakWidth"]; } 68 } 69 public ILookupParameter<DoubleValue> MinPeakHeightParameter { 70 get { return (ILookupParameter<DoubleValue>)Parameters["MinPeakHeight"]; } 71 } 72 public ILookupParameter<DoubleValue> MaxPeakHeightParameter { 73 get { return (ILookupParameter<DoubleValue>)Parameters["MaxPeakHeight"]; } 74 } 59 75 public ILookupParameter<IntValue> PeakMovementIntervalParameter { 60 76 get { return (ILookupParameter<IntValue>)Parameters["PeakMovementInterval"]; } … … 78 94 get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; } 79 95 } 96 #endregion 80 97 81 98 [StorableConstructor] … … 83 100 protected MovingPeaksBenchmarkProblemEvaluator(MovingPeaksBenchmarkProblemEvaluator original, Cloner cloner) : base(original, cloner) { } 84 101 public MovingPeaksBenchmarkProblemEvaluator() : base() { 102 Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension.")); 85 103 Parameters.Add(new ValueLookupParameter<DoubleMatrix>("PeakLocations", "Current position of the peaks.")); 86 104 PeakLocationsParameter.ActualName = "InitialPeakLocations"; … … 90 108 PeakHeightsParameter.ActualName = "InitialPeakHeights"; 91 109 Parameters.Add(new LookupParameter<IntValue>("MovingPeaksRandomSeed", "The random seed for initializing the PRNG for changing the peaks.")); 110 Parameters.Add(new LookupParameter<DoubleValue>("MinPeakWidth", "The minimum width of each peak.")); 111 Parameters.Add(new LookupParameter<DoubleValue>("MaxPeakWidth", "The maximum width of each peak.")); 112 Parameters.Add(new LookupParameter<DoubleValue>("MinPeakHeight", "The minimum height of each peak.")); 113 Parameters.Add(new LookupParameter<DoubleValue>("MaxPeakHeight", "The maximum height of each peak.")); 92 114 Parameters.Add(new LookupParameter<IntValue>("PeakMovementInterval", "The interval in evaluated solutions in which peaks are moved.")); 93 115 Parameters.Add(new LookupParameter<DoubleValue>("PeakMovementStrength", "The length of the random vector used for changing peak locations.")); … … 101 123 PeakWidthsParameter.Hidden = true; 102 124 PeakHeightsParameter.Hidden = true; 125 MovingPeaksRandomSeedParameter.Hidden = true; 126 MinPeakWidthParameter.Hidden = true; 127 MaxPeakWidthParameter.Hidden = true; 128 MinPeakHeightParameter.Hidden = true; 129 MaxPeakHeightParameter.Hidden = true; 130 PeakMovementIntervalParameter.Hidden = true; 131 PeakMovementStrengthParameter.Hidden = true; 103 132 BestKnownQualityParameter.Hidden = true; 104 133 BestKnownSolutionParameter.Hidden = true; … … 111 140 112 141 public override IOperation InstrumentedApply() { 142 lock (this) { 143 if (uniformRandom == null) { 144 uniformRandom = new MersenneTwister(); 145 uniformRandom.Reset(MovingPeaksRandomSeedParameter.ActualValue.Value); 146 } 147 } 148 113 149 DoubleMatrix peaks = PeakLocationsParameter.ActualValue; 114 150 DoubleArray widths = PeakWidthsParameter.ActualValue; … … 127 163 results.Add(new Result("Current Peak Widths", widths)); 128 164 results.Add(new Result("Current Peak Heights", heights)); 129 } 130 if (uniformRandom == null) { 131 uniformRandom = new MersenneTwister(); 132 uniformRandom.Reset(MovingPeaksRandomSeedParameter.ActualValue.Value); 133 } 134 135 // move peaks if peaks movement interval is reached 165 166 for (int i = 0; i < widths.Length; i++) { 167 if (widths[i] < 0) { 168 widths[i] = MinPeakWidthParameter.ActualValue.Value + uniformRandom.NextDouble() * (MaxPeakWidthParameter.ActualValue.Value - MinPeakWidthParameter.ActualValue.Value); 169 } 170 if (heights[i] < 0) { 171 heights[i] = MinPeakHeightParameter.ActualValue.Value + uniformRandom.NextDouble() * (MaxPeakHeightParameter.ActualValue.Value - MinPeakHeightParameter.ActualValue.Value); 172 } 173 } 174 } 175 136 176 lock (this) { 177 // move peaks if peaks movement interval is reached 137 178 if ((executions % PeakMovementIntervalParameter.ActualValue.Value) == 0) { 138 MovePeaks(uniformRandom, peaks, widths, heights, PeakMovementStrengthParameter.ActualValue.Value); 179 MovePeaks(uniformRandom, peaks, widths, heights, 180 PeakMovementStrengthParameter.ActualValue.Value, 181 MinPeakWidthParameter.ActualValue.Value, MaxPeakWidthParameter.ActualValue.Value, 182 MinPeakHeightParameter.ActualValue.Value, MaxPeakHeightParameter.ActualValue.Value, 183 BoundsParameter.ActualValue[0, 0], BoundsParameter.ActualValue[0, 1]); 139 184 140 185 // update best known solution & quality according to highest peak … … 202 247 } 203 248 204 private void MovePeaks(IRandom uniformRandom, DoubleMatrix peaks, DoubleArray widths, DoubleArray heights, double strength) { 249 private void MovePeaks(IRandom uniformRandom, DoubleMatrix peaks, DoubleArray widths, DoubleArray heights, double strength, 250 double minWidth, double maxWidth, double minHeight, double maxHeight, double minLocation, double maxLocation) { 205 251 IRandom normalRandom = new NormalDistributedRandom(uniformRandom, 0, 1); 206 252 for (int i = 0; i < peaks.Rows; i++) { … … 208 254 for (int j = 0; j < v.Length; j++) { 209 255 peaks[i, j] += v[j]; 210 } 211 widths[i] = widths[i] + 0.01 * normalRandom.NextDouble(); 212 heights[i] = heights[i] + 7 * normalRandom.NextDouble(); 256 if (peaks[i, j] < minLocation) peaks[i, j] = minLocation; 257 if (peaks[i, j] > maxLocation) peaks[i, j] = maxLocation; 258 } 259 260 widths[i] = NewRandomValue(normalRandom, widths[i], 1.0, minWidth, maxWidth); 261 heights[i] = NewRandomValue(normalRandom, heights[i], 7, minHeight, maxHeight); 213 262 } 214 263 } … … 226 275 return vector; 227 276 } 277 278 private double NewRandomValue(IRandom normalRandom, double value, double factor, double min, double max) { 279 double r, newValue; 280 do { 281 r = normalRandom.NextDouble(); 282 newValue = value + factor * r; 283 } while ((newValue < min) || (newValue > max)); 284 return newValue; 285 } 228 286 } 229 287 }
Note: See TracChangeset
for help on using the changeset viewer.