Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.FixedOperators/3.2/CreateChildren.cs @ 2075

Last change on this file since 2075 was 1646, checked in by dtraxing, 16 years ago

Renamed HeuristicLab.SGAHardWired Plugin to HeuristicLab.FixedOperators. (ticket #580)

File size: 3.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Text;
25using System.Linq;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Permutation;
29using HeuristicLab.Evolutionary;
30using HeuristicLab.Operators;
31using HeuristicLab.Routing.TSP;
32
33namespace HeuristicLab.FixedOperators {
34  class CreateChildren : OperatorBase {
35    ChildrenInitializer ci;
36    OperatorBase crossover;
37    OperatorBase mutator;
38    OperatorBase evaluator;
39    SubScopesRemover sr;
40    Counter counter;
41    Sorter sorter;
42    IRandom random;
43    DoubleData probability;
44   
45    public override string Description {
46      get { return @"Implements the control structures of CreateChildren hard wired. Operators are delegated."; }
47    }
48
49    public CreateChildren()
50      : base() {
51      ci = new ChildrenInitializer();
52 
53      // variables infos
54      AddVariableInfo(new VariableInfo("Random", "Pseudo random number generator", typeof(IRandom), VariableKind.In));
55      AddVariableInfo(new VariableInfo("MutationRate", "Probability to choose first branch", typeof(DoubleData), VariableKind.In));
56      AddVariableInfo(new VariableInfo("Crossover", "Crossover strategy for SGA", typeof(OperatorBase), VariableKind.In));
57      AddVariableInfo(new VariableInfo("Mutator", "Mutation strategy for SGA", typeof(OperatorBase), VariableKind.In));
58      AddVariableInfo(new VariableInfo("Evaluator", "Evaluation strategy for SGA", typeof(OperatorBase), VariableKind.In));
59
60      sr = new SubScopesRemover();
61      sr.GetVariableInfo("SubScopeIndex").Local = true;
62
63      counter = new Counter();
64      counter.GetVariableInfo("Value").ActualName = "EvaluatedSolutions";
65
66      sorter = new Sorter();
67      sorter.GetVariableInfo("Descending").ActualName = "Maximization";
68      sorter.GetVariableInfo("Value").ActualName = "Quality";
69    }
70
71    public override IOperation Apply(IScope scope) {
72      crossover = (OperatorBase)GetVariableValue("Crossover", scope, true);
73      mutator = (OperatorBase)GetVariableValue("Mutator", scope, true);
74      evaluator = GetVariableValue<OperatorBase>("Evaluator", scope, true);
75
76      random = GetVariableValue<IRandom>("Random", scope, true);
77      probability = GetVariableValue<DoubleData>("MutationRate", scope, true);
78
79      // ChildrenInitializer
80      ci.Apply(scope);
81      // UniformSequentialSubScopesProcessor
82      foreach (IScope s in scope.SubScopes) {
83        crossover.Execute(s);
84        // Stochastic Branch
85        if(random.NextDouble() < probability.Data)
86          mutator.Execute(s);
87        evaluator.Execute(s);
88        sr.Execute(s);
89        counter.Execute(s);
90      } // foreach
91
92      sorter.Execute(scope);
93
94      return null;
95    } // Apply
96  } // class CreateChildren
97} // namespace HeuristicLab.FixedOperators
Note: See TracBrowser for help on using the repository browser.