#region License Information /* HeuristicLab * Copyright (C) 2002-2013 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; using HeuristicLab.PluginInfrastructure; namespace HeuristicLab.Analysis.SolutionCaching { [StorableClass] public abstract class MutationPointcut : SingleSuccessorOperator, IManipulator, IStochasticOperator, IPointcut where TA : class, IAdvice where TM : class, IManipulator { protected const string AdviceParameterName = "Advice"; protected const string MutatorsParameterName = "Mutators"; public ConstrainedValueParameter MutatorsParameter { get { return (ConstrainedValueParameter)Parameters[MutatorsParameterName]; } } public ConstrainedValueParameter AdviceParameter { get { return (ConstrainedValueParameter)Parameters[AdviceParameterName]; } } public ILookupParameter RandomParameter { get { return (ILookupParameter)Parameters["Random"]; } } [StorableConstructor] protected MutationPointcut(bool deserializing) : base(deserializing) { } protected MutationPointcut(MutationPointcut original, Cloner cloner) : base(original, cloner) { } public MutationPointcut() : base() { var advices = new ConstrainedValueParameter(AdviceParameterName, "Advice to introduce after crossover"); foreach (var a in ApplicationManager.Manager.GetInstances()) { advices.ValidValues.Add(a); } Parameters.Add(advices); Parameters.Add(new LookupParameter("Random", "The random number generator to use.")); Parameters.Add(new ConstrainedValueParameter(MutatorsParameterName, "The mutators.")); } public override IOperation Apply() { IOperation successor = base.Apply(); IOperation mutationOperation = ExecutionContext.CreateChildOperation(MutatorsParameter.Value); IOperation adviceOperation = ExecutionContext.CreateChildOperation(AdviceParameter.Value); var opCol = new OperationCollection(); opCol.Add(mutationOperation); opCol.Add(adviceOperation); if (successor != null) opCol.Add(successor); return opCol; } } }