#region License Information /* HeuristicLab * Copyright (C) 2002-2008 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.Core; using HeuristicLab.Operators; using HeuristicLab.Selection; using HeuristicLab.Logging; using HeuristicLab.Data; using HeuristicLab.GP.Operators; using HeuristicLab.Modeling; using System.Collections.Generic; using System; namespace HeuristicLab.GP.StructureIdentification { public class StandardGP : HeuristicLab.GP.Algorithms.StandardGP, IAlgorithm { public override string Name { get { return "StandardGP - StructureIdentification"; } } public HeuristicLab.DataAnalysis.Dataset Dataset { get { throw new NotImplementedException(); } set { throw new NotImplementedException(); } } public int TargetVariable { get { throw new NotImplementedException(); } set { throw new NotImplementedException(); } } public IAnalyzerModel Model { get { throw new NotImplementedException(); } } public virtual double PunishmentFactor { get { return GetVariableInjector().GetVariable("PunishmentFactor").GetValue().Data; } set { GetVariableInjector().GetVariable("PunishmentFactor").GetValue().Data = value; } } public StandardGP() : base() { PunishmentFactor = 10.0; } protected override IOperator CreateFunctionLibraryInjector() { return DefaultStructureIdentificationAlgorithmOperators.CreateFunctionLibraryInjector(); } protected override IOperator CreateProblemInjector() { return DefaultStructureIdentificationAlgorithmOperators.CreateProblemInjector(); } protected override IOperator CreateInitialPopulationEvaluator() { return DefaultStructureIdentificationAlgorithmOperators.CreateInitialPopulationEvaluator(); } protected override IOperator CreateEvaluationOperator() { return DefaultStructureIdentificationAlgorithmOperators.CreateEvaluator(); } protected override IOperator CreateGenerationStepHook() { return DefaultStructureIdentificationAlgorithmOperators.CreateGenerationStepHook(); } protected override VariableInjector CreateGlobalInjector() { VariableInjector injector = base.CreateGlobalInjector(); injector.AddVariable(new HeuristicLab.Core.Variable("UseEstimatedTargetValue", new BoolData())); injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData())); return injector; } protected override IOperator CreateLoggingOperator() { CombinedOperator loggingOperator = new CombinedOperator(); loggingOperator.Name = "Logging"; SequentialProcessor seq = new SequentialProcessor(); DataCollector collector = new DataCollector(); ItemList names = collector.GetVariable("VariableNames").GetValue>(); names.Add(new StringData("BestQuality")); names.Add(new StringData("AverageQuality")); names.Add(new StringData("WorstQuality")); names.Add(new StringData("BestValidationQuality")); names.Add(new StringData("AverageValidationQuality")); names.Add(new StringData("WorstValidationQuality")); names.Add(new StringData("EvaluatedSolutions")); QualityLogger qualityLogger = new QualityLogger(); QualityLogger validationQualityLogger = new QualityLogger(); validationQualityLogger.GetVariableInfo("Quality").ActualName = "ValidationQuality"; validationQualityLogger.GetVariableInfo("QualityLog").ActualName = "ValidationQualityLog"; seq.AddSubOperator(collector); seq.AddSubOperator(qualityLogger); seq.AddSubOperator(validationQualityLogger); loggingOperator.OperatorGraph.AddOperator(seq); loggingOperator.OperatorGraph.InitialOperator = seq; return loggingOperator; } public override object Clone(IDictionary clonedObjects) { StandardGP clone = (StandardGP)base.Clone(clonedObjects); clone.PunishmentFactor = PunishmentFactor; return clone; } } }