Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17717 was 17332, checked in by bwerth, 5 years ago

#2745 updated persistence to HEAL.Attic

File size: 2.6 KB
RevLine 
[14833]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
[17332]22using HEAL.Attic;
[14833]23using HeuristicLab.Common;
24using HeuristicLab.Core;
[15343]25using HeuristicLab.Optimization;
26using HeuristicLab.Encodings.IntegerVectorEncoding;
[14833]27
28// ReSharper disable once CheckNamespace
29namespace HeuristicLab.Algorithms.EGO {
30
[17332]31    [StorableType("6c6474ee-b8f2-409e-a2e4-61b7c01e1fa2")]
32    [Item("UniformRandomDiscreteSampling", "A uniform random sampling strategy for real valued optimization")]
[15343]33  public class UniformRandomDiscreteSampling : ParameterizedNamedItem, IInitialSampling<IntegerVector> {
[14833]34
35    #region HL-Constructors, Serialization and Cloning
36    [StorableConstructor]
[17332]37    protected UniformRandomDiscreteSampling(StorableConstructorFlag deserializing) : base(deserializing) { }
[15343]38    protected UniformRandomDiscreteSampling(UniformRandomDiscreteSampling original, Cloner cloner) : base(original, cloner) { }
39    public UniformRandomDiscreteSampling() {
[14833]40    }
41    public override IDeepCloneable Clone(Cloner cloner) {
[15343]42      return new UniformRandomDiscreteSampling(this, cloner);
[14833]43    }
44
[15343]45    public IntegerVector[] GetSamples(int noSamples, IntegerVector[] existingSamples, IEncoding encoding, IRandom random) {
46      var enc = encoding as IntegerVectorEncoding;
47      var res = new IntegerVector[noSamples];
[14833]48      for (var i = 0; i < noSamples; i++) {
[15343]49        var r = new IntegerVector(enc.Length);
[14833]50        res[i] = r;
[15343]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);
[14833]54        }
55      }
56      return res;
57    }
[15343]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
[14833]60    }
61  }
62
63
64
65
66  #endregion
67
68
69}
70
Note: See TracBrowser for help on using the repository browser.