#region License Information /* HeuristicLab * Copyright (C) 2002-2012 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.Operators; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Encodings.ParameterConfigurationEncoding { /// /// An operator which creates a new set of parameters. /// [Item("RandomParameterVectorCreator", "An operator which creates a new set of parameters.")] [StorableClass] public sealed class RandomParameterConfigurationCreator : SingleSuccessorOperator, IStochasticOperator, IParameterConfigurationCreator { public override bool CanChangeName { get { return false; } } public ILookupParameter RandomParameter { get { return (LookupParameter)Parameters["Random"]; } } public ILookupParameter InitialParameterConfigurationParameter { get { return (ILookupParameter)Parameters["ParameterConfiguration"]; } } public IValueLookupParameter ParameterConfigurationParameter { get { return (IValueLookupParameter)Parameters["ParameterConfigurationTreeSolutionCandidate"]; } } #region Constructors and Cloning public RandomParameterConfigurationCreator() : base() { Parameters.Add(new LookupParameter("Random", "The pseudo random number generator which should be used to initialize the new random permutation.")); Parameters.Add(new LookupParameter("ParameterConfiguration", "The parameter configuration tree on which the new solution will be based on.")); Parameters.Add(new ValueLookupParameter("ParameterConfigurationTreeSolutionCandidate", "The new random parameter set.")); } [StorableConstructor] private RandomParameterConfigurationCreator(bool deserializing) : base(deserializing) { } private RandomParameterConfigurationCreator(RandomParameterConfigurationCreator original, Cloner cloner) : base(original, cloner) { } public override IDeepCloneable Clone(Cloner cloner) { return new RandomParameterConfigurationCreator(this, cloner); } #endregion public override IOperation Apply() { ParameterConfigurationParameter.ActualValue = (ParameterConfigurationTree)InitialParameterConfigurationParameter.ActualValue.Clone(); ParameterConfigurationParameter.ActualValue.Randomize(RandomParameter.ActualValue); return base.Apply(); } } }