- Timestamp:
- 03/18/10 20:56:34 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs
r3098 r3101 53 53 get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; } 54 54 } 55 private ConstrainedValueParameter<I SingleMoveGenerator> MoveGeneratorParameter {56 get { return (ConstrainedValueParameter<I SingleMoveGenerator>)Parameters["MoveGenerator"]; }55 private ConstrainedValueParameter<IMultiMoveGenerator> MoveGeneratorParameter { 56 get { return (ConstrainedValueParameter<IMultiMoveGenerator>)Parameters["MoveGenerator"]; } 57 57 } 58 58 private ConstrainedValueParameter<IMoveMaker> MoveMakerParameter { … … 67 67 private ValueParameter<IntValue> MaximumIterationsParameter { 68 68 get { return (ValueParameter<IntValue>)Parameters["MaximumIterations"]; } 69 } 70 private ValueParameter<IntValue> InnerIterationsParameter { 71 get { return (ValueParameter<IntValue>)Parameters["InnerIterations"]; } 69 72 } 70 73 private ValueParameter<DoubleValue> StartTemperatureParameter { … … 85 88 set { SetSeedRandomlyParameter.Value = value; } 86 89 } 87 public I SingleMoveGenerator MoveGenerator {90 public IMultiMoveGenerator MoveGenerator { 88 91 get { return MoveGeneratorParameter.Value; } 89 92 set { MoveGeneratorParameter.Value = value; } … … 100 103 get { return MaximumIterationsParameter.Value; } 101 104 set { MaximumIterationsParameter.Value = value; } 105 } 106 public IntValue InnerIterations { 107 get { return InnerIterationsParameter.Value; } 108 set { InnerIterationsParameter.Value = value; } 109 } 110 public DoubleValue StartTemperature { 111 get { return StartTemperatureParameter.Value; } 112 set { StartTemperatureParameter.Value = value; } 113 } 114 public DoubleValue EndTemperature { 115 get { return EndTemperatureParameter.Value; } 116 set { EndTemperatureParameter.Value = value; } 102 117 } 103 118 private RandomCreator RandomCreator { … … 121 136 Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); 122 137 Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); 123 Parameters.Add(new ConstrainedValueParameter<I SingleMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution."));138 Parameters.Add(new ConstrainedValueParameter<IMultiMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution.")); 124 139 Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>("MoveEvaluator", "The operator used to evaluate a move.")); 125 140 Parameters.Add(new ConstrainedValueParameter<IMoveMaker>("MoveMaker", "The operator used to perform a move.")); 126 141 Parameters.Add(new ConstrainedValueParameter<IDiscreteDoubleValueModifier>("AnnealingOperator", "The operator used to modify the temperature.")); 127 Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(1000))); 142 Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(100))); 143 Parameters.Add(new ValueParameter<IntValue>("InnerIterations", "The amount of inner iterations (number of moves before temperature is adjusted again).", new IntValue(10))); 128 144 Parameters.Add(new ValueParameter<DoubleValue>("StartTemperature", "The initial temperature.", new DoubleValue(100))); 129 145 Parameters.Add(new ValueParameter<DoubleValue>("EndTemperature", "The final temperature which should be reached when iterations reaches maximum iterations.", new DoubleValue(1e-6))); … … 176 192 ParameterizeSolutionsCreator(); 177 193 ParameterizeMainLoop(); 178 ParameterizeMoveEvaluator(); 179 ParameterizeMoveMaker(); 194 ParameterizeMoveEvaluators(); 195 ParameterizeMoveMakers(); 196 ParameterizeMoveGenerators(); 180 197 UpdateMoveGenerator(); 181 198 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); … … 191 208 ParameterizeSolutionsCreator(); 192 209 ParameterizeMainLoop(); 193 ParameterizeMoveEvaluator ();194 ParameterizeMoveMaker ();210 ParameterizeMoveEvaluators(); 211 ParameterizeMoveMakers(); 195 212 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 196 213 base.Problem_EvaluatorChanged(sender, e); … … 204 221 op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged); 205 222 } 206 I SingleMoveGenerator oldMoveGenerator = MoveGenerator;223 IMultiMoveGenerator oldMoveGenerator = MoveGenerator; 207 224 UpdateMoveGenerator(); 208 225 if (oldMoveGenerator == MoveGenerator) // in this case MoveGeneratorParameter_ValueChanged did not fire 209 226 UpdateMoveParameters(); 210 227 ParameterizeMainLoop(); 211 ParameterizeMoveEvaluator(); 212 ParameterizeMoveMaker(); 228 ParameterizeMoveEvaluators(); 229 ParameterizeMoveMakers(); 230 ParameterizeMoveGenerators(); 213 231 base.Problem_OperatorsChanged(sender, e); 214 232 } 215 233 private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) { 216 234 ParameterizeMainLoop(); 217 ParameterizeMoveEvaluator ();218 ParameterizeMoveMaker ();235 ParameterizeMoveEvaluators(); 236 ParameterizeMoveMakers(); 219 237 } 220 238 private void MoveGeneratorParameter_ValueChanged(object sender, EventArgs e) { … … 223 241 private void MoveEvaluatorParameter_ValueChanged(object sender, EventArgs e) { 224 242 ParameterizeMainLoop(); 225 ParameterizeMoveEvaluator ();226 ParameterizeMoveMaker ();243 ParameterizeMoveEvaluators(); 244 ParameterizeMoveMakers(); 227 245 } 228 246 private void MoveEvaluator_MoveQualityParameter_ActualNameChanged(object sender, EventArgs e) { 229 247 ParameterizeMainLoop(); 230 ParameterizeMoveEvaluator ();231 ParameterizeMoveMaker ();248 ParameterizeMoveEvaluators(); 249 ParameterizeMoveMakers(); 232 250 } 233 251 #endregion … … 257 275 } 258 276 private void UpdateMoveGenerator() { 259 I SingleMoveGenerator oldMoveGenerator = MoveGenerator;277 IMultiMoveGenerator oldMoveGenerator = MoveGenerator; 260 278 MoveGeneratorParameter.ValidValues.Clear(); 261 279 if (Problem != null) { 262 foreach (I SingleMoveGenerator generator in Problem.Operators.OfType<ISingleMoveGenerator>().Where(x => !(x is IMultiMoveGenerator)).OrderBy(x => x.Name))280 foreach (IMultiMoveGenerator generator in Problem.Operators.OfType<IMultiMoveGenerator>().OrderBy(x => x.Name)) 263 281 MoveGeneratorParameter.ValidValues.Add(generator); 264 282 } 265 283 if (oldMoveGenerator != null) { 266 I SingleMoveGenerator newMoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType());284 IMultiMoveGenerator newMoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType()); 267 285 if (newMoveGenerator != null) MoveGenerator = newMoveGenerator; 268 286 } … … 314 332 ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; 315 333 } 316 private void ParameterizeMoveEvaluator () {334 private void ParameterizeMoveEvaluators() { 317 335 foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) { 318 336 op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 319 337 } 320 338 } 321 private void ParameterizeMoveMaker () {339 private void ParameterizeMoveMakers() { 322 340 foreach (IMoveMaker op in Problem.Operators.OfType<IMoveMaker>()) { 323 341 op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; … … 337 355 } 338 356 } 357 private void ParameterizeMoveGenerators() { 358 foreach (IMultiMoveGenerator op in Problem.Operators.OfType<IMultiMoveGenerator>()) { 359 op.SampleSizeParameter.ActualName = InnerIterationsParameter.Name; 360 } 361 } 339 362 #endregion 340 363 } -
trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealingMainLoop.cs
r3094 r3101 55 55 get { return (ValueLookupParameter<DoubleValue>)Parameters["EndTemperature"]; } 56 56 } 57 public ValueLookupParameter<IntValue> InnerIterationsParameter { 58 get { return (ValueLookupParameter<IntValue>)Parameters["InnerIterations"]; } 59 } 57 60 public ValueLookupParameter<IntValue> MaximumIterationsParameter { 58 61 get { return (ValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; } … … 97 100 Parameters.Add(new ValueLookupParameter<DoubleValue>("StartTemperature", "The initial temperature.")); 98 101 Parameters.Add(new ValueLookupParameter<DoubleValue>("EndTemperature", "The end temperature.")); 102 Parameters.Add(new ValueLookupParameter<IntValue>("InnerIterations", "The amount of inner iterations (number of moves before temperature is adjusted again).")); 99 103 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of iterations which should be processed.")); 100 104 Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored.")); … … 116 120 Placeholder annealingOperator = new Placeholder(); 117 121 UniformSequentialSubScopesProcessor mainProcessor = new UniformSequentialSubScopesProcessor(); 122 DataTableValuesCollector valuesCollector = new DataTableValuesCollector(); 118 123 Placeholder moveGenerator = new Placeholder(); 119 SequentialSubScopesProcessor moveEvaluationProcessor = newSequentialSubScopesProcessor();124 UniformSequentialSubScopesProcessor moveEvaluationProcessor = new UniformSequentialSubScopesProcessor(); 120 125 Placeholder moveEvaluator = new Placeholder(); 121 126 ProbabilisticQualityComparator qualityComparator = new ProbabilisticQualityComparator(); … … 123 128 Placeholder moveMaker = new Placeholder(); 124 129 SubScopesRemover subScopesRemover = new SubScopesRemover(); 125 DataTableValuesCollector valuesCollector = new DataTableValuesCollector();126 130 IntCounter iterationsCounter = new IntCounter(); 127 131 Comparator iterationsComparator = new Comparator(); … … 142 146 annealingOperator.OperatorParameter.ActualName = "AnnealingOperator"; 143 147 148 valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Quality")); 149 valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestQuality")); 150 valuesCollector.DataTableParameter.ActualName = "Qualities"; 151 144 152 moveGenerator.Name = "Move generator (placeholder)"; 145 153 moveGenerator.OperatorParameter.ActualName = "MoveGenerator"; … … 159 167 160 168 subScopesRemover.RemoveAllSubScopes = true; 161 162 valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Quality"));163 valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestQuality"));164 valuesCollector.DataTableParameter.ActualName = "Qualities";165 169 166 170 iterationsCounter.Name = "Increment Iterations"; … … 188 192 bestQualityMemorizer.Successor = annealingOperator; 189 193 annealingOperator.Successor = mainProcessor; 190 mainProcessor.Operator = moveGenerator; 191 mainProcessor.Successor = valuesCollector; 194 mainProcessor.Operator = valuesCollector; 195 mainProcessor.Successor = iterationsCounter; 196 valuesCollector.Successor = moveGenerator; 192 197 moveGenerator.Successor = moveEvaluationProcessor; 193 moveEvaluationProcessor.Operator s.Add(moveEvaluator);198 moveEvaluationProcessor.Operator = moveEvaluator; 194 199 moveEvaluationProcessor.Successor = subScopesRemover; 195 200 moveEvaluator.Successor = qualityComparator; 196 201 qualityComparator.Successor = improvesQualityBranch; 197 202 improvesQualityBranch.TrueBranch = moveMaker; 198 valuesCollector.Successor = iterationsCounter;199 203 iterationsCounter.Successor = iterationsComparator; 200 204 iterationsComparator.Successor = iterationsTermination; -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/StochasticTwoOptMultiMoveGenerator.cs
r3098 r3101 47 47 public static TwoOptMove[] Apply(Permutation permutation, IRandom random, int sampleSize) { 48 48 int length = permutation.Length; 49 int totalMoves = (length) * (length - 1) / 2 - 3;50 // FIXME: Should this be an exception or a warning for the logger?51 if (sampleSize >= totalMoves) throw new InvalidOperationException("StochasticTwoOptMoveGenerator: Sample size (" + sampleSize + ") is larger than the set of all possible moves (" + totalMoves + "), use the ExhaustiveTwoOptMoveGenerator instead.");52 49 TwoOptMove[] moves = new TwoOptMove[sampleSize]; 53 50 for (int i = 0; i < sampleSize; i++) {
Note: See TracChangeset
for help on using the changeset viewer.