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