#region License Information
/* HeuristicLab
* Copyright (C) 2002-2016 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 .
*
* Author: Sabine Winkler
*/
#endregion
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using HeuristicLab.Problems.DataAnalysis;
using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
namespace HeuristicLab.Problems.GrammaticalEvolution {
[StorableClass]
public class GESymbolicRegressionSingleObjectiveEvaluator : GESymbolicDataAnalysisSingleObjectiveEvaluator,
IGESymbolicRegressionSingleObjectiveEvaluator {
public const string EvaluatorParameterName = "Evaluator";
public const string RandomParameterName = "Random";
public const string BoundsParameterName = "Bounds";
public const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
public IValueParameter EvaluatorParameter {
get { return (IValueParameter)Parameters[EvaluatorParameterName]; }
}
public ILookupParameter BoundsParameter {
get { return (ILookupParameter)Parameters[BoundsParameterName]; }
}
public ILookupParameter MaximumSymbolicExpressionTreeLengthParameter {
get { return (ILookupParameter)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
}
public ISymbolicRegressionSingleObjectiveEvaluator Evaluator {
get { return EvaluatorParameter.Value; }
}
[StorableConstructor]
protected GESymbolicRegressionSingleObjectiveEvaluator(bool deserializing) : base(deserializing) { }
protected GESymbolicRegressionSingleObjectiveEvaluator(GESymbolicRegressionSingleObjectiveEvaluator original, Cloner cloner) : base(original, cloner) { }
public GESymbolicRegressionSingleObjectiveEvaluator()
: base() {
Parameters.Add(new ValueParameter(EvaluatorParameterName, "The symbolic regression evaluator that should be used to assess the quality of trees.", new SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator()));
Parameters.Add(new LookupParameter(BoundsParameterName, "The integer number range in which the single genomes of a genotype are created."));
Parameters.Add(new LookupParameter(MaximumSymbolicExpressionTreeLengthParameterName, "Genotype length."));
}
public override IDeepCloneable Clone(Cloner cloner) {
return new GESymbolicRegressionSingleObjectiveEvaluator(this, cloner);
}
public override bool Maximization {
get { return Evaluator.Maximization; }
}
public override IOperation Apply() {
var genotype = IntegerVectorParameter.ActualValue;
// translate to phenotype
var tree = GenotypeToPhenotypeMapperParameter.ActualValue.Map(
RandomParameter.ActualValue,
BoundsParameter.ActualValue,
MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value,
SymbolicExpressionTreeGrammarParameter.ActualValue,
genotype
);
SymbolicExpressionTreeParameter.ActualValue = tree; // write to scope for analyzers
// create operation for evaluation
var evalOp = ExecutionContext.CreateChildOperation(Evaluator);
var successorOp = base.Apply();
return new OperationCollection(evalOp, successorOp);
}
}
}