Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2745_EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/SamplingMethods/UniformRandomDiscreteSampling.cs @ 17317

Last change on this file since 17317 was 15343, checked in by bwerth, 7 years ago

#2745 added discretized EGO-version for use with IntegerVectors

File size: 2.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Optimization;
25using HeuristicLab.Encodings.IntegerVectorEncoding;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28// ReSharper disable once CheckNamespace
29namespace HeuristicLab.Algorithms.EGO {
30
31  [StorableClass]
32  [Item("UniformRandomDiscreteSampling", "A uniform random sampling strategy for real valued optimization")]
33  public class UniformRandomDiscreteSampling : ParameterizedNamedItem, IInitialSampling<IntegerVector> {
34
35    #region HL-Constructors, Serialization and Cloning
36    [StorableConstructor]
37    protected UniformRandomDiscreteSampling(bool deserializing) : base(deserializing) { }
38    protected UniformRandomDiscreteSampling(UniformRandomDiscreteSampling original, Cloner cloner) : base(original, cloner) { }
39    public UniformRandomDiscreteSampling() {
40    }
41    public override IDeepCloneable Clone(Cloner cloner) {
42      return new UniformRandomDiscreteSampling(this, cloner);
43    }
44
45    public IntegerVector[] GetSamples(int noSamples, IntegerVector[] existingSamples, IEncoding encoding, IRandom random) {
46      var enc = encoding as IntegerVectorEncoding;
47      var res = new IntegerVector[noSamples];
48      for (var i = 0; i < noSamples; i++) {
49        var r = new IntegerVector(enc.Length);
50        res[i] = r;
51        for (var j = 0; j < enc.Length; j++) {
52          var b = j % enc.Bounds.Rows;
53          r[j] = UniformRandom(enc.Bounds[b, 0], enc.Bounds[b, 1], random);
54        }
55      }
56      return res;
57    }
58    private static int UniformRandom(int min, int max, IRandom rand) {
59      return rand.Next(min, max + 1);  //TODO check wether max is inclusive or exclusive
60    }
61  }
62
63
64
65
66  #endregion
67
68
69}
70
Note: See TracBrowser for help on using the repository browser.