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