[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 |
|
---|
| 22 | using HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
[15343] | 24 | using HeuristicLab.Optimization;
|
---|
| 25 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
[14833] | 26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 27 |
|
---|
| 28 | // ReSharper disable once CheckNamespace
|
---|
| 29 | namespace HeuristicLab.Algorithms.EGO {
|
---|
| 30 |
|
---|
| 31 | [StorableClass]
|
---|
[15343] | 32 | [Item("UniformRandomDiscreteSampling", "A uniform random sampling strategy for real valued optimization")]
|
---|
| 33 | public class UniformRandomDiscreteSampling : ParameterizedNamedItem, IInitialSampling<IntegerVector> {
|
---|
[14833] | 34 |
|
---|
| 35 | #region HL-Constructors, Serialization and Cloning
|
---|
| 36 | [StorableConstructor]
|
---|
[15343] | 37 | protected UniformRandomDiscreteSampling(bool deserializing) : base(deserializing) { }
|
---|
| 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 |
|
---|