[1230] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using System.Xml;
|
---|
| 28 | using System.Diagnostics;
|
---|
| 29 | using HeuristicLab.DataAnalysis;
|
---|
| 30 | using HeuristicLab.Operators;
|
---|
| 31 | using HeuristicLab.Random;
|
---|
| 32 | using HeuristicLab.Selection;
|
---|
| 33 | using HeuristicLab.Logging;
|
---|
| 34 | using HeuristicLab.Data;
|
---|
| 35 | using HeuristicLab.Operators.Programmable;
|
---|
[1335] | 36 | using HeuristicLab.Evolutionary;
|
---|
[1230] | 37 |
|
---|
| 38 | namespace HeuristicLab.GP.StructureIdentification {
|
---|
[1231] | 39 | public abstract class AlgorithmBase : ItemBase {
|
---|
| 40 | public virtual double MutationRate {
|
---|
[1287] | 41 | get { return GetVariableInjector().GetVariable("MutationRate").GetValue<DoubleData>().Data; }
|
---|
| 42 | set { GetVariableInjector().GetVariable("MutationRate").GetValue<DoubleData>().Data = value; }
|
---|
[1230] | 43 | }
|
---|
[1231] | 44 | public virtual int PopulationSize {
|
---|
[1287] | 45 | get { return GetVariableInjector().GetVariable("PopulationSize").GetValue<IntData>().Data; }
|
---|
| 46 | set { GetVariableInjector().GetVariable("PopulationSize").GetValue<IntData>().Data = value; }
|
---|
[1230] | 47 | }
|
---|
| 48 |
|
---|
[1231] | 49 | public virtual bool SetSeedRandomly {
|
---|
[1287] | 50 | get { return GetRandomInjector().GetVariable("SetSeedRandomly").GetValue<BoolData>().Data; }
|
---|
| 51 | set { GetRandomInjector().GetVariable("SetSeedRandomly").GetValue<BoolData>().Data = value; }
|
---|
[1230] | 52 | }
|
---|
| 53 |
|
---|
[1231] | 54 | public virtual int Seed {
|
---|
[1287] | 55 | get { return GetRandomInjector().GetVariable("Seed").GetValue<IntData>().Data; }
|
---|
| 56 | set { GetRandomInjector().GetVariable("Seed").GetValue<IntData>().Data = value; }
|
---|
[1230] | 57 | }
|
---|
| 58 |
|
---|
[1231] | 59 | public virtual IOperator ProblemInjector {
|
---|
[1230] | 60 | get { return algorithm.SubOperators[0]; }
|
---|
| 61 | set {
|
---|
| 62 | value.Name = "ProblemInjector";
|
---|
| 63 | algorithm.RemoveSubOperator(0);
|
---|
| 64 | algorithm.AddSubOperator(value, 0);
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[1231] | 68 | public virtual int Elites {
|
---|
[1287] | 69 | get { return GetVariableInjector().GetVariable("Elites").GetValue<IntData>().Data; }
|
---|
| 70 | set { GetVariableInjector().GetVariable("Elites").GetValue<IntData>().Data = value; }
|
---|
[1230] | 71 | }
|
---|
| 72 |
|
---|
[1231] | 73 | public virtual int MaxTreeSize {
|
---|
[1287] | 74 | get { return GetVariableInjector().GetVariable("MaxTreeSize").GetValue<IntData>().Data; }
|
---|
| 75 | set { GetVariableInjector().GetVariable("MaxTreeSize").GetValue<IntData>().Data = value; }
|
---|
[1230] | 76 | }
|
---|
| 77 |
|
---|
[1231] | 78 | public virtual int MaxTreeHeight {
|
---|
[1287] | 79 | get { return GetVariableInjector().GetVariable("MaxTreeHeight").GetValue<IntData>().Data; }
|
---|
| 80 | set { GetVariableInjector().GetVariable("MaxTreeHeight").GetValue<IntData>().Data = value; }
|
---|
[1230] | 81 | }
|
---|
| 82 |
|
---|
[1231] | 83 | public virtual int Parents {
|
---|
[1287] | 84 | get { return GetVariableInjector().GetVariable("Parents").GetValue<IntData>().Data; }
|
---|
| 85 | set { GetVariableInjector().GetVariable("Parents").GetValue<IntData>().Data = value; }
|
---|
[1231] | 86 | }
|
---|
| 87 |
|
---|
[1287] | 88 | public virtual double PunishmentFactor {
|
---|
| 89 | get { return GetVariableInjector().GetVariable("PunishmentFactor").GetValue<DoubleData>().Data; }
|
---|
| 90 | set { GetVariableInjector().GetVariable("PunishmentFactor").GetValue<DoubleData>().Data = value; }
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | public virtual bool UseEstimatedTargetValue {
|
---|
| 94 | get { return GetVariableInjector().GetVariable("UseEstimatedTargetValue").GetValue<BoolData>().Data; }
|
---|
| 95 | set { GetVariableInjector().GetVariable("UseEstimatedTargetValue").GetValue<BoolData>().Data = value; }
|
---|
| 96 | }
|
---|
| 97 |
|
---|
[1230] | 98 | private IOperator algorithm;
|
---|
| 99 |
|
---|
| 100 | private SequentialEngine.SequentialEngine engine;
|
---|
| 101 | public IEngine Engine {
|
---|
| 102 | get { return engine; }
|
---|
[1231] | 103 | protected set { engine = (SequentialEngine.SequentialEngine)value; }
|
---|
[1230] | 104 | }
|
---|
| 105 |
|
---|
| 106 | public AlgorithmBase() {
|
---|
| 107 | engine = new SequentialEngine.SequentialEngine();
|
---|
| 108 | CombinedOperator algo = CreateAlgorithm();
|
---|
| 109 | engine.OperatorGraph.AddOperator(algo);
|
---|
| 110 | engine.OperatorGraph.InitialOperator = algo;
|
---|
[1287] | 111 | SetSeedRandomly = true;
|
---|
| 112 | Elites = 1;
|
---|
| 113 | MutationRate = 0.15;
|
---|
| 114 | PopulationSize = 1000;
|
---|
| 115 | MaxTreeSize = 100;
|
---|
| 116 | MaxTreeHeight = 10;
|
---|
| 117 | Parents = 2000;
|
---|
| 118 | PunishmentFactor = 10;
|
---|
| 119 | UseEstimatedTargetValue = false;
|
---|
[1230] | 120 | }
|
---|
| 121 |
|
---|
[1287] | 122 | protected internal virtual CombinedOperator CreateAlgorithm() {
|
---|
[1230] | 123 | CombinedOperator algo = new CombinedOperator();
|
---|
| 124 | algo.Name = "GP";
|
---|
| 125 | SequentialProcessor seq = new SequentialProcessor();
|
---|
[1287] | 126 | IOperator problemInjector = CreateProblemInjector();
|
---|
[1230] | 127 |
|
---|
| 128 | RandomInjector randomInjector = new RandomInjector();
|
---|
| 129 | randomInjector.Name = "Random Injector";
|
---|
| 130 |
|
---|
| 131 | IOperator globalInjector = CreateGlobalInjector();
|
---|
| 132 | IOperator initialization = CreateInitialization();
|
---|
[1287] | 133 | IOperator funLibInjector = CreateFunctionLibraryInjector();
|
---|
[1230] | 134 | IOperator mainLoop = CreateMainLoop();
|
---|
| 135 | mainLoop.Name = "Main loop";
|
---|
| 136 |
|
---|
| 137 | IOperator treeCreator = CreateTreeCreator();
|
---|
[1287] | 138 |
|
---|
[1230] | 139 | MeanSquaredErrorEvaluator evaluator = new MeanSquaredErrorEvaluator();
|
---|
| 140 | evaluator.GetVariableInfo("MSE").ActualName = "Quality";
|
---|
| 141 | evaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
|
---|
| 142 | evaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
|
---|
| 143 | evaluator.Name = "Evaluator";
|
---|
[1287] | 144 |
|
---|
[1230] | 145 | IOperator crossover = CreateCrossover();
|
---|
| 146 | IOperator manipulator = CreateManipulator();
|
---|
| 147 |
|
---|
| 148 | IOperator selector = CreateSelector();
|
---|
| 149 | LeftReducer cleanUp = new LeftReducer();
|
---|
| 150 |
|
---|
[1287] | 151 | seq.AddSubOperator(problemInjector);
|
---|
[1230] | 152 | seq.AddSubOperator(randomInjector);
|
---|
| 153 | seq.AddSubOperator(globalInjector);
|
---|
| 154 | seq.AddSubOperator(funLibInjector);
|
---|
| 155 | seq.AddSubOperator(initialization);
|
---|
| 156 | seq.AddSubOperator(mainLoop);
|
---|
| 157 | seq.AddSubOperator(cleanUp);
|
---|
| 158 |
|
---|
| 159 | initialization.AddSubOperator(treeCreator);
|
---|
| 160 | initialization.AddSubOperator(evaluator);
|
---|
| 161 |
|
---|
| 162 | mainLoop.AddSubOperator(selector);
|
---|
| 163 | mainLoop.AddSubOperator(crossover);
|
---|
| 164 | mainLoop.AddSubOperator(manipulator);
|
---|
| 165 | mainLoop.AddSubOperator(evaluator);
|
---|
| 166 | algo.OperatorGraph.AddOperator(seq);
|
---|
| 167 | algo.OperatorGraph.InitialOperator = seq;
|
---|
| 168 | this.algorithm = seq;
|
---|
| 169 | return algo;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
[1287] | 172 | protected internal virtual IOperator CreateProblemInjector() {
|
---|
| 173 | return new EmptyOperator();
|
---|
| 174 | }
|
---|
[1230] | 175 |
|
---|
[1287] | 176 | protected internal abstract IOperator CreateSelector();
|
---|
[1230] | 177 |
|
---|
[1287] | 178 | protected internal abstract IOperator CreateCrossover();
|
---|
[1230] | 179 |
|
---|
[1287] | 180 | protected internal abstract IOperator CreateTreeCreator();
|
---|
[1230] | 181 |
|
---|
[1287] | 182 | protected internal abstract IOperator CreateFunctionLibraryInjector();
|
---|
| 183 |
|
---|
| 184 | protected internal virtual IOperator CreateGlobalInjector() {
|
---|
[1230] | 185 | VariableInjector injector = new VariableInjector();
|
---|
| 186 | injector.Name = "Global Injector";
|
---|
| 187 | injector.AddVariable(new HeuristicLab.Core.Variable("Generations", new IntData(0)));
|
---|
[1287] | 188 | injector.AddVariable(new HeuristicLab.Core.Variable("MutationRate", new DoubleData()));
|
---|
| 189 | injector.AddVariable(new HeuristicLab.Core.Variable("PopulationSize", new IntData()));
|
---|
| 190 | injector.AddVariable(new HeuristicLab.Core.Variable("Elites", new IntData()));
|
---|
[1230] | 191 | injector.AddVariable(new HeuristicLab.Core.Variable("Maximization", new BoolData(false)));
|
---|
[1287] | 192 | injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeHeight", new IntData()));
|
---|
| 193 | injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeSize", new IntData()));
|
---|
[1230] | 194 | injector.AddVariable(new HeuristicLab.Core.Variable("EvaluatedSolutions", new IntData(0)));
|
---|
| 195 | injector.AddVariable(new HeuristicLab.Core.Variable("TotalEvaluatedNodes", new DoubleData(0)));
|
---|
[1287] | 196 | injector.AddVariable(new HeuristicLab.Core.Variable("Parents", new IntData()));
|
---|
| 197 | injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData()));
|
---|
| 198 | injector.AddVariable(new HeuristicLab.Core.Variable("UseEstimatedTargetValue", new BoolData()));
|
---|
[1230] | 199 | return injector;
|
---|
| 200 | }
|
---|
| 201 |
|
---|
[1287] | 202 | protected internal abstract IOperator CreateManipulator();
|
---|
[1230] | 203 |
|
---|
[1287] | 204 | protected internal virtual IOperator CreateInitialization() {
|
---|
[1230] | 205 | CombinedOperator init = new CombinedOperator();
|
---|
| 206 | init.Name = "Initialization";
|
---|
| 207 | SequentialProcessor seq = new SequentialProcessor();
|
---|
| 208 | SubScopesCreater subScopesCreater = new SubScopesCreater();
|
---|
| 209 | subScopesCreater.GetVariableInfo("SubScopes").ActualName = "PopulationSize";
|
---|
| 210 | UniformSequentialSubScopesProcessor subScopesProc = new UniformSequentialSubScopesProcessor();
|
---|
| 211 | SequentialProcessor individualSeq = new SequentialProcessor();
|
---|
| 212 | OperatorExtractor treeCreater = new OperatorExtractor();
|
---|
| 213 | treeCreater.Name = "Tree generator (extr.)";
|
---|
| 214 | treeCreater.GetVariableInfo("Operator").ActualName = "Tree generator";
|
---|
| 215 | OperatorExtractor evaluator = new OperatorExtractor();
|
---|
| 216 | evaluator.Name = "Evaluator (extr.)";
|
---|
| 217 | evaluator.GetVariableInfo("Operator").ActualName = "Evaluator";
|
---|
| 218 | MeanSquaredErrorEvaluator validationEvaluator = new MeanSquaredErrorEvaluator();
|
---|
| 219 | validationEvaluator.GetVariableInfo("MSE").ActualName = "ValidationQuality";
|
---|
| 220 | validationEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
|
---|
| 221 | validationEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
|
---|
| 222 | Counter evalCounter = new Counter();
|
---|
| 223 | evalCounter.GetVariableInfo("Value").ActualName = "EvaluatedSolutions";
|
---|
| 224 | Sorter sorter = new Sorter();
|
---|
| 225 | sorter.GetVariableInfo("Descending").ActualName = "Maximization";
|
---|
| 226 | sorter.GetVariableInfo("Value").ActualName = "Quality";
|
---|
| 227 |
|
---|
| 228 | seq.AddSubOperator(subScopesCreater);
|
---|
| 229 | seq.AddSubOperator(subScopesProc);
|
---|
| 230 | seq.AddSubOperator(sorter);
|
---|
| 231 |
|
---|
| 232 | subScopesProc.AddSubOperator(individualSeq);
|
---|
| 233 | individualSeq.AddSubOperator(treeCreater);
|
---|
| 234 | individualSeq.AddSubOperator(evaluator);
|
---|
| 235 | individualSeq.AddSubOperator(validationEvaluator);
|
---|
| 236 | individualSeq.AddSubOperator(evalCounter);
|
---|
| 237 |
|
---|
| 238 | init.OperatorGraph.AddOperator(seq);
|
---|
| 239 | init.OperatorGraph.InitialOperator = seq;
|
---|
| 240 | return init;
|
---|
| 241 | }
|
---|
| 242 |
|
---|
[1287] | 243 | protected internal virtual IOperator CreateMainLoop() {
|
---|
[1230] | 244 | CombinedOperator main = new CombinedOperator();
|
---|
| 245 | SequentialProcessor seq = new SequentialProcessor();
|
---|
| 246 | IOperator childCreater = CreateChildCreater();
|
---|
| 247 | IOperator replacement = CreateReplacement();
|
---|
| 248 |
|
---|
| 249 | BestSolutionStorer solutionStorer = new BestSolutionStorer();
|
---|
| 250 | solutionStorer.GetVariableInfo("Quality").ActualName = "ValidationQuality";
|
---|
| 251 | solutionStorer.GetVariableInfo("BestSolution").ActualName = "BestValidationSolution";
|
---|
| 252 | solutionStorer.AddSubOperator(CreateBestSolutionProcessor());
|
---|
| 253 |
|
---|
| 254 | BestAverageWorstQualityCalculator qualityCalculator = new BestAverageWorstQualityCalculator();
|
---|
| 255 | BestAverageWorstQualityCalculator validationQualityCalculator = new BestAverageWorstQualityCalculator();
|
---|
[1287] | 256 | validationQualityCalculator.Name = "BestAverageWorstValidationQualityCalculator";
|
---|
| 257 | validationQualityCalculator.GetVariableInfo("Quality").ActualName = "ValidationQuality";
|
---|
[1230] | 258 | validationQualityCalculator.GetVariableInfo("BestQuality").ActualName = "BestValidationQuality";
|
---|
| 259 | validationQualityCalculator.GetVariableInfo("AverageQuality").ActualName = "AverageValidationQuality";
|
---|
| 260 | validationQualityCalculator.GetVariableInfo("WorstQuality").ActualName = "WorstValidationQuality";
|
---|
[1287] | 261 | IOperator loggingOperator = CreateLoggingOperator();
|
---|
[1230] | 262 | Counter counter = new Counter();
|
---|
| 263 | counter.GetVariableInfo("Value").ActualName = "Generations";
|
---|
[1287] | 264 | IOperator loopCondition = CreateLoopCondition(seq);
|
---|
[1230] | 265 |
|
---|
| 266 | seq.AddSubOperator(childCreater);
|
---|
| 267 | seq.AddSubOperator(replacement);
|
---|
| 268 | seq.AddSubOperator(solutionStorer);
|
---|
| 269 | seq.AddSubOperator(qualityCalculator);
|
---|
| 270 | seq.AddSubOperator(validationQualityCalculator);
|
---|
[1287] | 271 | seq.AddSubOperator(loggingOperator);
|
---|
[1230] | 272 | seq.AddSubOperator(counter);
|
---|
[1287] | 273 | seq.AddSubOperator(loopCondition);
|
---|
[1230] | 274 |
|
---|
| 275 | main.OperatorGraph.AddOperator(seq);
|
---|
| 276 | main.OperatorGraph.InitialOperator = seq;
|
---|
| 277 | return main;
|
---|
| 278 | }
|
---|
| 279 |
|
---|
[1287] | 280 | protected internal virtual IOperator CreateLoggingOperator() {
|
---|
[1230] | 281 | return new EmptyOperator();
|
---|
| 282 | }
|
---|
| 283 |
|
---|
[1287] | 284 | protected internal virtual IOperator CreateLoopCondition(IOperator loop) {
|
---|
| 285 | SequentialProcessor seq = new SequentialProcessor();
|
---|
| 286 | seq.Name = "Loop Condition";
|
---|
| 287 | LessThanComparator comparator = new LessThanComparator();
|
---|
| 288 | comparator.GetVariableInfo("LeftSide").ActualName = "Generations";
|
---|
| 289 | comparator.GetVariableInfo("RightSide").ActualName = "MaxGenerations";
|
---|
| 290 | comparator.GetVariableInfo("Result").ActualName = "GenerationsCondition";
|
---|
| 291 | ConditionalBranch cond = new ConditionalBranch();
|
---|
| 292 | cond.GetVariableInfo("Condition").ActualName = "GenerationsCondition";
|
---|
| 293 |
|
---|
| 294 | seq.AddSubOperator(comparator);
|
---|
| 295 | seq.AddSubOperator(cond);
|
---|
| 296 |
|
---|
| 297 | cond.AddSubOperator(loop);
|
---|
| 298 | return seq;
|
---|
| 299 | }
|
---|
| 300 |
|
---|
| 301 | protected internal virtual IOperator CreateBestSolutionProcessor() {
|
---|
| 302 | return new EmptyOperator();
|
---|
| 303 | }
|
---|
| 304 |
|
---|
| 305 | protected internal virtual IOperator CreateReplacement() {
|
---|
[1230] | 306 | CombinedOperator replacement = new CombinedOperator();
|
---|
| 307 | replacement.Name = "Replacement";
|
---|
| 308 | SequentialProcessor seq = new SequentialProcessor();
|
---|
| 309 | SequentialSubScopesProcessor seqScopeProc = new SequentialSubScopesProcessor();
|
---|
| 310 | SequentialProcessor selectedProc = new SequentialProcessor();
|
---|
| 311 | LeftSelector leftSelector = new LeftSelector();
|
---|
| 312 | leftSelector.GetVariableInfo("Selected").ActualName = "Elites";
|
---|
| 313 | RightReducer rightReducer = new RightReducer();
|
---|
| 314 |
|
---|
| 315 | SequentialProcessor remainingProc = new SequentialProcessor();
|
---|
| 316 | RightSelector rightSelector = new RightSelector();
|
---|
| 317 | rightSelector.GetVariableInfo("Selected").ActualName = "Elites";
|
---|
| 318 | LeftReducer leftReducer = new LeftReducer();
|
---|
| 319 | MergingReducer mergingReducer = new MergingReducer();
|
---|
| 320 | Sorter sorter = new Sorter();
|
---|
| 321 | sorter.GetVariableInfo("Descending").ActualName = "Maximization";
|
---|
| 322 | sorter.GetVariableInfo("Value").ActualName = "Quality";
|
---|
| 323 |
|
---|
| 324 | seq.AddSubOperator(seqScopeProc);
|
---|
| 325 | seqScopeProc.AddSubOperator(selectedProc);
|
---|
| 326 | selectedProc.AddSubOperator(leftSelector);
|
---|
| 327 | selectedProc.AddSubOperator(rightReducer);
|
---|
| 328 |
|
---|
| 329 | seqScopeProc.AddSubOperator(remainingProc);
|
---|
| 330 | remainingProc.AddSubOperator(rightSelector);
|
---|
| 331 | remainingProc.AddSubOperator(leftReducer);
|
---|
| 332 | seq.AddSubOperator(mergingReducer);
|
---|
| 333 | seq.AddSubOperator(sorter);
|
---|
| 334 | replacement.OperatorGraph.AddOperator(seq);
|
---|
| 335 | replacement.OperatorGraph.InitialOperator = seq;
|
---|
| 336 | return replacement;
|
---|
| 337 | }
|
---|
| 338 |
|
---|
[1287] | 339 | protected internal virtual IOperator CreateChildCreater() {
|
---|
[1230] | 340 | CombinedOperator childCreater = new CombinedOperator();
|
---|
| 341 | childCreater.Name = "Create children";
|
---|
| 342 | SequentialProcessor seq = new SequentialProcessor();
|
---|
| 343 | OperatorExtractor selector = new OperatorExtractor();
|
---|
| 344 | selector.Name = "Selector (extr.)";
|
---|
| 345 | selector.GetVariableInfo("Operator").ActualName = "Selector";
|
---|
[1335] | 346 |
|
---|
[1230] | 347 | SequentialSubScopesProcessor seqScopesProc = new SequentialSubScopesProcessor();
|
---|
| 348 | EmptyOperator emptyOpt = new EmptyOperator();
|
---|
| 349 | SequentialProcessor selectedProc = new SequentialProcessor();
|
---|
[1335] | 350 | ChildrenInitializer childInitializer = new ChildrenInitializer();
|
---|
| 351 | ((IntData)childInitializer.GetVariable("ParentsPerChild").Value).Data = 2;
|
---|
| 352 |
|
---|
[1230] | 353 | OperatorExtractor crossover = new OperatorExtractor();
|
---|
| 354 | crossover.Name = "Crossover (extr.)";
|
---|
| 355 | crossover.GetVariableInfo("Operator").ActualName = "Crossover";
|
---|
| 356 | UniformSequentialSubScopesProcessor individualProc = new UniformSequentialSubScopesProcessor();
|
---|
| 357 | SequentialProcessor individualSeqProc = new SequentialProcessor();
|
---|
| 358 | StochasticBranch cond = new StochasticBranch();
|
---|
| 359 | cond.GetVariableInfo("Probability").ActualName = "MutationRate";
|
---|
| 360 | OperatorExtractor manipulator = new OperatorExtractor();
|
---|
| 361 | manipulator.Name = "Manipulator (extr.)";
|
---|
| 362 | manipulator.GetVariableInfo("Operator").ActualName = "Manipulator";
|
---|
| 363 | OperatorExtractor evaluator = new OperatorExtractor();
|
---|
| 364 | evaluator.Name = "Evaluator (extr.)";
|
---|
| 365 | evaluator.GetVariableInfo("Operator").ActualName = "Evaluator";
|
---|
| 366 | MeanSquaredErrorEvaluator validationEvaluator = new MeanSquaredErrorEvaluator();
|
---|
| 367 | validationEvaluator.GetVariableInfo("MSE").ActualName = "ValidationQuality";
|
---|
| 368 | validationEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
|
---|
| 369 | validationEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
|
---|
| 370 | Counter evalCounter = new Counter();
|
---|
| 371 | evalCounter.GetVariableInfo("Value").ActualName = "EvaluatedSolutions";
|
---|
[1335] | 372 | SubScopesRemover parentRefRemover = new SubScopesRemover();
|
---|
[1230] | 373 |
|
---|
| 374 | Sorter sorter = new Sorter();
|
---|
| 375 | sorter.GetVariableInfo("Descending").ActualName = "Maximization";
|
---|
| 376 | sorter.GetVariableInfo("Value").ActualName = "Quality";
|
---|
| 377 |
|
---|
| 378 |
|
---|
| 379 | seq.AddSubOperator(selector);
|
---|
| 380 | seq.AddSubOperator(seqScopesProc);
|
---|
| 381 | seqScopesProc.AddSubOperator(emptyOpt);
|
---|
| 382 | seqScopesProc.AddSubOperator(selectedProc);
|
---|
[1335] | 383 | selectedProc.AddSubOperator(childInitializer);
|
---|
[1230] | 384 | selectedProc.AddSubOperator(individualProc);
|
---|
| 385 | individualProc.AddSubOperator(individualSeqProc);
|
---|
[1335] | 386 | individualSeqProc.AddSubOperator(crossover);
|
---|
[1230] | 387 | individualSeqProc.AddSubOperator(cond);
|
---|
| 388 | cond.AddSubOperator(manipulator);
|
---|
| 389 | individualSeqProc.AddSubOperator(evaluator);
|
---|
| 390 | individualSeqProc.AddSubOperator(validationEvaluator);
|
---|
| 391 | individualSeqProc.AddSubOperator(evalCounter);
|
---|
[1335] | 392 | individualSeqProc.AddSubOperator(parentRefRemover);
|
---|
[1230] | 393 | selectedProc.AddSubOperator(sorter);
|
---|
| 394 |
|
---|
| 395 | childCreater.OperatorGraph.AddOperator(seq);
|
---|
| 396 | childCreater.OperatorGraph.InitialOperator = seq;
|
---|
| 397 | return childCreater;
|
---|
| 398 | }
|
---|
| 399 |
|
---|
| 400 | public override object Clone(IDictionary<Guid, object> clonedObjects) {
|
---|
| 401 | AlgorithmBase clone = (AlgorithmBase)base.Clone(clonedObjects);
|
---|
| 402 | clonedObjects.Add(Guid, clone);
|
---|
| 403 | clone.engine = (SequentialEngine.SequentialEngine)Auxiliary.Clone(Engine, clonedObjects);
|
---|
| 404 | return clone;
|
---|
| 405 | }
|
---|
| 406 |
|
---|
[1287] | 407 | protected VariableInjector GetVariableInjector() {
|
---|
[1230] | 408 | CombinedOperator co1 = (CombinedOperator)Engine.OperatorGraph.InitialOperator;
|
---|
[1287] | 409 | // SequentialProcessor in GP
|
---|
[1230] | 410 | algorithm = (SequentialProcessor)co1.OperatorGraph.InitialOperator;
|
---|
[1287] | 411 | return (VariableInjector)algorithm.SubOperators[2];
|
---|
[1230] | 412 | }
|
---|
| 413 |
|
---|
[1287] | 414 | protected RandomInjector GetRandomInjector() {
|
---|
| 415 | CombinedOperator co1 = (CombinedOperator)Engine.OperatorGraph.InitialOperator;
|
---|
| 416 | // SequentialProcessor in GP
|
---|
| 417 | algorithm = (SequentialProcessor)co1.OperatorGraph.InitialOperator;
|
---|
| 418 | return (RandomInjector)algorithm.SubOperators[1];
|
---|
| 419 | }
|
---|
| 420 |
|
---|
[1230] | 421 | #region Persistence Methods
|
---|
| 422 | public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
|
---|
| 423 | XmlNode node = base.GetXmlNode(name, document, persistedObjects);
|
---|
| 424 | node.AppendChild(PersistenceManager.Persist("Engine", Engine, document, persistedObjects));
|
---|
| 425 | return node;
|
---|
| 426 | }
|
---|
| 427 | public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
|
---|
| 428 | base.Populate(node, restoredObjects);
|
---|
| 429 | engine = (SequentialEngine.SequentialEngine)PersistenceManager.Restore(node.SelectSingleNode("Engine"), restoredObjects);
|
---|
| 430 | }
|
---|
| 431 | #endregion
|
---|
| 432 | }
|
---|
| 433 | }
|
---|