Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.SGA.Hardwired/3.2/SGAMainWithHWControllStructures.cs @ 1584

Last change on this file since 1584 was 1576, checked in by dtraxing, 16 years ago

Changed version to 3.2 and updated SGAMain.(ticket #580)

File size: 4.1 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;
32using HeuristicLab.Logging;
33
34namespace HeuristicLab.SGA.Hardwired {
35  class SGAMainWithHWControllStructures : CombinedOperator {
36    public override string Description {
37      get { return @"Implements the SGAMain with hardwired control structures. Operators are delegated."; }
38    }
39
40    public SGAMainWithHWControllStructures()
41      : base() {
42      AddVariableInfo(new VariableInfo("Selector", "Selection strategy for SGA", typeof(OperatorBase), VariableKind.In));
43      AddVariableInfo(new VariableInfo("MaximumGenerations", "Maximum number of generations to create", typeof(IntData), VariableKind.In));
44
45      Name = "SGAMainWithHWControllStructures";
46    }
47
48    public override IOperation Apply(IScope scope) {
49
50      //base.Apply(scope); // noch nachfragen ob das auch in ordnung wäre
51      for (int i = 0; i < SubOperators.Count; i++) {
52        if (scope.GetVariable(SubOperators[i].Name) != null)
53          scope.RemoveVariable(SubOperators[i].Name);
54        scope.AddVariable(new Variable(SubOperators[i].Name, SubOperators[i]));
55      }
56
57      OperatorBase selector = (OperatorBase)GetVariableValue("Selector", scope, true);
58      OperatorBase createChildren = new CreateChildren();
59      OperatorBase createReplacement = new CreateReplacement();
60      QualityLogger ql = new QualityLogger();
61
62      BestAverageWorstQualityCalculator bawqc = new BestAverageWorstQualityCalculator();
63      DataCollector dc = new DataCollector();
64      ItemList<StringData> names = dc.GetVariable("VariableNames").GetValue<ItemList<StringData>>();
65      names.Add(new StringData("BestQuality"));
66      names.Add(new StringData("AverageQuality"));
67      names.Add(new StringData("WorstQuality"));
68
69      LinechartInjector lci = new LinechartInjector();
70      lci.GetVariableInfo("Linechart").ActualName = "Quality Linechart";
71      lci.GetVariable("NumberOfLines").GetValue<IntData>().Data = 3;
72
73      Counter c = new Counter();
74      c.GetVariableInfo("Value").ActualName = "Generations";
75
76      LessThanComparator ltc = new LessThanComparator();
77      ltc.GetVariableInfo("LeftSide").ActualName = "Generations";
78      ltc.GetVariableInfo("RightSide").ActualName = "MaximumGenerations";
79      ltc.GetVariableInfo("Result").ActualName = "GenerationsCondition";
80
81      IntData maxGenerations = GetVariableValue<IntData>("MaximumGenerations", scope, true);
82      //IntData nrOfGenerations = GetVariableValue<IntData>("Generations", scope, true);
83
84      for (int i = 0; i < maxGenerations.Data; i++) {
85        selector.Execute(scope);
86        createChildren.Execute(scope.SubScopes[1]);
87        createReplacement.Execute(scope);
88        ql.Execute(scope);
89        bawqc.Execute(scope);
90        dc.Execute(scope);
91        lci.Execute(scope);
92        //c.Execute(scope);
93        //ltc.Execute(scope);
94        //nrOfGenerations.Data = i;
95      }
96
97     
98      return null;
99    } // Apply
100  } // class SGAMainWithHWControllStructures
101} // namespace HeuristicLab.SGA.Hardwired
Note: See TracBrowser for help on using the repository browser.