Changeset 3141
- Timestamp:
- 03/20/10 16:15:26 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearch.cs
r3131 r3141 74 74 get { return (ValueParameter<IntValue>)Parameters["MaximumIterations"]; } 75 75 } 76 private ValueParameter<IntValue> SampleSizeParameter { 77 get { return (ValueParameter<IntValue>)Parameters["SampleSize"]; } 78 } 76 79 #endregion 77 80 … … 124 127 #endregion 125 128 129 [StorableConstructor] 130 public TabuSearch(bool deserializing) : base() { } 126 131 public TabuSearch() 127 132 : base() { … … 135 140 Parameters.Add(new ValueParameter<IntValue>("TabuTenure", "The length of the tabu list.", new IntValue(10))); 136 141 Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(1000))); 142 Parameters.Add(new ValueParameter<IntValue>("SampleSize", "The neighborhood size for stochastic sampling move generators", new IntValue(20))); 137 143 138 144 RandomCreator randomCreator = new RandomCreator(); … … 163 169 } 164 170 165 [StorableConstructor]166 private TabuSearch(bool deserializing) : base() { }167 168 171 public override IDeepCloneable Clone(Cloner cloner) { 169 172 TabuSearch clone = (TabuSearch)base.Clone(cloner); … … 185 188 ParameterizeSolutionsCreator(); 186 189 ParameterizeMainLoop(); 190 ParameterizeMoveGenerators(); 187 191 ParameterizeMoveEvaluator(); 188 192 ParameterizeMoveMaker(); … … 204 208 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 205 209 base.Problem_EvaluatorChanged(sender, e); 210 } 211 protected override void Problem_VisualizerChanged(object sender, EventArgs e) { 212 ParameterizeStochasticOperator(Problem.Visualizer); 213 ParameterizeMainLoop(); 214 if (Problem.Visualizer != null) Problem.Visualizer.VisualizationParameter.ActualNameChanged += new EventHandler(Visualizer_VisualizationParameter_ActualNameChanged); 215 base.Problem_VisualizerChanged(sender, e); 206 216 } 207 217 protected override void Problem_OperatorsChanged(object sender, EventArgs e) { … … 222 232 UpdateMoveParameters(); 223 233 ParameterizeMainLoop(); 234 ParameterizeMoveGenerators(); 224 235 ParameterizeMoveEvaluator(); 225 236 ParameterizeMoveMaker(); … … 249 260 private void TabuMoveEvaluator_MoveTabuParameter_ActualNameChanged(object sender, EventArgs e) { 250 261 ParameterizeMainLoop(); 262 } 263 private void Visualizer_VisualizationParameter_ActualNameChanged(object sender, EventArgs e) { 264 ParameterizeMainLoop(); 265 } 266 private void SampleSizeParameter_NameChanged(object sender, EventArgs e) { 267 ParameterizeMoveGenerators(); 251 268 } 252 269 #endregion … … 260 277 op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged); 261 278 } 279 if (Problem.Visualizer != null) Problem.Visualizer.VisualizationParameter.ActualNameChanged += new EventHandler(Visualizer_VisualizationParameter_ActualNameChanged); 262 280 } 263 281 MoveGeneratorParameter.ValueChanged += new EventHandler(MoveGeneratorParameter_ValueChanged); 264 282 MoveEvaluatorParameter.ValueChanged += new EventHandler(MoveEvaluatorParameter_ValueChanged); 265 283 TabuMoveEvaluatorParameter.ValueChanged += new EventHandler(TabuMoveEvaluatorParameter_ValueChanged); 284 SampleSizeParameter.NameChanged += new EventHandler(SampleSizeParameter_NameChanged); 266 285 } 267 286 private void UpdateMoveGenerator() { … … 269 288 MoveGeneratorParameter.ValidValues.Clear(); 270 289 if (Problem != null) { 271 foreach (IMoveGenerator generator in Problem.Operators.OfType<IMoveGenerator>().OrderBy(x => x.Name)) 290 foreach (IMoveGenerator generator in Problem.Operators.OfType<IMoveGenerator>().OrderBy(x => x.Name)) { 272 291 MoveGeneratorParameter.ValidValues.Add(generator); 292 } 273 293 } 274 294 if (oldMoveGenerator != null && MoveGeneratorParameter.ValidValues.Any(x => x.GetType() == oldMoveGenerator.GetType())) … … 330 350 } 331 351 private void ParameterizeMainLoop() { 352 MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name; 332 353 MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 333 354 MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; … … 336 357 if (TabuMoveEvaluator != null) 337 358 MainLoop.MoveTabuParameter.ActualName = TabuMoveEvaluator.MoveTabuParameter.ActualName; 359 MainLoop.VisualizerParameter.ActualName = Problem.VisualizerParameter.Name; 360 if (Problem.Visualizer != null) 361 MainLoop.VisualizationParameter.ActualName = Problem.Visualizer.VisualizationParameter.ActualName; 338 362 } 339 363 private void ParameterizeStochasticOperator(IOperator op) { 340 364 if (op is IStochasticOperator) 341 365 ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; 366 } 367 private void ParameterizeMoveGenerators() { 368 if (Problem != null) { 369 foreach (IMultiMoveGenerator generator in Problem.Operators.OfType<IMultiMoveGenerator>()) 370 generator.SampleSizeParameter.ActualName = SampleSizeParameter.Name; 371 } 342 372 } 343 373 private void ParameterizeMoveEvaluator() { -
trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearchMainLoop.cs
r3132 r3141 34 34 [Item("TabuSearchMainLoop", "An operator which represents the main loop of a tabu search.")] 35 35 [StorableClass] 36 public class TabuSearchMainLoop : AlgorithmOperator {36 public sealed class TabuSearchMainLoop : AlgorithmOperator { 37 37 #region Parameter properties 38 38 public ValueLookupParameter<IRandom> RandomParameter { … … 45 45 get { return (LookupParameter<DoubleValue>)Parameters["Quality"]; } 46 46 } 47 public ValueLookupParameter<DoubleValue> BestKnownQualityParameter { 48 get { return (ValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 49 } 47 50 public LookupParameter<DoubleValue> MoveQualityParameter { 48 51 get { return (LookupParameter<DoubleValue>)Parameters["MoveQuality"]; } … … 57 60 get { return (ValueLookupParameter<IntValue>)Parameters["TabuTenure"]; } 58 61 } 62 public ValueLookupParameter<IOperator> MoveGeneratorParameter { 63 get { return (ValueLookupParameter<IOperator>)Parameters["MoveGenerator"]; } 64 } 65 public ValueLookupParameter<IOperator> MoveEvaluatorParameter { 66 get { return (ValueLookupParameter<IOperator>)Parameters["MoveEvaluator"]; } 67 } 68 public ValueLookupParameter<IOperator> MoveMakerParameter { 69 get { return (ValueLookupParameter<IOperator>)Parameters["MoveMaker"]; } 70 } 71 public ValueLookupParameter<IOperator> TabuMoveEvaluatorParameter { 72 get { return (ValueLookupParameter<IOperator>)Parameters["TabuMoveEvaluator"]; } 73 } 74 public ValueLookupParameter<IOperator> TabuMoveMakerParameter { 75 get { return (ValueLookupParameter<IOperator>)Parameters["TabuMoveMaker"]; } 76 } 77 public ValueLookupParameter<IOperator> VisualizerParameter { 78 get { return (ValueLookupParameter<IOperator>)Parameters["Visualizer"]; } 79 } 80 public LookupParameter<IItem> VisualizationParameter { 81 get { return (LookupParameter<IItem>)Parameters["Visualization"]; } 82 } 59 83 public ValueLookupParameter<VariableCollection> ResultsParameter { 60 84 get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; } 61 }62 public ValueLookupParameter<IOperator> MoveGeneratorParameter {63 get { return (ValueLookupParameter<IOperator>)Parameters["MoveGenerator"]; }64 }65 public ValueLookupParameter<IOperator> MoveEvaluatorParameter {66 get { return (ValueLookupParameter<IOperator>)Parameters["MoveEvaluator"]; }67 }68 public ValueLookupParameter<IOperator> MoveMakerParameter {69 get { return (ValueLookupParameter<IOperator>)Parameters["MoveMaker"]; }70 }71 public ValueLookupParameter<IOperator> TabuMoveEvaluatorParameter {72 get { return (ValueLookupParameter<IOperator>)Parameters["TabuMoveEvaluator"]; }73 }74 public ValueLookupParameter<IOperator> TabuMoveMakerParameter {75 get { return (ValueLookupParameter<IOperator>)Parameters["TabuMoveMaker"]; }76 }77 78 private ScopeParameter CurrentScopeParameter {79 get { return (ScopeParameter)Parameters["CurrentScope"]; }80 }81 public IScope CurrentScope {82 get { return CurrentScopeParameter.ActualValue; }83 85 } 84 86 #endregion … … 90 92 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); 91 93 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); 94 Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far.")); 92 95 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The value which represents the quality of a move.")); 93 96 Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The value that indicates if a move is tabu or not.")); 94 97 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.")); 95 98 Parameters.Add(new ValueLookupParameter<IntValue>("TabuTenure", "The length of the tabu list, and also means the number of iterations a move is kept tabu")); 96 Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored.")); 97 99 98 100 Parameters.Add(new ValueLookupParameter<IOperator>("MoveGenerator", "The operator that generates the moves.")); 99 101 Parameters.Add(new ValueLookupParameter<IOperator>("MoveMaker", "The operator that performs a move and updates the quality.")); … … 102 104 Parameters.Add(new ValueLookupParameter<IOperator>("TabuMoveMaker", "The operator that declares a move tabu.")); 103 105 104 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the TS should be applied.")); 106 Parameters.Add(new ValueLookupParameter<IOperator>("Visualizer", "The operator used to visualize solutions.")); 107 Parameters.Add(new LookupParameter<IItem>("Visualization", "The item which represents the visualization of solutions.")); 108 Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored.")); 105 109 #endregion 106 110 … … 108 112 TabuListCreator tabuListCreator = new TabuListCreator(); 109 113 VariableCreator variableCreator = new VariableCreator(); 110 BestQualityMemorizer bestQualityMemorizer = new BestQualityMemorizer(); 114 BestQualityMemorizer bestQualityMemorizer1 = new BestQualityMemorizer(); 115 BestQualityMemorizer bestQualityMemorizer2 = new BestQualityMemorizer(); 116 QualityDifferenceCalculator qualityDifferenceCalculator1 = new QualityDifferenceCalculator(); 117 Placeholder visualizer1 = new Placeholder(); 111 118 ResultsCollector resultsCollector = new ResultsCollector(); 112 119 UniformSequentialSubScopesProcessor mainProcessor = new UniformSequentialSubScopesProcessor(); … … 126 133 IntCounter iterationsCounter = new IntCounter(); 127 134 Comparator iterationsComparator = new Comparator(); 135 BestQualityMemorizer bestQualityMemorizer3 = new BestQualityMemorizer(); 136 BestQualityMemorizer bestQualityMemorizer4 = new BestQualityMemorizer(); 137 QualityDifferenceCalculator qualityDifferenceCalculator2 = new QualityDifferenceCalculator(); 138 Placeholder visualizer2 = new Placeholder(); 128 139 ConditionalBranch iterationsTermination = new ConditionalBranch(); 129 EmptyOperator finished = new EmptyOperator();130 140 131 141 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0))); … … 135 145 variableCreator.CollectedValues.Add(new ValueParameter<DataTable>("MoveQualities", new DataTable("MoveQualities"))); 136 146 147 bestQualityMemorizer1.BestQualityParameter.ActualName = "BestQuality"; 148 bestQualityMemorizer1.MaximizationParameter.ActualName = MaximizationParameter.Name; 149 bestQualityMemorizer1.QualityParameter.ActualName = QualityParameter.Name; 150 151 bestQualityMemorizer2.BestQualityParameter.ActualName = BestKnownQualityParameter.Name; 152 bestQualityMemorizer2.MaximizationParameter.ActualName = MaximizationParameter.Name; 153 bestQualityMemorizer2.QualityParameter.ActualName = QualityParameter.Name; 154 155 qualityDifferenceCalculator1.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest"; 156 qualityDifferenceCalculator1.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name; 157 qualityDifferenceCalculator1.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest"; 158 qualityDifferenceCalculator1.SecondQualityParameter.ActualName = "BestQuality"; 159 160 visualizer1.Name = "Visualizer (placeholder)"; 161 visualizer1.OperatorParameter.ActualName = VisualizerParameter.Name; 162 137 163 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iterations")); 138 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality" ) { ActualName = "BestQuality" });164 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality")); 139 165 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Move Quality")); 140 166 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Average Move Quality")); 141 167 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Worst Move Quality")); 142 168 resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("MoveQualities")); 169 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name)); 170 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Absolute Difference of Best Known Quality to Best Quality", null, "AbsoluteDifferenceBestKnownToBest")); 171 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Relative Difference of Best Known Quality to Best Quality", null, "RelativeDifferenceBestKnownToBest")); 172 resultsCollector.CollectedValues.Add(new LookupParameter<IItem>("Solution Visualization", null, VisualizationParameter.Name)); 143 173 resultsCollector.ResultsParameter.ActualName = "Results"; 144 174 … … 146 176 147 177 moveGenerator.Name = "MoveGenerator (placeholder)"; 148 moveGenerator.OperatorParameter.ActualName = "MoveGenerator";178 moveGenerator.OperatorParameter.ActualName = MoveGeneratorParameter.Name; 149 179 150 180 moveEvaluator.Name = "MoveEvaluator (placeholder)"; 151 moveEvaluator.OperatorParameter.ActualName = "MoveEvaluator";181 moveEvaluator.OperatorParameter.ActualName = MoveEvaluatorParameter.Name; 152 182 153 183 tabuMoveEvaluator.Name = "TabuMoveEvaluator (placeholder)"; 154 tabuMoveEvaluator.OperatorParameter.ActualName = "TabuMoveEvaluator";155 156 moveQualitySorter.DescendingParameter.ActualName = "Maximization";157 moveQualitySorter.ValueParameter.ActualName = "MoveQuality";184 tabuMoveEvaluator.OperatorParameter.ActualName = TabuMoveEvaluatorParameter.Name; 185 186 moveQualitySorter.DescendingParameter.ActualName = MaximizationParameter.Name; 187 moveQualitySorter.ValueParameter.ActualName = MoveQualityParameter.Name; 158 188 159 189 bestAverageWorstMoveQualityCalculator.AverageQualityParameter.ActualName = "Average Move Quality"; 160 190 bestAverageWorstMoveQualityCalculator.BestQualityParameter.ActualName = "Best Move Quality"; 161 191 bestAverageWorstMoveQualityCalculator.MaximizationParameter.ActualName = "Maximization"; 162 bestAverageWorstMoveQualityCalculator.QualityParameter.ActualName = "MoveQuality";192 bestAverageWorstMoveQualityCalculator.QualityParameter.ActualName = MoveQualityParameter.Name; 163 193 bestAverageWorstMoveQualityCalculator.WorstQualityParameter.ActualName = "Worst Move Quality"; 164 165 moveMakingProcessor.Name = "MoveMaking processor (UniformSequentialSubScopesProcessor)"; 166 167 tabuMoveMaker.Name = "TabuMoveMaker (placeholder)"; 168 tabuMoveMaker.OperatorParameter.ActualName = "TabuMoveMaker"; 169 170 moveMaker.Name = "MoveMaker (placeholder)"; 171 moveMaker.OperatorParameter.ActualName = "MoveMaker"; 172 194 173 195 valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Move Quality")); 174 196 valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Average Move Quality")); … … 176 198 valuesCollector.DataTableParameter.ActualName = "MoveQualities"; 177 199 200 moveMakingProcessor.Name = "MoveMaking processor (UniformSequentialSubScopesProcessor)"; 201 202 tabuMoveMaker.Name = "TabuMoveMaker (placeholder)"; 203 tabuMoveMaker.OperatorParameter.ActualName = TabuMoveMakerParameter.Name; 204 205 moveMaker.Name = "MoveMaker (placeholder)"; 206 moveMaker.OperatorParameter.ActualName = MoveMakerParameter.Name; 207 178 208 subScopesRemover.RemoveAllSubScopes = true; 179 209 … … 185 215 iterationsComparator.Comparison = new Comparison(ComparisonType.Less); 186 216 iterationsComparator.LeftSideParameter.ActualName = "Iterations"; 187 iterationsComparator.RightSideParameter.ActualName = "MaximumIterations";217 iterationsComparator.RightSideParameter.ActualName = MaximumIterationsParameter.Name; 188 218 iterationsComparator.ResultParameter.ActualName = "IterationsCondition"; 219 220 bestQualityMemorizer3.BestQualityParameter.ActualName = "BestQuality"; 221 bestQualityMemorizer3.MaximizationParameter.ActualName = MaximizationParameter.Name; 222 bestQualityMemorizer3.QualityParameter.ActualName = QualityParameter.Name; 223 224 bestQualityMemorizer4.BestQualityParameter.ActualName = BestKnownQualityParameter.Name; 225 bestQualityMemorizer4.MaximizationParameter.ActualName = MaximizationParameter.Name; 226 bestQualityMemorizer4.QualityParameter.ActualName = QualityParameter.Name; 227 228 qualityDifferenceCalculator2.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest"; 229 qualityDifferenceCalculator2.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name; 230 qualityDifferenceCalculator2.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest"; 231 qualityDifferenceCalculator2.SecondQualityParameter.ActualName = "BestQuality"; 232 233 visualizer2.Name = "Visualizer (placeholder)"; 234 visualizer2.OperatorParameter.ActualName = VisualizerParameter.Name; 189 235 190 236 iterationsTermination.Name = "Iterations Termination Condition"; … … 195 241 OperatorGraph.InitialOperator = tabuListCreator; 196 242 tabuListCreator.Successor = variableCreator; 197 variableCreator.Successor = bestQualityMemorizer; 198 bestQualityMemorizer.Successor = resultsCollector; 243 variableCreator.Successor = bestQualityMemorizer1; 244 bestQualityMemorizer1.Successor = bestQualityMemorizer2; 245 bestQualityMemorizer2.Successor = qualityDifferenceCalculator1; 246 qualityDifferenceCalculator1.Successor = visualizer1; 247 visualizer1.Successor = resultsCollector; 199 248 resultsCollector.Successor = mainProcessor; 200 249 mainProcessor.Operator = moveGenerator; 201 mainProcessor.Successor = valuesCollector;250 mainProcessor.Successor = iterationsCounter; 202 251 moveGenerator.Successor = moveEvaluationProcessor; 203 252 moveEvaluationProcessor.Operator = moveEvaluator; 204 253 moveEvaluationProcessor.Successor = moveQualitySorter; 205 254 moveEvaluator.Successor = tabuMoveEvaluator; 255 tabuMoveEvaluator.Successor = null; 206 256 moveQualitySorter.Successor = bestAverageWorstMoveQualityCalculator; 207 bestAverageWorstMoveQualityCalculator.Successor = tabuSelector; 257 bestAverageWorstMoveQualityCalculator.Successor = valuesCollector; 258 valuesCollector.Successor = tabuSelector; 208 259 tabuSelector.Successor = rightReducer; 209 260 rightReducer.Successor = moveMakingProcessor; … … 211 262 moveMakingProcessor.Successor = subScopesRemover; 212 263 tabuMoveMaker.Successor = moveMaker; 213 valuesCollector.Successor = iterationsCounter; 264 moveMaker.Successor = null; 265 subScopesRemover.Successor = null; 214 266 iterationsCounter.Successor = iterationsComparator; 215 iterationsComparator.Successor = iterationsTermination; 216 iterationsTermination.TrueBranch = bestQualityMemorizer; 217 iterationsTermination.FalseBranch = finished; 267 iterationsComparator.Successor = bestQualityMemorizer3; 268 bestQualityMemorizer3.Successor = bestQualityMemorizer4; 269 bestQualityMemorizer4.Successor = qualityDifferenceCalculator2; 270 qualityDifferenceCalculator2.Successor = visualizer2; 271 visualizer2.Successor = iterationsTermination; 272 iterationsTermination.TrueBranch = mainProcessor; 273 iterationsTermination.FalseBranch = null; 218 274 #endregion 219 275 }
Note: See TracChangeset
for help on using the changeset viewer.