Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.TS/3.3/TSOperator.cs @ 2994

Last change on this file since 2994 was 2982, checked in by abeham, 15 years ago

changed order of making a move tabu and performing the move #840

File size: 8.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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 HeuristicLab.Analysis;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Operators;
26using HeuristicLab.Parameters;
27
28namespace HeuristicLab.Algorithms.TS {
29  /// <summary>
30  /// An operator which represents a Tabu Search.
31  /// </summary>
32  [Item("TSOperator", "An operator which represents a Tabu Search.")]
33  public class TSOperator : AlgorithmOperator {
34    #region Parameter properties
35    public ValueLookupParameter<IRandom> RandomParameter {
36      get { return (ValueLookupParameter<IRandom>)Parameters["Random"]; }
37    }
38    public ValueLookupParameter<BoolData> MaximizationParameter {
39      get { return (ValueLookupParameter<BoolData>)Parameters["Maximization"]; }
40    }
41    public SubScopesLookupParameter<DoubleData> QualityParameter {
42      get { return (SubScopesLookupParameter<DoubleData>)Parameters["Quality"]; }
43    }
44    public ValueLookupParameter<IntData> MaximumIterationsParameter {
45      get { return (ValueLookupParameter<IntData>)Parameters["MaximumIterations"]; }
46    }
47    public ValueLookupParameter<IntData> TabuTenureParameter {
48      get { return (ValueLookupParameter<IntData>)Parameters["TabuTenure"]; }
49    }
50    public ValueLookupParameter<VariableCollection> ResultsParameter {
51      get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
52    }
53    private ScopeParameter CurrentScopeParameter {
54      get { return (ScopeParameter)Parameters["CurrentScope"]; }
55    }
56
57    public IScope CurrentScope {
58      get { return CurrentScopeParameter.ActualValue; }
59    }
60    #endregion
61
62    public TSOperator()
63      : base() {
64      #region Create parameters
65      Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
66      Parameters.Add(new ValueLookupParameter<BoolData>("Maximization", "True if the problem is a maximization problem, otherwise false."));
67      Parameters.Add(new SubScopesLookupParameter<DoubleData>("Quality", "The value which represents the quality of a solution."));
68      Parameters.Add(new ValueLookupParameter<IntData>("MaximumIterations", "The maximum number of generations which should be processed."));
69      Parameters.Add(new ValueLookupParameter<IntData>("TabuTenure", "The length of the tabu list, and also means the number of iterations a move is kept tabu"));
70      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
71      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the TS should be applied."));
72      #endregion
73
74      #region Create operators
75      VariableCreator variableCreator = new VariableCreator();
76      ResultsCollector resultsCollector = new ResultsCollector();
77      Placeholder moveGenerator = new Placeholder();
78      UniformSequentialSubScopesProcessor moveEvaluationProcessor = new UniformSequentialSubScopesProcessor();
79      Placeholder moveQualityEvaluator = new Placeholder();
80      Placeholder moveTabuEvaluator = new Placeholder();
81      SubScopesSorter moveQualitySorter = new SubScopesSorter();
82      Placeholder tabuSelector = new Placeholder();
83      SequentialSubScopesProcessor moveMakingProcessor = new SequentialSubScopesProcessor();
84      EmptyOperator emptyOp = new EmptyOperator();
85      UniformSequentialSubScopesProcessor actualMoveMakingProcessor = new UniformSequentialSubScopesProcessor();
86      Placeholder moveMaker = new Placeholder();
87      Placeholder moveTabuMaker = new Placeholder();
88      SubScopesRemover subScopesRemover = new SubScopesRemover();
89      IntCounter iterationsCounter = new IntCounter();
90      Comparator iterationsComparator = new Comparator();
91      ConditionalBranch iterationsTermination = new ConditionalBranch();
92      EmptyOperator finished = new EmptyOperator();
93
94      variableCreator.CollectedValues.Add(new ValueParameter<IntData>("Iterations", new IntData(0)));
95      variableCreator.CollectedValues.Add(new ValueParameter<DoubleData>("Best Quality", new DoubleData(0)));
96      variableCreator.CollectedValues.Add(new ValueParameter<DoubleData>("Best Move Quality", new DoubleData(0)));
97      variableCreator.CollectedValues.Add(new ValueParameter<DoubleData>("Average Move Quality", new DoubleData(0)));
98      variableCreator.CollectedValues.Add(new ValueParameter<DoubleData>("Worst Move Quality", new DoubleData(0)));
99      variableCreator.CollectedValues.Add(new ValueParameter<DataTable>("Qualities", new DataTable("Qualities")));
100      variableCreator.CollectedValues.Add(new ValueParameter<DataTable>("MoveQualities", new DataTable("MoveQualities")));
101
102      resultsCollector.CollectedValues.Add(new LookupParameter<IntData>("Iterations"));
103      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleData>("Best Quality"));
104      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleData>("Best Move Quality"));
105      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleData>("Average Move Quality"));
106      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleData>("Worst Move Quality"));
107      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Qualities"));
108      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("MoveQualities"));
109      resultsCollector.ResultsParameter.ActualName = "Results";
110
111      moveGenerator.Name = "MoveGenerator (placeholder)";
112      moveGenerator.OperatorParameter.ActualName = "MoveGenerator";
113
114      moveQualityEvaluator.Name = "MoveQualityEvaluator (placeholder)";
115      moveQualityEvaluator.OperatorParameter.ActualName = "MoveQualityEvaluator";
116
117      moveTabuEvaluator.Name = "MoveTabuEvaluator (placeholder)";
118      moveTabuEvaluator.OperatorParameter.ActualName = "MoveTabuEvaluator";
119
120      moveQualitySorter.DescendingParameter.ActualName = "Maximization";
121      moveQualitySorter.ValueParameter.ActualName = "MoveQuality";
122
123      tabuSelector.Name = "TabuSelector (placeholder)";
124      tabuSelector.OperatorParameter.ActualName = "TabuSelector";
125
126      moveMaker.Name = "MoveMaker (placeholder)";
127      moveMaker.OperatorParameter.ActualName = "MoveMaker";
128
129      moveTabuMaker.Name = "MoveTabuMaker (placeholder)";
130      moveTabuMaker.OperatorParameter.ActualName = "MoveTabuMaker";
131
132      subScopesRemover.RemoveAllSubScopes = true;
133
134      iterationsCounter.Increment = new IntData(1);
135      iterationsCounter.IncrementParameter.ActualName = "Iterations";
136
137      iterationsComparator.Comparison = new ComparisonData(Comparison.Less);
138      iterationsComparator.LeftSideParameter.ActualName = "Iterations";
139      iterationsComparator.RightSideParameter.ActualName = "MaximumIterations";
140      iterationsComparator.ResultParameter.ActualName = "IterationsCondition";
141
142      iterationsTermination.ConditionParameter.ActualName = "IterationsCondition";
143      #endregion
144
145      #region Create operator graph
146      OperatorGraph.InitialOperator = variableCreator;
147      variableCreator.Successor = resultsCollector;
148      resultsCollector.Successor = moveGenerator;
149      moveGenerator.Successor = moveEvaluationProcessor;
150      moveEvaluationProcessor.Operator = moveQualityEvaluator;
151      moveQualityEvaluator.Successor = moveTabuEvaluator;
152      moveEvaluationProcessor.Successor = moveQualitySorter;
153      moveQualitySorter.Successor = tabuSelector;
154      tabuSelector.Successor = moveMakingProcessor;
155      moveMakingProcessor.Operators.AddRange(new Operator[] { emptyOp, actualMoveMakingProcessor });
156      actualMoveMakingProcessor.Operator = moveTabuMaker;
157      moveTabuMaker.Successor = moveMaker;
158      moveMakingProcessor.Successor = subScopesRemover;
159      subScopesRemover.Successor = iterationsCounter;
160      iterationsCounter.Successor = iterationsComparator;
161      iterationsComparator.Successor = iterationsTermination;
162      iterationsTermination.TrueBranch = resultsCollector;
163      iterationsTermination.FalseBranch = finished;
164      #endregion
165    }
166  }
167}
Note: See TracBrowser for help on using the repository browser.