[13071] | 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 |
|
---|
| 22 | using HeuristicLab.Common;
|
---|
[13069] | 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
| 26 | using HeuristicLab.Parameters;
|
---|
| 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 | using System.Linq;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.BioBoost.SolutionCreation {
|
---|
| 31 |
|
---|
| 32 | [StorableClass]
|
---|
| 33 | public class LimitedValuesIntegerVectorCreator : IntegerVectorCreator {
|
---|
| 34 |
|
---|
| 35 | #region parameters
|
---|
| 36 | public ValueLookupParameter<IntValue> NrOfValuesParameter {
|
---|
| 37 | get { return (ValueLookupParameter<IntValue>) Parameters["NrOfValues"]; }
|
---|
| 38 | }
|
---|
| 39 | #endregion
|
---|
| 40 |
|
---|
| 41 | #region parameter values
|
---|
| 42 | public IntValue NrOfValues {
|
---|
| 43 | get { return NrOfValuesParameter.ActualValue; }
|
---|
| 44 | set { NrOfValuesParameter.ActualValue = value; }
|
---|
| 45 | }
|
---|
| 46 | #endregion
|
---|
| 47 |
|
---|
| 48 | #region Construction & Cloning
|
---|
| 49 | [StorableConstructor]
|
---|
| 50 | protected LimitedValuesIntegerVectorCreator(bool isDeserializing) : base(isDeserializing) {}
|
---|
| 51 | protected LimitedValuesIntegerVectorCreator(LimitedValuesIntegerVectorCreator orig, Cloner cloner) : base(orig, cloner) {}
|
---|
| 52 | public LimitedValuesIntegerVectorCreator() {
|
---|
| 53 | Parameters.Add(new ValueLookupParameter<IntValue>("NrOfValues", "Nr of distinct values to chose from.", new IntValue(1)));
|
---|
| 54 | }
|
---|
| 55 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 56 | return new LimitedValuesIntegerVectorCreator(this, cloner);
|
---|
| 57 | }
|
---|
| 58 | #endregion
|
---|
| 59 |
|
---|
| 60 | protected override IntegerVector Create(IRandom random, IntValue length, IntMatrix bounds) {
|
---|
| 61 | var nrOfValues = NrOfValues.Value;
|
---|
| 62 | var len = length.Value;
|
---|
| 63 | var values = Enumerable.Range(0, nrOfValues).Select(i => random.Next(len)).ToList();
|
---|
| 64 | return new IntegerVector(Enumerable.Range(0, len).Select(i => values[random.Next(nrOfValues)]).ToArray());
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | }
|
---|
| 68 | }
|
---|