1 | using HeuristicLab.Common;
|
---|
2 | using HeuristicLab.Core;
|
---|
3 | using HeuristicLab.Data;
|
---|
4 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
5 | using HeuristicLab.Parameters;
|
---|
6 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
7 | using System.Linq;
|
---|
8 |
|
---|
9 | namespace 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 | }
|
---|