Free cookie consent management tool by TermsFeed Policy Generator

source: branches/gp-algorithms-refactoring-#720/sources/HeuristicLab.GP.StructureIdentification/3.3/StandardGP.cs @ 2337

Last change on this file since 2337 was 2337, checked in by gkronber, 15 years ago

refactoring: pulled common code of OSGP and SGP into static class DefaultStructureIdentificationOperators. #720

File size: 4.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Core;
23using HeuristicLab.Operators;
24using HeuristicLab.Selection;
25using HeuristicLab.Logging;
26using HeuristicLab.Data;
27using HeuristicLab.GP.Operators;
28using HeuristicLab.Modeling;
29using System.Collections.Generic;
30using System;
31
32namespace HeuristicLab.GP.StructureIdentification {
33  public class StandardGP : HeuristicLab.GP.Algorithms.StandardGP, IAlgorithm {
34
35    public override string Name { get { return "StandardGP - StructureIdentification"; } }
36
37    public HeuristicLab.DataAnalysis.Dataset Dataset {
38      get {
39        throw new NotImplementedException();
40      }
41      set {
42        throw new NotImplementedException();
43      }
44    }
45
46    public int TargetVariable {
47      get {
48        throw new NotImplementedException();
49      }
50      set {
51        throw new NotImplementedException();
52      }
53    }
54
55    public IAnalyzerModel Model {
56      get { throw new NotImplementedException(); }
57    }
58
59    public virtual double PunishmentFactor {
60      get { return GetVariableInjector().GetVariable("PunishmentFactor").GetValue<DoubleData>().Data; }
61      set { GetVariableInjector().GetVariable("PunishmentFactor").GetValue<DoubleData>().Data = value; }
62    }
63
64    public StandardGP()
65      : base() {
66
67      PunishmentFactor = 10.0;
68    }
69
70    protected override IOperator CreateFunctionLibraryInjector() {
71      return DefaultStructureIdentificationAlgorithmOperators.CreateFunctionLibraryInjector();
72    }
73
74    protected override IOperator CreateProblemInjector() {
75      return DefaultStructureIdentificationAlgorithmOperators.CreateProblemInjector();
76    }
77
78    protected override IOperator CreateInitialPopulationEvaluator() {
79      return DefaultStructureIdentificationAlgorithmOperators.CreateInitialPopulationEvaluator();
80    }
81
82    protected override IOperator CreateEvaluationOperator() {
83      return DefaultStructureIdentificationAlgorithmOperators.CreateEvaluator();     
84    }
85
86
87    protected override IOperator CreateGenerationStepHook() {
88      return DefaultStructureIdentificationAlgorithmOperators.CreateGenerationStepHook();
89    }
90
91    protected override VariableInjector CreateGlobalInjector() {
92      VariableInjector injector = base.CreateGlobalInjector();
93      injector.AddVariable(new HeuristicLab.Core.Variable("UseEstimatedTargetValue", new BoolData()));
94      injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData()));
95      return injector;
96    }
97
98    protected override IOperator CreateLoggingOperator() {
99      CombinedOperator loggingOperator = new CombinedOperator();
100      loggingOperator.Name = "Logging";
101      SequentialProcessor seq = new SequentialProcessor();
102
103      DataCollector collector = new DataCollector();
104      ItemList<StringData> names = collector.GetVariable("VariableNames").GetValue<ItemList<StringData>>();
105      names.Add(new StringData("BestQuality"));
106      names.Add(new StringData("AverageQuality"));
107      names.Add(new StringData("WorstQuality"));
108      names.Add(new StringData("BestValidationQuality"));
109      names.Add(new StringData("AverageValidationQuality"));
110      names.Add(new StringData("WorstValidationQuality"));
111      names.Add(new StringData("EvaluatedSolutions"));
112      QualityLogger qualityLogger = new QualityLogger();
113      QualityLogger validationQualityLogger = new QualityLogger();
114      validationQualityLogger.GetVariableInfo("Quality").ActualName = "ValidationQuality";
115      validationQualityLogger.GetVariableInfo("QualityLog").ActualName = "ValidationQualityLog";
116      seq.AddSubOperator(collector);
117      seq.AddSubOperator(qualityLogger);
118      seq.AddSubOperator(validationQualityLogger);
119
120      loggingOperator.OperatorGraph.AddOperator(seq);
121      loggingOperator.OperatorGraph.InitialOperator = seq;
122      return loggingOperator;
123    }
124
125    public override object Clone(IDictionary<Guid, object> clonedObjects) {
126      StandardGP clone = (StandardGP)base.Clone(clonedObjects);
127      clone.PunishmentFactor = PunishmentFactor;
128      return clone;
129    }
130  }
131}
Note: See TracBrowser for help on using the repository browser.