#region License Information
/* HeuristicLab
* Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Encodings.IntegerVectorEncoding;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using System.Linq;
using HEAL.Attic;
namespace HeuristicLab.BioBoost.SolutionCreation {
[StorableType("83148271-792B-471B-99C0-740E8671940A")]
public class LimitedValuesIntegerVectorCreator : IntegerVectorCreator {
#region parameters
public ValueLookupParameter NrOfValuesParameter {
get { return (ValueLookupParameter) Parameters["NrOfValues"]; }
}
#endregion
#region parameter values
public IntValue NrOfValues {
get { return NrOfValuesParameter.ActualValue; }
set { NrOfValuesParameter.ActualValue = value; }
}
#endregion
#region Construction & Cloning
[StorableConstructor]
protected LimitedValuesIntegerVectorCreator(StorableConstructorFlag _) : base(_) { }
protected LimitedValuesIntegerVectorCreator(LimitedValuesIntegerVectorCreator orig, Cloner cloner) : base(orig, cloner) {}
public LimitedValuesIntegerVectorCreator() {
Parameters.Add(new ValueLookupParameter("NrOfValues", "Nr of distinct values to chose from.", new IntValue(1)));
}
public override IDeepCloneable Clone(Cloner cloner) {
return new LimitedValuesIntegerVectorCreator(this, cloner);
}
#endregion
protected override IntegerVector Create(IRandom random, IntValue length, IntMatrix bounds) {
var nrOfValues = NrOfValues.Value;
var len = length.Value;
var values = Enumerable.Range(0, nrOfValues).Select(i => random.Next(len)).ToList();
return new IntegerVector(Enumerable.Range(0, len).Select(i => values[random.Next(nrOfValues)]).ToArray());
}
}
}