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