#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 CrossoverPointcut : SingleSuccessorOperator, ICrossover, IStochasticOperator, IPointcut
where TA : class, IAdvice
where TC : class, ICrossover {
protected const string AdviceParameterName = "Advice";
protected const string CrossoversParameterName = "Crossovers";
public ConstrainedValueParameter CrossoversParameter {
get { return (ConstrainedValueParameter)Parameters[CrossoversParameterName]; }
}
public ConstrainedValueParameter AdviceParameter {
get { return (ConstrainedValueParameter)Parameters[AdviceParameterName]; }
}
public ILookupParameter RandomParameter {
get { return (ILookupParameter)Parameters["Random"]; }
}
[StorableConstructor]
protected CrossoverPointcut(bool deserializing) : base(deserializing) { }
protected CrossoverPointcut(CrossoverPointcut original, Cloner cloner) : base(original, cloner) { }
public CrossoverPointcut()
: 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(CrossoversParameterName, "The crossovers."));
}
public override IOperation Apply() {
IOperation successor = base.Apply();
IOperation crossoverOperation = ExecutionContext.CreateChildOperation(CrossoversParameter.Value);
IOperation adviceOperation = ExecutionContext.CreateChildOperation(AdviceParameter.Value);
var opCol = new OperationCollection();
opCol.Add(crossoverOperation);
opCol.Add(adviceOperation);
if (successor != null)
opCol.Add(successor);
return opCol;
}
}
}