source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/SolutionCreation/LimitedValuesIntegerVectorCreator.cs @ 13069

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

#2499: imported source code for HeuristicLab.BioBoost from private repository with some changes

File size: 1.8 KB
Line 
1using HeuristicLab.Common;
2using HeuristicLab.Core;
3using HeuristicLab.Data;
4using HeuristicLab.Encodings.IntegerVectorEncoding;
5using HeuristicLab.Parameters;
6using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
7using System.Linq;
8
9namespace HeuristicLab.BioBoost.SolutionCreation {
10
11  [StorableClass]
12  public class LimitedValuesIntegerVectorCreator : IntegerVectorCreator {
13
14    #region parameters
15    public ValueLookupParameter<IntValue> NrOfValuesParameter {
16      get { return (ValueLookupParameter<IntValue>) Parameters["NrOfValues"]; }
17    }
18    #endregion
19
20    #region parameter values
21    public IntValue NrOfValues {
22      get { return NrOfValuesParameter.ActualValue; }
23      set { NrOfValuesParameter.ActualValue = value; }
24    }
25    #endregion
26
27    #region Construction & Cloning
28    [StorableConstructor]
29    protected LimitedValuesIntegerVectorCreator(bool isDeserializing) : base(isDeserializing) {}
30    protected LimitedValuesIntegerVectorCreator(LimitedValuesIntegerVectorCreator orig, Cloner cloner) : base(orig, cloner) {}
31    public LimitedValuesIntegerVectorCreator() {
32      Parameters.Add(new ValueLookupParameter<IntValue>("NrOfValues", "Nr of distinct values to chose from.", new IntValue(1)));
33    }
34    public override IDeepCloneable Clone(Cloner cloner) {
35      return new LimitedValuesIntegerVectorCreator(this, cloner);
36    }
37    #endregion
38
39    protected override IntegerVector Create(IRandom random, IntValue length, IntMatrix bounds) {
40      var nrOfValues = NrOfValues.Value;
41      var len = length.Value;
42      var values = Enumerable.Range(0, nrOfValues).Select(i => random.Next(len)).ToList();
43      return new IntegerVector(Enumerable.Range(0, len).Select(i => values[random.Next(nrOfValues)]).ToArray());
44    }
45
46  }
47}
Note: See TracBrowser for help on using the repository browser.