Changeset 3621 for trunk/sources/HeuristicLab.Algorithms.LocalSearch
- Timestamp:
- 05/05/10 02:52:59 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearch.cs
r3616 r3621 33 33 using HeuristicLab.PluginInfrastructure; 34 34 using HeuristicLab.Random; 35 using HeuristicLab.Analysis; 35 36 36 37 namespace HeuristicLab.Algorithms.LocalSearch { … … 71 72 get { return (ValueParameter<IntValue>)Parameters["SampleSize"]; } 72 73 } 74 private ValueParameter<MultiAnalyzer> MoveAnalyzerParameter { 75 get { return (ValueParameter<MultiAnalyzer>)Parameters["MoveAnalyzer"]; } 76 } 77 private ValueParameter<MultiAnalyzer> AnalyzerParameter { 78 get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; } 79 } 73 80 #endregion 74 81 … … 102 109 set { SampleSizeParameter.Value = value; } 103 110 } 111 public MultiAnalyzer MoveAnalyzer { 112 get { return MoveAnalyzerParameter.Value; } 113 set { MoveAnalyzerParameter.Value = value; } 114 } 115 public MultiAnalyzer Analyzer { 116 get { return AnalyzerParameter.Value; } 117 set { AnalyzerParameter.Value = value; } 118 } 104 119 private RandomCreator RandomCreator { 105 120 get { return (RandomCreator)OperatorGraph.InitialOperator; } … … 111 126 get { return (LocalSearchMainLoop)SolutionsCreator.Successor; } 112 127 } 113 #endregion 114 128 private BestAverageWorstQualityAnalyzer moveQualityAnalyzer; 129 #endregion 130 131 [StorableConstructor] 132 private LocalSearch(bool deserializing) : base(deserializing) { } 115 133 public LocalSearch() 116 134 : base() { … … 122 140 Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(1000))); 123 141 Parameters.Add(new ValueParameter<IntValue>("SampleSize", "Number of moves that MultiMoveGenerators should create. This is ignored for Exhaustive- and SingleMoveGenerators.", new IntValue(100))); 124 142 Parameters.Add(new ValueParameter<MultiAnalyzer>("MoveAnalyzer", "The operator used to analyze the moves in each iteration.", new MultiAnalyzer())); 143 Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each iteration.", new MultiAnalyzer())); 144 125 145 RandomCreator randomCreator = new RandomCreator(); 126 146 SolutionsCreator solutionsCreator = new SolutionsCreator(); … … 144 164 lsMainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; 145 165 lsMainLoop.ResultsParameter.ActualName = "Results"; 166 lsMainLoop.MoveAnalyzerParameter.ActualName = MoveAnalyzerParameter.Name; 167 lsMainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name; 146 168 147 169 Initialize(); 148 170 } 149 [StorableConstructor]150 private LocalSearch(bool deserializing) : base(deserializing) { }151 171 152 172 public override IDeepCloneable Clone(Cloner cloner) { … … 173 193 ParameterizeMoveEvaluators(); 174 194 ParameterizeMoveMakers(); 195 ParameterizeAnalyzers(); 175 196 UpdateMoveGenerator(); 176 197 UpdateMoveParameters(); 198 UpdateAnalyzers(); 177 199 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 178 200 base.OnProblemChanged(); … … 189 211 ParameterizeMoveEvaluators(); 190 212 ParameterizeMoveMakers(); 213 ParameterizeAnalyzers(); 191 214 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 192 215 base.Problem_EvaluatorChanged(sender, e); … … 202 225 UpdateMoveGenerator(); 203 226 UpdateMoveParameters(); 227 UpdateAnalyzers(); 204 228 ParameterizeMainLoop(); 205 229 ParameterizeMoveEvaluators(); … … 219 243 ParameterizeMoveEvaluators(); 220 244 ParameterizeMoveMakers(); 245 ParameterizeAnalyzers(); 221 246 } 222 247 private void MoveEvaluator_MoveQualityParameter_ActualNameChanged(object sender, EventArgs e) { … … 224 249 ParameterizeMoveEvaluators(); 225 250 ParameterizeMoveMakers(); 251 ParameterizeAnalyzers(); 226 252 } 227 253 #endregion … … 230 256 [StorableHook(HookType.AfterDeserialization)] 231 257 private void Initialize() { 258 InitializeAnalyzers(); 259 UpdateAnalyzers(); 232 260 if (Problem != null) { 233 261 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); … … 238 266 MoveGeneratorParameter.ValueChanged += new EventHandler(MoveGeneratorParameter_ValueChanged); 239 267 MoveEvaluatorParameter.ValueChanged += new EventHandler(MoveEvaluatorParameter_ValueChanged); 268 } 269 private void InitializeAnalyzers() { 270 moveQualityAnalyzer = new BestAverageWorstQualityAnalyzer(); 271 ParameterizeAnalyzers(); 240 272 } 241 273 private void UpdateMoveGenerator() { … … 281 313 } 282 314 } 315 private void UpdateAnalyzers() { 316 Analyzer.Operators.Clear(); 317 MoveAnalyzer.Operators.Clear(); 318 MoveAnalyzer.Operators.Add(moveQualityAnalyzer); 319 /*if (Problem != null) { 320 foreach (ISolutionAnalyzer analyzer in Problem.Operators.OfType<ISolutionAnalyzer>().OrderBy(x => x.Name)) 321 Analyzer.Operators.Add(analyzer); 322 }*/ 323 } 283 324 private void ClearMoveParameters() { 284 325 MoveMakerParameter.ValidValues.Clear(); … … 312 353 } 313 354 } 355 private void ParameterizeAnalyzers() { 356 moveQualityAnalyzer.ResultsParameter.ActualName = "Results"; 357 if (Problem != null) { 358 moveQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 359 if (MoveEvaluator != null) 360 moveQualityAnalyzer.QualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName; 361 moveQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name; 362 } 363 } 314 364 #endregion 315 365 } -
trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearchMainLoop.cs
r3376 r3621 68 68 get { return (ValueLookupParameter<IOperator>)Parameters["MoveMaker"]; } 69 69 } 70 public ValueLookupParameter<IOperator> VisualizerParameter {71 get { return (ValueLookupParameter<IOperator>)Parameters[" Visualizer"]; }72 } 73 public LookupParameter<IItem> VisualizationParameter {74 get { return ( LookupParameter<IItem>)Parameters["Visualization"]; }70 public ValueLookupParameter<IOperator> MoveAnalyzerParameter { 71 get { return (ValueLookupParameter<IOperator>)Parameters["MoveAnalyzer"]; } 72 } 73 public ValueLookupParameter<IOperator> AnalyzerParameter { 74 get { return (ValueLookupParameter<IOperator>)Parameters["Analyzer"]; } 75 75 } 76 76 … … 104 104 Parameters.Add(new ValueLookupParameter<IOperator>("MoveEvaluator", "The operator that evaluates a move.")); 105 105 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."));106 Parameters.Add(new ValueLookupParameter<IOperator>("MoveAnalyzer", "The operator used to analyze the moves in each iteration.")); 107 Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze each iteration.")); 108 108 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the TS should be applied.")); 109 109 #endregion … … 111 111 #region Create operators 112 112 VariableCreator variableCreator = new VariableCreator(); 113 BestQualityMemorizer bestQualityMemorizer1 = new BestQualityMemorizer(); 114 BestQualityMemorizer bestQualityMemorizer2 = new BestQualityMemorizer(); 115 DataTableValuesCollector dataTableValuesCollector1 = new DataTableValuesCollector(); 116 QualityDifferenceCalculator qualityDifferenceCalculator1 = new QualityDifferenceCalculator(); 117 Placeholder visualizer1 = new Placeholder(); 118 ResultsCollector resultsCollector = new ResultsCollector(); 113 ResultsCollector resultsCollector1 = new ResultsCollector(); 114 UniformSubScopesProcessor uniformSubScopesProcessor0 = new UniformSubScopesProcessor(); 115 Placeholder analyzer1 = new Placeholder(); 119 116 UniformSubScopesProcessor mainProcessor = new UniformSubScopesProcessor(); 120 117 Placeholder moveGenerator = new Placeholder(); 121 118 UniformSubScopesProcessor moveEvaluationProcessor = new UniformSubScopesProcessor(); 122 119 Placeholder moveEvaluator = new Placeholder(); 120 Placeholder moveAnalyzer = new Placeholder(); 123 121 BestSelector bestSelector = new BestSelector(); 124 122 RightReducer rightReducer = new RightReducer(); … … 130 128 IntCounter iterationsCounter = new IntCounter(); 131 129 Comparator iterationsComparator = new Comparator(); 132 BestQualityMemorizer bestQualityMemorizer3 = new BestQualityMemorizer(); 133 BestQualityMemorizer bestQualityMemorizer4 = new BestQualityMemorizer(); 134 DataTableValuesCollector dataTableValuesCollector2 = new DataTableValuesCollector(); 135 QualityDifferenceCalculator qualityDifferenceCalculator2 = new QualityDifferenceCalculator(); 136 Placeholder visualizer2 = new Placeholder(); 130 ResultsCollector resultsCollector2 = new ResultsCollector(); 131 UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor(); 132 Placeholder analyzer2 = new Placeholder(); 137 133 ConditionalBranch iterationsTermination = new ConditionalBranch(); 138 134 139 135 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0))); 140 136 141 bestQualityMemorizer1.BestQualityParameter.ActualName = BestKnownQualityParameter.Name; 142 bestQualityMemorizer1.MaximizationParameter.ActualName = MaximizationParameter.Name; 143 bestQualityMemorizer1.QualityParameter.ActualName = QualityParameter.Name; 144 145 bestQualityMemorizer2.BestQualityParameter.ActualName = "BestQuality"; 146 bestQualityMemorizer2.MaximizationParameter.ActualName = MaximizationParameter.Name; 147 bestQualityMemorizer2.QualityParameter.ActualName = QualityParameter.Name; 148 149 dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("BestQuality")); 150 dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name)); 151 dataTableValuesCollector1.DataTableParameter.ActualName = "Qualities"; 152 153 qualityDifferenceCalculator1.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest"; 154 qualityDifferenceCalculator1.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name; 155 qualityDifferenceCalculator1.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest"; 156 qualityDifferenceCalculator1.SecondQualityParameter.ActualName = "BestQuality"; 157 158 visualizer1.Name = "Visualizer (placeholder)"; 159 visualizer1.OperatorParameter.ActualName = VisualizerParameter.Name; 160 161 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iterations")); 162 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality")); 163 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name)); 164 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Absolute Difference of Best Known Quality to Best Quality", null, "AbsoluteDifferenceBestKnownToBest")); 165 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Relative Difference of Best Known Quality to Best Quality", null, "RelativeDifferenceBestKnownToBest")); 166 resultsCollector.CollectedValues.Add(new LookupParameter<IItem>("Solution Visualization", null, VisualizationParameter.Name)); 167 resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Qualities")); 168 resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name; 137 resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Iterations")); 138 resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name; 139 140 analyzer1.Name = "Analyzer (placeholder)"; 141 analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name; 169 142 170 143 mainProcessor.Name = "Solution processor (UniformSubScopesProcessor)"; … … 175 148 moveEvaluator.Name = "MoveEvaluator (placeholder)"; 176 149 moveEvaluator.OperatorParameter.ActualName = MoveEvaluatorParameter.Name; 150 151 moveAnalyzer.Name = "MoveAnalyzer (placeholder)"; 152 moveAnalyzer.OperatorParameter.ActualName = MoveAnalyzerParameter.Name; 177 153 178 154 bestSelector.CopySelected = new BoolValue(false); … … 204 180 iterationsComparator.ResultParameter.ActualName = "Terminate"; 205 181 206 bestQualityMemorizer3.BestQualityParameter.ActualName = BestKnownQualityParameter.Name; 207 bestQualityMemorizer3.MaximizationParameter.ActualName = MaximizationParameter.Name; 208 bestQualityMemorizer3.QualityParameter.ActualName = QualityParameter.Name; 209 210 bestQualityMemorizer4.BestQualityParameter.ActualName = "BestQuality"; 211 bestQualityMemorizer4.MaximizationParameter.ActualName = MaximizationParameter.Name; 212 bestQualityMemorizer4.QualityParameter.ActualName = QualityParameter.Name; 213 214 dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("BestQuality")); 215 dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name)); 216 dataTableValuesCollector2.DataTableParameter.ActualName = "Qualities"; 217 218 qualityDifferenceCalculator2.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest"; 219 qualityDifferenceCalculator2.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name; 220 qualityDifferenceCalculator2.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest"; 221 qualityDifferenceCalculator2.SecondQualityParameter.ActualName = "BestQuality"; 222 223 visualizer2.Name = "Visualizer (placeholder)"; 224 visualizer2.OperatorParameter.ActualName = VisualizerParameter.Name; 182 resultsCollector2.CollectedValues.Add(new LookupParameter<IntValue>("Iterations")); 183 resultsCollector2.ResultsParameter.ActualName = ResultsParameter.Name; 184 185 analyzer2.Name = "Analyzer (placeholder)"; 186 analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name; 225 187 226 188 iterationsTermination.Name = "Iterations Termination Condition"; … … 230 192 #region Create operator graph 231 193 OperatorGraph.InitialOperator = variableCreator; 232 variableCreator.Successor = bestQualityMemorizer1; 233 bestQualityMemorizer1.Successor = bestQualityMemorizer2; 234 bestQualityMemorizer2.Successor = dataTableValuesCollector1; 235 dataTableValuesCollector1.Successor = qualityDifferenceCalculator1; 236 qualityDifferenceCalculator1.Successor = visualizer1; 237 visualizer1.Successor = resultsCollector; 238 resultsCollector.Successor = mainProcessor; 194 variableCreator.Successor = resultsCollector1; 195 resultsCollector1.Successor = uniformSubScopesProcessor0; 196 uniformSubScopesProcessor0.Operator = analyzer1; 197 uniformSubScopesProcessor0.Successor = mainProcessor; 198 analyzer1.Successor = null; 239 199 mainProcessor.Operator = moveGenerator; 240 200 mainProcessor.Successor = iterationsCounter; 241 201 moveGenerator.Successor = moveEvaluationProcessor; 242 202 moveEvaluationProcessor.Operator = moveEvaluator; 243 moveEvaluationProcessor.Successor = bestSelector; 203 moveEvaluationProcessor.Successor = moveAnalyzer; 204 moveAnalyzer.Successor = bestSelector; 244 205 bestSelector.Successor = rightReducer; 245 206 rightReducer.Successor = moveMakingProcessor; … … 253 214 moveMaker.Successor = null; 254 215 iterationsCounter.Successor = iterationsComparator; 255 iterationsComparator.Successor = bestQualityMemorizer3; 256 bestQualityMemorizer3.Successor = bestQualityMemorizer4; 257 bestQualityMemorizer4.Successor = dataTableValuesCollector2; 258 dataTableValuesCollector2.Successor = qualityDifferenceCalculator2; 259 qualityDifferenceCalculator2.Successor = visualizer2; 260 visualizer2.Successor = iterationsTermination; 216 iterationsComparator.Successor = resultsCollector2; 217 resultsCollector2.Successor = uniformSubScopesProcessor1; 218 uniformSubScopesProcessor1.Operator = analyzer2; 219 uniformSubScopesProcessor1.Successor = iterationsTermination; 220 analyzer2.Successor = null; 261 221 iterationsTermination.TrueBranch = null; 262 222 iterationsTermination.FalseBranch = mainProcessor;
Note: See TracChangeset
for help on using the changeset viewer.