Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/SolutionCreation/LimitedValuesIntegerVectorCreator.cs @ 16575

Last change on this file since 16575 was 16575, checked in by gkronber, 5 years ago

#2520: changed HeuristicLab.BioBoost addon to compile with new HL.Persistence

File size: 2.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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.Data;
25using HeuristicLab.Encodings.IntegerVectorEncoding;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using System.Linq;
29using HEAL.Attic;
30
31namespace HeuristicLab.BioBoost.SolutionCreation {
32
33  [StorableType("83148271-792B-471B-99C0-740E8671940A")]
34  public class LimitedValuesIntegerVectorCreator : IntegerVectorCreator {
35
36    #region parameters
37    public ValueLookupParameter<IntValue> NrOfValuesParameter {
38      get { return (ValueLookupParameter<IntValue>) Parameters["NrOfValues"]; }
39    }
40    #endregion
41
42    #region parameter values
43    public IntValue NrOfValues {
44      get { return NrOfValuesParameter.ActualValue; }
45      set { NrOfValuesParameter.ActualValue = value; }
46    }
47    #endregion
48
49    #region Construction & Cloning
50    [StorableConstructor]
51    protected LimitedValuesIntegerVectorCreator(StorableConstructorFlag _) : base(_) { }
52    protected LimitedValuesIntegerVectorCreator(LimitedValuesIntegerVectorCreator orig, Cloner cloner) : base(orig, cloner) {}
53    public LimitedValuesIntegerVectorCreator() {
54      Parameters.Add(new ValueLookupParameter<IntValue>("NrOfValues", "Nr of distinct values to chose from.", new IntValue(1)));
55    }
56    public override IDeepCloneable Clone(Cloner cloner) {
57      return new LimitedValuesIntegerVectorCreator(this, cloner);
58    }
59    #endregion
60
61    protected override IntegerVector Create(IRandom random, IntValue length, IntMatrix bounds) {
62      var nrOfValues = NrOfValues.Value;
63      var len = length.Value;
64      var values = Enumerable.Range(0, nrOfValues).Select(i => random.Next(len)).ToList();
65      return new IntegerVector(Enumerable.Range(0, len).Select(i => values[random.Next(nrOfValues)]).ToArray());
66    }
67
68  }
69}
Note: See TracBrowser for help on using the repository browser.