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.Text;
|
---|
25 | using System.Linq;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.Permutation;
|
---|
29 | using HeuristicLab.Evolutionary;
|
---|
30 | using HeuristicLab.Operators;
|
---|
31 | using HeuristicLab.Routing.TSP;
|
---|
32 | using HeuristicLab.Logging;
|
---|
33 |
|
---|
34 | namespace 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 | }
|
---|
44 |
|
---|
45 | public override IOperation Apply(IScope scope) {
|
---|
46 | int nrOfGenerations = 1000;
|
---|
47 |
|
---|
48 | OperatorBase selector = (OperatorBase)GetVariableValue("Selector", scope, true);
|
---|
49 | OperatorBase createChildren = new CreateChildren();
|
---|
50 | OperatorBase createReplacement = new CreateReplacement();
|
---|
51 | QualityLogger ql = new QualityLogger();
|
---|
52 |
|
---|
53 | BestAverageWorstQualityCalculator bawqc = new BestAverageWorstQualityCalculator();
|
---|
54 | DataCollector dc = new DataCollector();
|
---|
55 | ItemList<StringData> names = dc.GetVariable("VariableNames").GetValue<ItemList<StringData>>();
|
---|
56 | names.Add(new StringData("BestQuality"));
|
---|
57 | names.Add(new StringData("AverageQuality"));
|
---|
58 | names.Add(new StringData("WorstQuality"));
|
---|
59 |
|
---|
60 | LinechartInjector lci = new LinechartInjector();
|
---|
61 | lci.GetVariableInfo("Linechart").ActualName = "Quality Linechart";
|
---|
62 | lci.GetVariable("NumberOfLines").GetValue<IntData>().Data = 3;
|
---|
63 |
|
---|
64 | Counter c = new Counter();
|
---|
65 | c.GetVariableInfo("Value").ActualName = "Generations";
|
---|
66 |
|
---|
67 | LessThanComparator ltc = new LessThanComparator();
|
---|
68 | ltc.GetVariableInfo("LeftSide").ActualName = "Generations";
|
---|
69 | ltc.GetVariableInfo("RightSide").ActualName = "MaximumGenerations";
|
---|
70 | ltc.GetVariableInfo("Result").ActualName = "GenerationsCondition";
|
---|
71 |
|
---|
72 | for (int i = 0; i < nrOfGenerations; i++) {
|
---|
73 | selector.Execute(scope);
|
---|
74 | createChildren.Execute(scope.SubScopes[1]);
|
---|
75 | createReplacement.Execute(scope);
|
---|
76 | ql.Execute(scope);
|
---|
77 | bawqc.Equals(scope);
|
---|
78 | dc.Execute(scope);
|
---|
79 | lci.Execute(scope);
|
---|
80 | c.Execute(scope);
|
---|
81 | ltc.Execute(scope);
|
---|
82 | }
|
---|
83 | return null;
|
---|
84 | } // Apply
|
---|
85 | } // class SGAMainWithHWControllStructures
|
---|
86 | } // namespace HeuristicLab.SGA.Hardwired
|
---|