Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.SGA.Hardwired/3.3/CreateChildren.cs @ 1543

Last change on this file since 1543 was 1543, checked in by dtraxing, 15 years ago

initial commit hardwired algorithms (ticket #580)
added HeuristicLab.SGA.Hardwired to HeuristicLab.sln and CopyAssemblies.cmd

File size: 4.2 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.SGA.Hardwired {
34  class CreateChildren : OperatorBase {
35    ChildrenInitializer ci;
36    OrderCrossover oc;
37    InversionManipulator im;
38    RoundedEuclideanPathTSPEvaluator repTSPe;
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 functionality of method SGAMain hard wired."; }
47    }
48
49    public CreateChildren()
50      : base() {
51      ci = new ChildrenInitializer();
52      oc = new OrderCrossover();
53      im = new InversionManipulator();
54      repTSPe = new RoundedEuclideanPathTSPEvaluator();
55 
56      // variables for stochastic branch
57      AddVariableInfo(new VariableInfo("Random", "Pseudo random number generator", typeof(IRandom), VariableKind.In));
58      AddVariableInfo(new VariableInfo("MutationRate", "Probability to choose first branch", typeof(DoubleData), 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    void valueInfo_ActualNameChanged(object sender, EventArgs e) {
72      throw new NotImplementedException();
73    } // SGAMain()
74
75    public override IOperation Apply(IScope scope) {
76
77      random = GetVariableValue<IRandom>("Random", scope, true);
78      probability = GetVariableValue<DoubleData>("MutationRate", scope, true);
79
80      // ChildrenInitializer
81      ci.Apply(scope);
82      // UniformSequentialSubScopesProcessor
83      foreach (IScope s in scope.SubScopes) {
84        oc.Execute(s);
85       
86        if(random.NextDouble() < probability.Data)
87          im.Execute(s);
88        repTSPe.Execute(s);
89        sr.Execute(s);
90        counter.Execute(s);
91      } // foreach
92      // set evaluated solutions
93      //IntData value = GetVariableValue<IntData>("EvaluatedSolutions", scope, true);
94      //value.Data = counter;
95
96      // sort with using of operator
97      sorter.Execute(scope);
98
99      // sort scopes
100      //bool descending = false;//GetVariableValue<BoolData>("Descending", scope, true).Data;
101      //double[] keys = new double[scope.SubScopes.Count];
102      //int[] sequence = new int[keys.Length];
103
104      //for (int i = 0; i < keys.Length; i++) {
105      //  keys[i] = scope.SubScopes[i].GetVariableValue<DoubleData>("Quality", false).Data;
106      //  sequence[i] = i;
107      //}
108
109      //Array.Sort<double, int>(keys, sequence);
110
111      //if (descending) {
112      //  int temp;
113      //  for (int i = 0; i < sequence.Length / 2; i++) {
114      //    temp = sequence[i];
115      //    sequence[i] = sequence[sequence.Length - 1 - i];
116      //    sequence[sequence.Length - 1 - i] = temp;
117      //  }
118      //}
119      //scope.ReorderSubScopes(sequence);
120
121      return null;
122    } // Apply
123
124  } // class SGAMain
125
126} // namespace HeuristicLab.SGA
Note: See TracBrowser for help on using the repository browser.