Changeset 3142 for trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing
- Timestamp:
- 03/20/10 19:01:04 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealingMainLoop.cs
r3101 r3142 46 46 get { return (LookupParameter<DoubleValue>)Parameters["Quality"]; } 47 47 } 48 public ValueLookupParameter<DoubleValue> BestKnownQualityParameter { 49 get { return (ValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 50 } 48 51 public LookupParameter<DoubleValue> MoveQualityParameter { 49 52 get { return (LookupParameter<DoubleValue>)Parameters["MoveQuality"]; } … … 61 64 get { return (ValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; } 62 65 } 66 public ValueLookupParameter<IOperator> MoveGeneratorParameter { 67 get { return (ValueLookupParameter<IOperator>)Parameters["MoveGenerator"]; } 68 } 69 public ValueLookupParameter<IOperator> MoveEvaluatorParameter { 70 get { return (ValueLookupParameter<IOperator>)Parameters["MoveEvaluator"]; } 71 } 72 public ValueLookupParameter<IOperator> MoveMakerParameter { 73 get { return (ValueLookupParameter<IOperator>)Parameters["MoveMaker"]; } 74 } 75 public ValueLookupParameter<IOperator> AnnealingOperatorParameter { 76 get { return (ValueLookupParameter<IOperator>)Parameters["AnnealingOperator"]; } 77 } 78 public ValueLookupParameter<IOperator> VisualizerParameter { 79 get { return (ValueLookupParameter<IOperator>)Parameters["Visualizer"]; } 80 } 81 public LookupParameter<IItem> VisualizationParameter { 82 get { return (LookupParameter<IItem>)Parameters["Visualization"]; } 83 } 63 84 public ValueLookupParameter<VariableCollection> ResultsParameter { 64 85 get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; } 65 }66 public ValueLookupParameter<IOperator> MoveGeneratorParameter {67 get { return (ValueLookupParameter<IOperator>)Parameters["MoveGenerator"]; }68 }69 public ValueLookupParameter<IOperator> MoveEvaluatorParameter {70 get { return (ValueLookupParameter<IOperator>)Parameters["MoveEvaluator"]; }71 }72 public ValueLookupParameter<IOperator> MoveMakerParameter {73 get { return (ValueLookupParameter<IOperator>)Parameters["MoveMaker"]; }74 }75 public ValueLookupParameter<IOperator> AnnealingOperatorParameter {76 get { return (ValueLookupParameter<IOperator>)Parameters["AnnealingOperator"]; }77 }78 79 private ScopeParameter CurrentScopeParameter {80 get { return (ScopeParameter)Parameters["CurrentScope"]; }81 }82 public IScope CurrentScope {83 get { return CurrentScopeParameter.ActualValue; }84 86 } 85 87 #endregion … … 97 99 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); 98 100 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); 101 Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far.")); 99 102 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The value which represents the quality of a move.")); 100 103 Parameters.Add(new ValueLookupParameter<DoubleValue>("StartTemperature", "The initial temperature.")); … … 102 105 Parameters.Add(new ValueLookupParameter<IntValue>("InnerIterations", "The amount of inner iterations (number of moves before temperature is adjusted again).")); 103 106 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of iterations which should be processed.")); 104 Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored.")); 105 107 106 108 Parameters.Add(new ValueLookupParameter<IOperator>("MoveGenerator", "The operator that generates the moves.")); 107 109 Parameters.Add(new ValueLookupParameter<IOperator>("MoveEvaluator", "The operator that evaluates a move.")); … … 109 111 Parameters.Add(new ValueLookupParameter<IOperator>("AnnealingOperator", "The operator that modifies the temperature.")); 110 112 111 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the TS should be applied.")); 113 Parameters.Add(new ValueLookupParameter<IOperator>("Visualizer", "The operator used to visualize solutions.")); 114 Parameters.Add(new LookupParameter<IItem>("Visualization", "The item which represents the visualization of solutions.")); 115 Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored.")); 112 116 #endregion 113 117 114 118 #region Create operators 115 119 VariableCreator variableCreator = new VariableCreator(); 116 BestQualityMemorizer initializeBestQuality = new BestQualityMemorizer(); 120 BestQualityMemorizer bestQualityMemorizer1 = new BestQualityMemorizer(); 121 BestQualityMemorizer bestQualityMemorizer2 = new BestQualityMemorizer(); 122 QualityDifferenceCalculator qualityDifferenceCalculator1 = new QualityDifferenceCalculator(); 123 Placeholder visualizer1 = new Placeholder(); 117 124 SequentialSubScopesProcessor sssp = new SequentialSubScopesProcessor(); 118 125 ResultsCollector resultsCollector = new ResultsCollector(); 119 BestQualityMemorizer bestQualityMemorizer = new BestQualityMemorizer();120 126 Placeholder annealingOperator = new Placeholder(); 121 127 UniformSequentialSubScopesProcessor mainProcessor = new UniformSequentialSubScopesProcessor(); … … 130 136 IntCounter iterationsCounter = new IntCounter(); 131 137 Comparator iterationsComparator = new Comparator(); 138 BestQualityMemorizer bestQualityMemorizer3 = new BestQualityMemorizer(); 139 BestQualityMemorizer bestQualityMemorizer4 = new BestQualityMemorizer(); 140 QualityDifferenceCalculator qualityDifferenceCalculator2 = new QualityDifferenceCalculator(); 141 Placeholder visualizer2 = new Placeholder(); 132 142 ConditionalBranch iterationsTermination = new ConditionalBranch(); 133 EmptyOperator finished = new EmptyOperator(); 134 143 135 144 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0))); 136 145 variableCreator.CollectedValues.Add(new ValueParameter<DataTable>("Qualities", new DataTable("Qualities"))); 137 146 variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("Temperature", new DoubleValue(double.MaxValue))); 138 147 148 bestQualityMemorizer1.BestQualityParameter.ActualName = "BestQuality"; 149 bestQualityMemorizer1.MaximizationParameter.ActualName = MaximizationParameter.Name; 150 bestQualityMemorizer1.QualityParameter.ActualName = QualityParameter.Name; 151 152 bestQualityMemorizer2.BestQualityParameter.ActualName = BestKnownQualityParameter.Name; 153 bestQualityMemorizer2.MaximizationParameter.ActualName = MaximizationParameter.Name; 154 bestQualityMemorizer2.QualityParameter.ActualName = QualityParameter.Name; 155 156 qualityDifferenceCalculator1.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest"; 157 qualityDifferenceCalculator1.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name; 158 qualityDifferenceCalculator1.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest"; 159 qualityDifferenceCalculator1.SecondQualityParameter.ActualName = "BestQuality"; 160 161 visualizer1.Name = "Visualizer (placeholder)"; 162 visualizer1.OperatorParameter.ActualName = VisualizerParameter.Name; 163 139 164 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iterations")); 140 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>( "Quality"));165 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(QualityParameter.Name)); 141 166 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality") { ActualName = "BestQuality" }); 167 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name)); 142 168 resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Qualities")); 143 169 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Temperature")); 144 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)); 173 145 174 annealingOperator.Name = "Annealing operator (placeholder)"; 146 annealingOperator.OperatorParameter.ActualName = "AnnealingOperator";147 148 valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>( "Quality"));175 annealingOperator.OperatorParameter.ActualName = AnnealingOperatorParameter.Name; 176 177 valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(QualityParameter.Name)); 149 178 valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestQuality")); 150 179 valuesCollector.DataTableParameter.ActualName = "Qualities"; 151 180 152 181 moveGenerator.Name = "Move generator (placeholder)"; 153 moveGenerator.OperatorParameter.ActualName = "MoveGenerator";182 moveGenerator.OperatorParameter.ActualName = MoveGeneratorParameter.Name; 154 183 155 184 moveEvaluator.Name = "Move evaluator (placeholder)"; 156 moveEvaluator.OperatorParameter.ActualName = "MoveEvaluator";157 158 qualityComparator.LeftSideParameter.ActualName = "MoveQuality";159 qualityComparator.RightSideParameter.ActualName = "Quality";185 moveEvaluator.OperatorParameter.ActualName = MoveEvaluatorParameter.Name; 186 187 qualityComparator.LeftSideParameter.ActualName = MoveQualityParameter.Name; 188 qualityComparator.RightSideParameter.ActualName = QualityParameter.Name; 160 189 qualityComparator.ResultParameter.ActualName = "IsBetter"; 161 190 qualityComparator.DampeningParameter.ActualName = "Temperature"; … … 164 193 165 194 moveMaker.Name = "Move maker (placeholder)"; 166 moveMaker.OperatorParameter.ActualName = "MoveMaker";195 moveMaker.OperatorParameter.ActualName = MoveMakerParameter.Name; 167 196 168 197 subScopesRemover.RemoveAllSubScopes = true; … … 174 203 iterationsComparator.Name = "Iterations >= MaximumIterations"; 175 204 iterationsComparator.LeftSideParameter.ActualName = "Iterations"; 176 iterationsComparator.RightSideParameter.ActualName = "MaximumIterations";177 iterationsComparator.ResultParameter.ActualName = " IterationsCondition";205 iterationsComparator.RightSideParameter.ActualName = MaximumIterationsParameter.Name; 206 iterationsComparator.ResultParameter.ActualName = "Terminate"; 178 207 iterationsComparator.Comparison.Value = ComparisonType.GreaterOrEqual; 179 208 209 bestQualityMemorizer3.BestQualityParameter.ActualName = "BestQuality"; 210 bestQualityMemorizer3.MaximizationParameter.ActualName = MaximizationParameter.Name; 211 bestQualityMemorizer3.QualityParameter.ActualName = QualityParameter.Name; 212 213 bestQualityMemorizer4.BestQualityParameter.ActualName = BestKnownQualityParameter.Name; 214 bestQualityMemorizer4.MaximizationParameter.ActualName = MaximizationParameter.Name; 215 bestQualityMemorizer4.QualityParameter.ActualName = QualityParameter.Name; 216 217 qualityDifferenceCalculator2.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest"; 218 qualityDifferenceCalculator2.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name; 219 qualityDifferenceCalculator2.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest"; 220 qualityDifferenceCalculator2.SecondQualityParameter.ActualName = "BestQuality"; 221 222 visualizer2.Name = "Visualizer (placeholder)"; 223 visualizer2.OperatorParameter.ActualName = VisualizerParameter.Name; 224 180 225 iterationsTermination.Name = "Iterations termination condition"; 181 iterationsTermination.ConditionParameter.ActualName = "IterationsCondition"; 182 183 finished.Name = "Finished"; 226 iterationsTermination.ConditionParameter.ActualName = "Terminate"; 184 227 #endregion 185 228 186 229 #region Create operator graph 187 230 OperatorGraph.InitialOperator = variableCreator; 188 variableCreator.Successor = initializeBestQuality; 189 initializeBestQuality.Successor = sssp; 231 variableCreator.Successor = bestQualityMemorizer1; 232 bestQualityMemorizer1.Successor = bestQualityMemorizer2; 233 bestQualityMemorizer2.Successor = qualityDifferenceCalculator1; 234 qualityDifferenceCalculator1.Successor = visualizer1; 235 visualizer1.Successor = sssp; 190 236 sssp.Operators.Add(resultsCollector); 191 sssp.Successor = bestQualityMemorizer;192 bestQualityMemorizer.Successor = annealingOperator;237 resultsCollector.Successor = null; 238 sssp.Successor = annealingOperator; 193 239 annealingOperator.Successor = mainProcessor; 194 240 mainProcessor.Operator = valuesCollector; … … 202 248 improvesQualityBranch.TrueBranch = moveMaker; 203 249 iterationsCounter.Successor = iterationsComparator; 204 iterationsComparator.Successor = iterationsTermination; 205 iterationsTermination.TrueBranch = finished; 206 iterationsTermination.FalseBranch = bestQualityMemorizer; 250 iterationsComparator.Successor = bestQualityMemorizer3; 251 bestQualityMemorizer3.Successor = bestQualityMemorizer4; 252 bestQualityMemorizer4.Successor = qualityDifferenceCalculator2; 253 qualityDifferenceCalculator2.Successor = visualizer2; 254 visualizer2.Successor = iterationsTermination; 255 iterationsTermination.TrueBranch = null; 256 iterationsTermination.FalseBranch = annealingOperator; 207 257 #endregion 208 258 }
Note: See TracChangeset
for help on using the changeset viewer.