Changeset 3622 for trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing
- Timestamp:
- 05/05/10 03:30:34 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs
r3616 r3622 33 33 using HeuristicLab.PluginInfrastructure; 34 34 using HeuristicLab.Random; 35 using HeuristicLab.Analysis; 35 36 36 37 namespace HeuristicLab.Algorithms.SimulatedAnnealing { … … 80 81 get { return (ValueParameter<DoubleValue>)Parameters["EndTemperature"]; } 81 82 } 83 private ValueParameter<MultiAnalyzer> AnalyzerParameter { 84 get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; } 85 } 82 86 #endregion 83 87 … … 119 123 set { EndTemperatureParameter.Value = value; } 120 124 } 125 public MultiAnalyzer Analyzer { 126 get { return AnalyzerParameter.Value; } 127 set { AnalyzerParameter.Value = value; } 128 } 121 129 private RandomCreator RandomCreator { 122 130 get { return (RandomCreator)OperatorGraph.InitialOperator; } … … 133 141 get { return annealingOperators; } 134 142 } 143 private BestAverageWorstQualityAnalyzer qualityAnalyzer; 135 144 #endregion 136 145 146 [StorableConstructor] 147 private SimulatedAnnealing(bool deserializing) : base(deserializing) { } 137 148 public SimulatedAnnealing() 138 149 : base() { … … 147 158 Parameters.Add(new ValueParameter<DoubleValue>("StartTemperature", "The initial temperature.", new DoubleValue(100))); 148 159 Parameters.Add(new ValueParameter<DoubleValue>("EndTemperature", "The final temperature which should be reached when iterations reaches maximum iterations.", new DoubleValue(1e-6))); 149 160 Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer())); 161 150 162 RandomCreator randomCreator = new RandomCreator(); 151 163 SolutionsCreator solutionsCreator = new SolutionsCreator(); … … 172 184 mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; 173 185 mainLoop.ResultsParameter.ActualName = "Results"; 186 mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name; 174 187 175 188 Initialize(); 176 189 } 177 [StorableConstructor]178 private SimulatedAnnealing(bool deserializing) : base(deserializing) { }179 190 180 191 public override IDeepCloneable Clone(Cloner cloner) { … … 204 215 ParameterizeMoveMakers(); 205 216 ParameterizeMoveGenerators(); 217 ParameterizeAnalyzers(); 218 UpdateAnalyzers(); 206 219 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 207 220 base.OnProblemChanged(); … … 218 231 ParameterizeMoveEvaluators(); 219 232 ParameterizeMoveMakers(); 233 ParameterizeAnalyzers(); 220 234 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 221 235 base.Problem_EvaluatorChanged(sender, e); … … 231 245 UpdateMoveGenerator(); 232 246 UpdateMoveParameters(); 247 UpdateAnalyzers(); 233 248 ParameterizeMainLoop(); 234 249 ParameterizeMoveEvaluators(); … … 241 256 ParameterizeMoveEvaluators(); 242 257 ParameterizeMoveMakers(); 258 ParameterizeAnalyzers(); 243 259 } 244 260 private void MoveGeneratorParameter_ValueChanged(object sender, EventArgs e) { … … 260 276 [StorableHook(HookType.AfterDeserialization)] 261 277 private void Initialize() { 278 InitializeAnalyzers(); 279 UpdateAnalyzers(); 262 280 if (Problem != null) { 263 281 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); … … 278 296 AnnealingOperatorParameter.ValidValues.Add(op); 279 297 } 298 private void InitializeAnalyzers() { 299 qualityAnalyzer = new BestAverageWorstQualityAnalyzer(); 300 ParameterizeAnalyzers(); 301 } 280 302 private void UpdateMoveGenerator() { 281 303 IMultiMoveGenerator oldMoveGenerator = MoveGenerator; … … 291 313 if (MoveGenerator == null) { 292 314 ClearMoveParameters(); 315 } 316 } 317 private void ParameterizeAnalyzers() { 318 qualityAnalyzer.ResultsParameter.ActualName = "Results"; 319 if (Problem != null) { 320 qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 321 qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 322 qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name; 293 323 } 294 324 } … … 367 397 } 368 398 } 399 private void UpdateAnalyzers() { 400 Analyzer.Operators.Clear(); 401 Analyzer.Operators.Add(qualityAnalyzer); 402 if (Problem != null) { 403 foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>().OrderBy(x => x.Name)) 404 Analyzer.Operators.Add(analyzer); 405 } 406 } 369 407 #endregion 370 408 } -
trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealingMainLoop.cs
r3522 r3622 77 77 get { return (ValueLookupParameter<IOperator>)Parameters["AnnealingOperator"]; } 78 78 } 79 public ValueLookupParameter<IOperator> VisualizerParameter { 80 get { return (ValueLookupParameter<IOperator>)Parameters["Visualizer"]; } 81 } 82 public LookupParameter<IItem> VisualizationParameter { 83 get { return (LookupParameter<IItem>)Parameters["Visualization"]; } 79 public ValueLookupParameter<IOperator> AnalyzerParameter { 80 get { return (ValueLookupParameter<IOperator>)Parameters["Analyzer"]; } 84 81 } 85 82 public ValueLookupParameter<VariableCollection> ResultsParameter { … … 112 109 Parameters.Add(new ValueLookupParameter<IOperator>("AnnealingOperator", "The operator that modifies the temperature.")); 113 110 114 Parameters.Add(new ValueLookupParameter<IOperator>("Visualizer", "The operator used to visualize solutions.")); 115 Parameters.Add(new LookupParameter<IItem>("Visualization", "The item which represents the visualization of solutions.")); 111 Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze each generation.")); 116 112 Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored.")); 117 113 #endregion … … 119 115 #region Create operators 120 116 VariableCreator variableCreator = new VariableCreator(); 121 BestQualityMemorizer bestQualityMemorizer1 = new BestQualityMemorizer(); 122 BestQualityMemorizer bestQualityMemorizer2 = new BestQualityMemorizer(); 123 QualityDifferenceCalculator qualityDifferenceCalculator1 = new QualityDifferenceCalculator(); 124 Placeholder visualizer1 = new Placeholder(); 117 ResultsCollector resultsCollector1 = new ResultsCollector(); 118 Placeholder analyzer1 = new Placeholder(); 125 119 SubScopesProcessor sssp = new SubScopesProcessor(); 126 120 ResultsCollector resultsCollector = new ResultsCollector(); 127 121 Placeholder annealingOperator = new Placeholder(); 128 122 UniformSubScopesProcessor mainProcessor = new UniformSubScopesProcessor(); 129 DataTableValuesCollector valuesCollector = new DataTableValuesCollector();130 123 Placeholder moveGenerator = new Placeholder(); 131 124 UniformSubScopesProcessor moveEvaluationProcessor = new UniformSubScopesProcessor(); … … 137 130 IntCounter iterationsCounter = new IntCounter(); 138 131 Comparator iterationsComparator = new Comparator(); 139 BestQualityMemorizer bestQualityMemorizer3 = new BestQualityMemorizer(); 140 BestQualityMemorizer bestQualityMemorizer4 = new BestQualityMemorizer(); 141 QualityDifferenceCalculator qualityDifferenceCalculator2 = new QualityDifferenceCalculator(); 142 Placeholder visualizer2 = new Placeholder(); 132 ResultsCollector resultsCollector2 = new ResultsCollector(); 133 Placeholder analyzer2 = new Placeholder(); 143 134 ConditionalBranch iterationsTermination = new ConditionalBranch(); 144 135 145 136 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0))); 146 variableCreator.CollectedValues.Add(new ValueParameter<DataTable>("Qualities", new DataTable("Qualities")));147 137 variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("Temperature", new DoubleValue(double.MaxValue))); 148 138 149 bestQualityMemorizer1.BestQualityParameter.ActualName = "BestQuality"; 150 bestQualityMemorizer1.MaximizationParameter.ActualName = MaximizationParameter.Name; 151 bestQualityMemorizer1.QualityParameter.ActualName = QualityParameter.Name; 152 153 bestQualityMemorizer2.BestQualityParameter.ActualName = BestKnownQualityParameter.Name; 154 bestQualityMemorizer2.MaximizationParameter.ActualName = MaximizationParameter.Name; 155 bestQualityMemorizer2.QualityParameter.ActualName = QualityParameter.Name; 156 157 qualityDifferenceCalculator1.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest"; 158 qualityDifferenceCalculator1.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name; 159 qualityDifferenceCalculator1.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest"; 160 qualityDifferenceCalculator1.SecondQualityParameter.ActualName = "BestQuality"; 161 162 visualizer1.Name = "Visualizer (placeholder)"; 163 visualizer1.OperatorParameter.ActualName = VisualizerParameter.Name; 164 165 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iterations")); 166 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(QualityParameter.Name)); 167 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality") { ActualName = "BestQuality" }); 168 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name)); 169 resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Qualities")); 170 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Temperature")); 171 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Absolute Difference of Best Known Quality to Best Quality", null, "AbsoluteDifferenceBestKnownToBest")); 172 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Relative Difference of Best Known Quality to Best Quality", null, "RelativeDifferenceBestKnownToBest")); 173 resultsCollector.CollectedValues.Add(new LookupParameter<IItem>("Solution Visualization", null, VisualizationParameter.Name)); 174 139 resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Iterations")); 140 resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Temperature")); 141 resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name; 142 143 analyzer1.Name = "Analyzer (placeholder)"; 144 analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name; 145 175 146 annealingOperator.Name = "Annealing operator (placeholder)"; 176 147 annealingOperator.OperatorParameter.ActualName = AnnealingOperatorParameter.Name; 177 178 valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Quality", null, QualityParameter.Name));179 valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));180 valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name));181 valuesCollector.DataTableParameter.ActualName = "Qualities";182 148 183 149 moveGenerator.Name = "Move generator (placeholder)"; … … 209 175 iterationsComparator.Comparison.Value = ComparisonType.GreaterOrEqual; 210 176 211 bestQualityMemorizer3.BestQualityParameter.ActualName = "BestQuality"; 212 bestQualityMemorizer3.MaximizationParameter.ActualName = MaximizationParameter.Name; 213 bestQualityMemorizer3.QualityParameter.ActualName = QualityParameter.Name; 214 215 bestQualityMemorizer4.BestQualityParameter.ActualName = BestKnownQualityParameter.Name; 216 bestQualityMemorizer4.MaximizationParameter.ActualName = MaximizationParameter.Name; 217 bestQualityMemorizer4.QualityParameter.ActualName = QualityParameter.Name; 218 219 qualityDifferenceCalculator2.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest"; 220 qualityDifferenceCalculator2.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name; 221 qualityDifferenceCalculator2.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest"; 222 qualityDifferenceCalculator2.SecondQualityParameter.ActualName = "BestQuality"; 223 224 visualizer2.Name = "Visualizer (placeholder)"; 225 visualizer2.OperatorParameter.ActualName = VisualizerParameter.Name; 177 resultsCollector2.CollectedValues.Add(new LookupParameter<IntValue>("Iterations")); 178 resultsCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Temperature")); 179 resultsCollector2.ResultsParameter.ActualName = ResultsParameter.Name; 180 181 analyzer2.Name = "Analyzer (placeholder)"; 182 analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name; 226 183 227 184 iterationsTermination.Name = "Iterations termination condition"; … … 231 188 #region Create operator graph 232 189 OperatorGraph.InitialOperator = variableCreator; 233 variableCreator.Successor = bestQualityMemorizer1; 234 bestQualityMemorizer1.Successor = bestQualityMemorizer2; 235 bestQualityMemorizer2.Successor = qualityDifferenceCalculator1; 236 qualityDifferenceCalculator1.Successor = visualizer1; 237 visualizer1.Successor = sssp; 190 variableCreator.Successor = resultsCollector1; 191 resultsCollector1.Successor = analyzer1; 192 analyzer1.Successor = sssp; 238 193 sssp.Operators.Add(resultsCollector); 239 194 resultsCollector.Successor = null; 240 195 sssp.Successor = annealingOperator; 241 196 annealingOperator.Successor = mainProcessor; 242 mainProcessor.Operator = valuesCollector;197 mainProcessor.Operator = moveGenerator; 243 198 mainProcessor.Successor = iterationsCounter; 244 valuesCollector.Successor = moveGenerator;245 199 moveGenerator.Successor = moveEvaluationProcessor; 246 200 moveEvaluationProcessor.Operator = moveEvaluator; … … 250 204 improvesQualityBranch.TrueBranch = moveMaker; 251 205 iterationsCounter.Successor = iterationsComparator; 252 iterationsComparator.Successor = bestQualityMemorizer3; 253 bestQualityMemorizer3.Successor = bestQualityMemorizer4; 254 bestQualityMemorizer4.Successor = qualityDifferenceCalculator2; 255 qualityDifferenceCalculator2.Successor = visualizer2; 256 visualizer2.Successor = iterationsTermination; 206 iterationsComparator.Successor = resultsCollector2; 207 resultsCollector2.Successor = analyzer2; 208 analyzer2.Successor = iterationsTermination; 257 209 iterationsTermination.TrueBranch = null; 258 210 iterationsTermination.FalseBranch = annealingOperator;
Note: See TracChangeset
for help on using the changeset viewer.