Changeset 3074
- Timestamp:
- 03/16/10 21:29:10 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 15 added
- 4 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.TS/3.3/TS.cs
r3048 r3074 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Data; … … 33 34 namespace HeuristicLab.Algorithms.TS { 34 35 [Item("TS", "A tabu search algorithm.")] 36 [Creatable("Algorithms")] 35 37 public sealed class TS : EngineAlgorithm { 36 /*#region Parameter Properties 38 #region Problem Properties 39 public override Type ProblemType { 40 get { return typeof(ISingleObjectiveProblem); } 41 } 42 public new ISingleObjectiveProblem Problem { 43 get { return (ISingleObjectiveProblem)base.Problem; } 44 set { base.Problem = value; } 45 } 46 #endregion 47 48 #region Parameter Properties 37 49 private ValueParameter<IntValue> SeedParameter { 38 50 get { return (ValueParameter<IntValue>)Parameters["Seed"]; } … … 43 55 private ConstrainedValueParameter<IMoveGenerator> MoveGeneratorParameter { 44 56 get { return (ConstrainedValueParameter<IMoveGenerator>)Parameters["MoveGenerator"]; } 57 } 58 private ConstrainedValueParameter<IMoveMaker> MoveMakerParameter { 59 get { return (ConstrainedValueParameter<IMoveMaker>)Parameters["MoveMaker"]; } 60 } 61 private ConstrainedValueParameter<ISingleObjectiveMoveEvaluator> MoveEvaluatorParameter { 62 get { return (ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>)Parameters["MoveEvaluator"]; } 63 } 64 private ConstrainedValueParameter<ITabuMoveEvaluator> TabuMoveEvaluatorParameter { 65 get { return (ConstrainedValueParameter<ITabuMoveEvaluator>)Parameters["TabuMoveEvaluator"]; } 66 } 67 private ConstrainedValueParameter<ITabuMoveMaker> TabuMoveMakerParameter { 68 get { return (ConstrainedValueParameter<ITabuMoveMaker>)Parameters["TabuMoveMaker"]; } 69 } 70 private ValueParameter<IntValue> TabuTenureParameter { 71 get { return (ValueParameter<IntValue>)Parameters["TabuTenure"]; } 45 72 } 46 73 private ValueParameter<IntValue> MaximumIterationsParameter { … … 61 88 get { return MoveGeneratorParameter.Value; } 62 89 set { MoveGeneratorParameter.Value = value; } 90 } 91 public IMoveMaker MoveMaker { 92 get { return MoveMakerParameter.Value; } 93 set { MoveMakerParameter.Value = value; } 94 } 95 public ISingleObjectiveMoveEvaluator MoveEvaluator { 96 get { return MoveEvaluatorParameter.Value; } 97 set { MoveEvaluatorParameter.Value = value; } 98 } 99 public ITabuMoveEvaluator TabuMoveEvaluator { 100 get { return TabuMoveEvaluatorParameter.Value; } 101 set { TabuMoveEvaluatorParameter.Value = value; } 102 } 103 public ITabuMoveMaker TabuMoveMaker { 104 get { return TabuMoveMakerParameter.Value; } 105 set { TabuMoveMakerParameter.Value = value; } 106 } 107 public IntValue TabuTenure { 108 get { return TabuTenureParameter.Value; } 109 set { TabuTenureParameter.Value = value; } 63 110 } 64 111 public IntValue MaximumIterations { … … 82 129 Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); 83 130 Parameters.Add(new ConstrainedValueParameter<IMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution.")); 131 Parameters.Add(new ConstrainedValueParameter<IMoveMaker>("MoveMaker", "The operator used to perform a move.")); 132 Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>("MoveEvaluator", "The operator used to evaluate a move.")); 133 Parameters.Add(new ConstrainedValueParameter<ITabuMoveEvaluator>("TabuMoveEvaluator", "The operator to evaluate whether a move is tabu or not.")); 134 Parameters.Add(new ConstrainedValueParameter<ITabuMoveMaker>("TabuMoveMaker", "The operator used to insert attributes of a move into the tabu list.")); 135 Parameters.Add(new ValueParameter<IntValue>("TabuTenure", "The length of the tabu list.", new IntValue(10))); 84 136 Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(1000))); 85 137 … … 100 152 101 153 tsMainLoop.MoveGeneratorParameter.ActualName = MoveGeneratorParameter.Name; 102 tsMainLoop.MoveMakerParameter.ActualName = Move Generator..Name;103 tsMainLoop. ElitesParameter.ActualName = ElitesParameter.Name;104 tsMainLoop. MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;105 tsMainLoop. MutatorParameter.ActualName = MutatorParameter.Name;106 tsMainLoop.M utationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;154 tsMainLoop.MoveMakerParameter.ActualName = MoveMakerParameter.Name; 155 tsMainLoop.MoveEvaluatorParameter.ActualName = MoveEvaluatorParameter.Name; 156 tsMainLoop.TabuMoveEvaluatorParameter.ActualName = TabuMoveEvaluatorParameter.Name; 157 tsMainLoop.TabuMoveMakerParameter.ActualName = TabuMoveMakerParameter.Name; 158 tsMainLoop.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name; 107 159 tsMainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; 108 160 tsMainLoop.ResultsParameter.ActualName = "Results"; 109 161 110 Initialze(); 111 } 162 Initialize(); 163 } 164 112 165 [StorableConstructor] 113 166 private TS(bool deserializing) : base() { } … … 115 168 public override IDeepCloneable Clone(Cloner cloner) { 116 169 TS clone = (TS)base.Clone(cloner); 117 clone.Initial ze();170 clone.Initialize(); 118 171 return clone; 119 172 } … … 124 177 ParameterizeStochasticOperator(Problem.Evaluator); 125 178 foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op); 179 foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) { 180 op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged); 181 } 126 182 ParameterizeSolutionsCreator(); 127 Parameterize SGAMainLoop();128 Parameterize Selectors();129 UpdateCrossovers();130 UpdateM utators();183 ParameterizeTSMainLoop(); 184 ParameterizeMoveEvaluator(); 185 ParameterizeMoveMaker(); 186 UpdateMoveGenerator(); 131 187 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 132 188 base.OnProblemChanged(); … … 140 196 ParameterizeStochasticOperator(Problem.Evaluator); 141 197 ParameterizeSolutionsCreator(); 142 ParameterizeSGAMainLoop(); 143 ParameterizeSelectors(); 198 ParameterizeTSMainLoop(); 199 ParameterizeMoveEvaluator(); 200 ParameterizeMoveMaker(); 144 201 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 145 202 base.Problem_EvaluatorChanged(sender, e); … … 147 204 protected override void Problem_OperatorsChanged(object sender, EventArgs e) { 148 205 foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op); 149 UpdateCrossovers(); 150 UpdateMutators(); 206 // This may seem pointless, but some operators already have the eventhandler registered, others don't 207 // FIXME: Is there another way to solve this problem? 208 foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) { 209 op.MoveQualityParameter.ActualNameChanged -= new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged); 210 op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged); 211 } 212 IMoveGenerator oldMoveGenerator = MoveGenerator; 213 UpdateMoveGenerator(); 214 if (oldMoveGenerator == MoveGenerator) // in this case MoveGeneratorParameter_ValueChanged did not fire 215 UpdateMoveParameters(); 216 ParameterizeTSMainLoop(); 217 ParameterizeMoveEvaluator(); 218 ParameterizeMoveMaker(); 151 219 base.Problem_OperatorsChanged(sender, e); 152 220 } 153 private void ElitesParameter_ValueChanged(object sender, EventArgs e) {154 Elites.ValueChanged += new EventHandler(Elites_ValueChanged);155 ParameterizeSelectors();156 }157 private void Elites_ValueChanged(object sender, EventArgs e) {158 ParameterizeSelectors();159 }160 private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {161 PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);162 ParameterizeSelectors();163 }164 private void PopulationSize_ValueChanged(object sender, EventArgs e) {165 ParameterizeSelectors();166 }167 221 private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) { 168 ParameterizeSGAMainLoop(); 169 ParameterizeSelectors(); 222 ParameterizeTSMainLoop(); 223 ParameterizeMoveEvaluator(); 224 ParameterizeMoveMaker(); 225 } 226 private void MoveGeneratorParameter_ValueChanged(object sender, EventArgs e) { 227 UpdateMoveParameters(); 228 } 229 private void MoveEvaluatorParameter_ValueChanged(object sender, EventArgs e) { 230 ParameterizeTSMainLoop(); 231 ParameterizeMoveEvaluator(); 232 ParameterizeMoveMaker(); 233 } 234 private void MoveEvaluator_MoveQualityParameter_ActualNameChanged(object sender, EventArgs e) { 235 ParameterizeTSMainLoop(); 236 ParameterizeMoveEvaluator(); 237 ParameterizeMoveMaker(); 170 238 } 171 239 #endregion … … 173 241 #region Helpers 174 242 [StorableHook(HookType.AfterDeserialization)] 175 private void Initialze() { 176 InitializeSelectors(); 177 UpdateSelectors(); 178 PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged); 179 PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged); 180 ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged); 181 Elites.ValueChanged += new EventHandler(Elites_ValueChanged); 182 if (Problem != null) 243 private void Initialize() { 244 if (Problem != null) { 183 245 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 184 } 185 246 foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) { 247 op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged); 248 } 249 } 250 MoveGeneratorParameter.ValueChanged += new EventHandler(MoveGeneratorParameter_ValueChanged); 251 MoveEvaluatorParameter.ValueChanged += new EventHandler(MoveEvaluatorParameter_ValueChanged); 252 } 253 private void UpdateMoveGenerator() { 254 IMoveGenerator oldMoveGenerator = MoveGenerator; 255 MoveGeneratorParameter.ValidValues.Clear(); 256 if (Problem != null) { 257 foreach (IMoveGenerator generator in Problem.Operators.OfType<IMoveGenerator>().OrderBy(x => x.Name)) 258 MoveGeneratorParameter.ValidValues.Add(generator); 259 } 260 if (oldMoveGenerator != null && MoveGeneratorParameter.ValidValues.Any(x => x.GetType() == oldMoveGenerator.GetType())) 261 MoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType()); 262 if (MoveGenerator == null) { 263 ClearMoveParameters(); 264 } 265 } 266 private void UpdateMoveParameters() { 267 IMoveMaker oldMoveMaker = MoveMaker; 268 ISingleObjectiveMoveEvaluator oldMoveEvaluator = MoveEvaluator; 269 ITabuMoveEvaluator oldTabuMoveEvaluator = TabuMoveEvaluator; 270 ITabuMoveMaker oldTabuMoveMaker = TabuMoveMaker; 271 ClearMoveParameters(); 272 List<Type> moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList(); 273 foreach (Type type in moveTypes.ToList()) { 274 if (moveTypes.Any(t => t != type && type.IsAssignableFrom(t))) 275 moveTypes.Remove(type); 276 } 277 foreach (Type type in moveTypes) { 278 var operators = Problem.Operators.Where(x => type.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name); 279 foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>()) 280 MoveMakerParameter.ValidValues.Add(moveMaker); 281 foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>()) 282 MoveEvaluatorParameter.ValidValues.Add(moveEvaluator); 283 foreach (ITabuMoveEvaluator tabuMoveEvaluator in operators.OfType<ITabuMoveEvaluator>()) 284 TabuMoveEvaluatorParameter.ValidValues.Add(tabuMoveEvaluator); 285 foreach (ITabuMoveMaker tabuMoveMaker in operators.OfType<ITabuMoveMaker>()) 286 TabuMoveMakerParameter.ValidValues.Add(tabuMoveMaker); 287 } 288 if (oldMoveMaker != null && MoveMakerParameter.ValidValues.Any(x => x.GetType() == oldMoveMaker.GetType())) 289 MoveMaker = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType()); 290 if (oldMoveEvaluator != null && MoveEvaluatorParameter.ValidValues.Any(x => x.GetType() == oldMoveEvaluator.GetType())) 291 MoveEvaluator = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType()); 292 if (oldTabuMoveMaker != null && TabuMoveMakerParameter.ValidValues.Any(x => x.GetType() == oldTabuMoveMaker.GetType())) 293 TabuMoveMaker = TabuMoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTabuMoveMaker.GetType()); 294 if (oldTabuMoveEvaluator != null && TabuMoveEvaluatorParameter.ValidValues.Any(x => x.GetType() == oldTabuMoveEvaluator.GetType())) 295 TabuMoveEvaluator = TabuMoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTabuMoveEvaluator.GetType()); 296 } 297 private void ClearMoveParameters() { 298 MoveMakerParameter.ValidValues.Clear(); 299 MoveEvaluatorParameter.ValidValues.Clear(); 300 TabuMoveEvaluatorParameter.ValidValues.Clear(); 301 TabuMoveMakerParameter.ValidValues.Clear(); 302 } 186 303 private void ParameterizeSolutionsCreator() { 187 304 SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name; 188 305 SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name; 189 306 } 190 private void ParameterizeSGAMainLoop() { 191 TSMainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name; 307 private void ParameterizeTSMainLoop() { 192 308 TSMainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 193 309 TSMainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 310 if (MoveEvaluator != null) 311 TSMainLoop.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName; 194 312 } 195 313 private void ParameterizeStochasticOperator(IOperator op) { … … 197 315 ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; 198 316 } 199 private void InitializeSelectors() { 200 selectors = new List<ISelector>(); 201 if (ApplicationManager.Manager != null) { 202 selectors.AddRange(ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name)); 203 ParameterizeSelectors(); 204 } 205 } 206 private void ParameterizeSelectors() { 207 foreach (ISelector selector in Selectors) { 208 selector.CopySelected = new BoolValue(true); 209 selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(2 * (PopulationSizeParameter.Value.Value - ElitesParameter.Value.Value)); 210 ParameterizeStochasticOperator(selector); 211 } 212 if (Problem != null) { 213 foreach (ISingleObjectiveSelector selector in Selectors.OfType<ISingleObjectiveSelector>()) { 214 selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 215 selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 216 } 217 } 218 } 219 private void UpdateSelectors() { 220 if (ApplicationManager.Manager != null) { 221 ISelector oldSelector = SelectorParameter.Value; 222 SelectorParameter.ValidValues.Clear(); 223 foreach (ISelector selector in Selectors.OrderBy(x => x.Name)) 224 SelectorParameter.ValidValues.Add(selector); 225 if (oldSelector != null) 226 SelectorParameter.Value = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSelector.GetType()); 227 } 228 } 229 private void UpdateCrossovers() { 230 ICrossover oldCrossover = CrossoverParameter.Value; 231 CrossoverParameter.ValidValues.Clear(); 232 foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name)) 233 CrossoverParameter.ValidValues.Add(crossover); 234 if (oldCrossover != null) 235 CrossoverParameter.Value = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType()); 236 } 237 private void UpdateMutators() { 238 IManipulator oldMutator = MutatorParameter.Value; 239 MutatorParameter.ValidValues.Clear(); 240 foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name)) 241 MutatorParameter.ValidValues.Add(mutator); 242 if (oldMutator != null) 243 MutatorParameter.Value = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType()); 244 } 245 #endregion 246 */ 317 private void ParameterizeMoveEvaluator() { 318 foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) { 319 op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 320 } 321 } 322 private void ParameterizeMoveMaker() { 323 foreach (IMoveMaker op in Problem.Operators.OfType<IMoveMaker>()) { 324 op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 325 if (MoveEvaluator != null) 326 op.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName; 327 } 328 } 329 #endregion 247 330 } 248 331 } -
trunk/sources/HeuristicLab.Algorithms.TS/3.3/TSMainLoop.cs
r3048 r3074 42 42 get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 43 43 } 44 public SubScopesLookupParameter<DoubleValue> QualityParameter { 45 get { return (SubScopesLookupParameter<DoubleValue>)Parameters["Quality"]; } 44 public LookupParameter<DoubleValue> QualityParameter { 45 get { return (LookupParameter<DoubleValue>)Parameters["Quality"]; } 46 } 47 public LookupParameter<DoubleValue> MoveQualityParameter { 48 get { return (LookupParameter<DoubleValue>)Parameters["MoveQuality"]; } 46 49 } 47 50 public ValueLookupParameter<IntValue> MaximumIterationsParameter { … … 57 60 get { return (ValueLookupParameter<IOperator>)Parameters["MoveGenerator"]; } 58 61 } 59 public ValueLookupParameter<IOperator> MoveQualityEvaluatorParameter { 60 get { return (ValueLookupParameter<IOperator>)Parameters["MoveQualityEvaluator"]; } 61 } 62 public ValueLookupParameter<IOperator> MoveTabuEvaluatorParameter { 63 get { return (ValueLookupParameter<IOperator>)Parameters["MoveTabuEvaluator"]; } 64 } 65 public ValueLookupParameter<IOperator> TabuSelectorParameter { 66 get { return (ValueLookupParameter<IOperator>)Parameters["TabuSelector"]; } 67 } 68 public ValueLookupParameter<IOperator> MoveTabuMakerParameter { 69 get { return (ValueLookupParameter<IOperator>)Parameters["MoveTabuMaker"]; } 62 public ValueLookupParameter<IOperator> MoveEvaluatorParameter { 63 get { return (ValueLookupParameter<IOperator>)Parameters["MoveEvaluator"]; } 70 64 } 71 65 public ValueLookupParameter<IOperator> MoveMakerParameter { 72 66 get { return (ValueLookupParameter<IOperator>)Parameters["MoveMaker"]; } 67 } 68 public ValueLookupParameter<IOperator> TabuMoveEvaluatorParameter { 69 get { return (ValueLookupParameter<IOperator>)Parameters["TabuMoveEvaluator"]; } 70 } 71 public ValueLookupParameter<IOperator> TabuMoveMakerParameter { 72 get { return (ValueLookupParameter<IOperator>)Parameters["TabuMoveMaker"]; } 73 73 } 74 74 … … 86 86 Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator.")); 87 87 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); 88 Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); 88 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); 89 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The value which represents the quality of a move.")); 89 90 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.")); 90 91 Parameters.Add(new ValueLookupParameter<IntValue>("TabuTenure", "The length of the tabu list, and also means the number of iterations a move is kept tabu")); … … 92 93 93 94 Parameters.Add(new ValueLookupParameter<IOperator>("MoveGenerator", "The operator that generates the moves.")); 94 Parameters.Add(new ValueLookupParameter<IOperator>("MoveQualityEvaluator", "The operator that evaluates the quality of a move."));95 Parameters.Add(new ValueLookupParameter<IOperator>("MoveTabuEvaluator", "The operator that evaluates whether a move is tabu."));96 Parameters.Add(new ValueLookupParameter<IOperator>("MoveTabuMaker", "The operator that declares a move tabu."));97 95 Parameters.Add(new ValueLookupParameter<IOperator>("MoveMaker", "The operator that performs a move and updates the quality.")); 96 Parameters.Add(new ValueLookupParameter<IOperator>("MoveEvaluator", "The operator that evaluates a move.")); 97 Parameters.Add(new ValueLookupParameter<IOperator>("TabuMoveEvaluator", "The operator that evaluates whether a move is tabu.")); 98 Parameters.Add(new ValueLookupParameter<IOperator>("TabuMoveMaker", "The operator that declares a move tabu.")); 98 99 99 100 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the TS should be applied.")); … … 108 109 Placeholder moveGenerator = new Placeholder(); 109 110 UniformSequentialSubScopesProcessor moveEvaluationProcessor = new UniformSequentialSubScopesProcessor(); 110 Placeholder move QualityEvaluator = new Placeholder();111 Placeholder moveTabuEvaluator = new Placeholder();111 Placeholder moveEvaluator = new Placeholder(); 112 Placeholder tabuMoveEvaluator = new Placeholder(); 112 113 SubScopesSorter moveQualitySorter = new SubScopesSorter(); 113 114 BestAverageWorstQualityCalculator bestAverageWorstMoveQualityCalculator = new BestAverageWorstQualityCalculator(); … … 115 116 RightReducer rightReducer = new RightReducer(); 116 117 UniformSequentialSubScopesProcessor moveMakingProcessor = new UniformSequentialSubScopesProcessor(); 117 Placeholder moveTabuMaker = new Placeholder();118 Placeholder tabuMoveMaker = new Placeholder(); 118 119 Placeholder moveMaker = new Placeholder(); 119 120 DataTableValuesCollector valuesCollector = new DataTableValuesCollector(); … … 143 144 moveGenerator.OperatorParameter.ActualName = "MoveGenerator"; 144 145 145 move QualityEvaluator.Name = "MoveQualityEvaluator (placeholder)";146 move QualityEvaluator.OperatorParameter.ActualName = "MoveQualityEvaluator";147 148 moveTabuEvaluator.Name = "MoveTabuEvaluator (placeholder)";149 moveTabuEvaluator.OperatorParameter.ActualName = "MoveTabuEvaluator";146 moveEvaluator.Name = "MoveEvaluator (placeholder)"; 147 moveEvaluator.OperatorParameter.ActualName = "MoveEvaluator"; 148 149 tabuMoveEvaluator.Name = "TabuMoveEvaluator (placeholder)"; 150 tabuMoveEvaluator.OperatorParameter.ActualName = "TabuMoveEvaluator"; 150 151 151 152 moveQualitySorter.DescendingParameter.ActualName = "Maximization"; … … 162 163 moveMakingProcessor.Name = "MoveMaking processor (UniformSequentialSubScopesProcessor)"; 163 164 164 moveTabuMaker.Name = "MoveTabuMaker (placeholder)";165 moveTabuMaker.OperatorParameter.ActualName = "MoveTabuMaker";165 tabuMoveMaker.Name = "TabuMoveMaker (placeholder)"; 166 tabuMoveMaker.OperatorParameter.ActualName = "TabuMoveMaker"; 166 167 167 168 moveMaker.Name = "MoveMaker (placeholder)"; … … 198 199 mainProcessor.Successor = valuesCollector; 199 200 moveGenerator.Successor = moveEvaluationProcessor; 200 moveEvaluationProcessor.Operator = move QualityEvaluator;201 moveEvaluationProcessor.Operator = moveEvaluator; 201 202 moveEvaluationProcessor.Successor = moveQualitySorter; 202 move QualityEvaluator.Successor = moveTabuEvaluator;203 moveEvaluator.Successor = tabuMoveEvaluator; 203 204 moveQualitySorter.Successor = bestAverageWorstMoveQualityCalculator; 204 205 bestAverageWorstMoveQualityCalculator.Successor = tabuSelector; 205 206 tabuSelector.Successor = rightReducer; 206 207 rightReducer.Successor = moveMakingProcessor; 207 moveMakingProcessor.Operator = moveTabuMaker;208 moveMakingProcessor.Operator = tabuMoveMaker; 208 209 moveMakingProcessor.Successor = subScopesRemover; 209 moveTabuMaker.Successor = moveMaker;210 tabuMoveMaker.Successor = moveMaker; 210 211 valuesCollector.Successor = iterationsCounter; 211 212 iterationsCounter.Successor = iterationsComparator; -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/HeuristicLab.Encodings.PermutationEncoding-3.3.csproj
r3053 r3074 98 98 <Compile Include="Interfaces\IPermutationMoveOperator.cs" /> 99 99 <Compile Include="Interfaces\IPermutationOperator.cs" /> 100 <Compile Include="Interfaces\IThreeOptPermutationMoveOperator.cs" /> 100 101 <Compile Include="Interfaces\ITwoOptPermutationMoveOperator.cs" /> 101 102 <Compile Include="Manipulators\InsertionManipulator.cs" /> … … 106 107 <Compile Include="Manipulators\TranslocationInversionManipulator.cs" /> 107 108 <Compile Include="Manipulators\TranslocationManipulator.cs" /> 109 <Compile Include="Moves\ThreeIndexMove.cs" /> 110 <Compile Include="Moves\ThreeOpt\StochasticThreeOptMoveGenerator.cs" /> 111 <Compile Include="Moves\ThreeOpt\ThreeOptMove.cs" /> 112 <Compile Include="Moves\ThreeOpt\ThreeOptMoveGenerator.cs" /> 108 113 <Compile Include="Moves\TwoOpt\ExhaustiveTwoOptMoveGenerator.cs"> 109 114 <SubType>Code</SubType> … … 120 125 <SubType>Code</SubType> 121 126 </Compile> 122 <Compile Include="Moves\TwoOpt\TwoOptMoveTabuAttribute.cs"> 123 <SubType>Code</SubType> 124 </Compile> 125 <Compile Include="Moves\TwoOpt\TwoOptMoveTabuEvaluator.cs"> 126 <SubType>Code</SubType> 127 </Compile> 128 <Compile Include="Moves\TwoOpt\TwoOptMoveTabuMaker.cs"> 129 <SubType>Code</SubType> 130 </Compile> 127 <Compile Include="Moves\TwoOpt\TwoOptTabuMoveAttribute.cs" /> 128 <Compile Include="Moves\TwoOpt\TwoOptTabuMoveEvaluator.cs" /> 129 <Compile Include="Moves\TwoOpt\TwoOptTabuMoveMaker.cs" /> 131 130 <Compile Include="PermutationManipulator.cs" /> 132 131 <Compile Include="PermutationCrossover.cs" /> -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/StochasticTwoOptMoveGenerator.cs
r3053 r3074 38 38 } 39 39 40 public IntValue SampleSize { 41 get { return SampleSizeParameter.Value; } 42 set { SampleSizeParameter.Value = value; } 43 } 44 40 45 public StochasticTwoOptMoveGenerator() 41 46 : base() { … … 50 55 TwoOptMove[] moves = new TwoOptMove[sampleSize]; 51 56 for (int i = 0; i < sampleSize; i++) { 52 int index1 = random.Next(length - 1); 53 int index2 = random.Next(index1 + 1, length); 57 int index1 = random.Next(length - 1), index2; 58 if (index1 >= 2) 59 index2 = random.Next(index1 + 1, length); 60 else index2 = random.Next(index1 + 1, length - (2 - index1)); 54 61 moves[i] = new TwoOptMove(index1, index2); 55 62 } -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/TwoOptMoveGenerator.cs
r3053 r3074 35 35 } 36 36 public ILookupParameter<TwoOptMove> TwoOptMoveParameter { 37 get { return (LookupParameter<TwoOptMove>)Parameters[" Move"]; }37 get { return (LookupParameter<TwoOptMove>)Parameters["TwoOptMove"]; } 38 38 } 39 39 protected ScopeParameter CurrentScopeParameter { … … 44 44 : base() { 45 45 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The permutation for which moves should be generated.")); 46 Parameters.Add(new LookupParameter<TwoOptMove>(" Move", "The moves that should be generated in subscopes."));46 Parameters.Add(new LookupParameter<TwoOptMove>("TwoOptMove", "The moves that should be generated in subscopes.")); 47 47 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes.")); 48 48 } … … 61 61 62 62 protected abstract TwoOptMove[] GenerateMoves(Permutation permutation); 63 64 public override bool CanChangeName { 65 get { return false; } 66 } 63 67 } 64 68 } -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/TwoOptMoveMaker.cs
r3053 r3074 33 33 public class TwoOptMoveMaker : SingleSuccessorOperator, ITwoOptPermutationMoveOperator, IMoveMaker { 34 34 public ILookupParameter<DoubleValue> QualityParameter { 35 get { return ( LookupParameter<DoubleValue>)Parameters["Quality"]; }35 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } 36 36 } 37 37 public ILookupParameter<DoubleValue> MoveQualityParameter { 38 get { return ( LookupParameter<DoubleValue>)Parameters["MoveQuality"]; }38 get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; } 39 39 } 40 40 public ILookupParameter<TwoOptMove> TwoOptMoveParameter { 41 get { return ( LookupParameter<TwoOptMove>)Parameters["Move"]; }41 get { return (ILookupParameter<TwoOptMove>)Parameters["TwoOptMove"]; } 42 42 } 43 43 public ILookupParameter<Permutation> PermutationParameter { … … 48 48 : base() { 49 49 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the solution.")); 50 Parameters.Add(new LookupParameter<TwoOptMove>(" Move", "The move to evaluate."));50 Parameters.Add(new LookupParameter<TwoOptMove>("TwoOptMove", "The move to evaluate.")); 51 51 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The relative quality of the move.")); 52 52 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The solution as permutation.")); … … 64 64 return base.Apply(); 65 65 } 66 67 public override bool CanChangeName { 68 get { return false; } 69 } 66 70 } 67 71 } -
trunk/sources/HeuristicLab.Problems.TSP/3.3/HeuristicLab.Problems.TSP-3.3.csproj
r3066 r3074 89 89 <Compile Include="Interfaces\ITSPCoordinatesPathEvaluator.cs" /> 90 90 <Compile Include="Interfaces\ITSPEvaluator.cs" /> 91 <Compile Include="Interfaces\ITSPMoveEvaluator.cs" /> 91 92 <Compile Include="Interfaces\ITSPPathEvaluator.cs" /> 92 93 <Compile Include="HeuristicLabProblemsTSPPlugin.cs" /> 93 <Compile Include="MoveEvaluators\TwoOptMoveTSPEvaluator.cs"> 94 <Compile Include="Interfaces\ITSPPathMoveEvaluator.cs" /> 95 <Compile Include="MoveEvaluators\TwoOptMoveTSPRoundedEuclideanPathEvaluator.cs" /> 96 <Compile Include="MoveEvaluators\TSPPathMoveEvaluator.cs" /> 97 <Compile Include="MoveEvaluators\TSPMoveEvaluator.cs" /> 98 <Compile Include="MoveEvaluators\TwoOptMoveTSPCoordinatesPathEvaluator.cs"> 94 99 <SubType>Code</SubType> 95 100 </Compile> -
trunk/sources/HeuristicLab.Problems.TSP/3.3/TSP.cs
r3066 r3074 196 196 OnEvaluatorChanged(); 197 197 } 198 private void MoveGenerator_TwoOptMoveParameter_ActualNameChanged(object sender, EventArgs e) { 199 string name = ((ILookupParameter<TwoOptMove>)sender).ActualName; 200 foreach (ITwoOptPermutationMoveOperator op in Operators.OfType<ITwoOptPermutationMoveOperator>()) { 201 if (!(op is IMoveGenerator)) op.TwoOptMoveParameter.ActualName = name; 202 } 203 } 204 private void MoveGenerator_ThreeOptMoveParameter_ActualNameChanged(object sender, EventArgs e) { 205 string name = ((ILookupParameter<ThreeOptMove>)sender).ActualName; 206 foreach (IThreeOptPermutationMoveOperator op in Operators.OfType<IThreeOptPermutationMoveOperator>()) { 207 if (!(op is IMoveGenerator)) op.ThreeOptMoveParameter.ActualName = name; 208 } 209 } 198 210 #endregion 199 211 … … 228 240 ParameterizeOperators(); 229 241 } 242 InitializeMoveGenerators(); 230 243 } 231 244 private void ParameterizeOperators() { … … 237 250 op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 238 251 } 239 } 252 foreach (IPermutationMoveOperator op in Operators.OfType<IPermutationMoveOperator>()) { 253 op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 254 } 255 foreach (ITSPPathMoveEvaluator op in Operators.OfType<ITSPPathMoveEvaluator>()) { 256 op.CoordinatesParameter.ActualName = CoordinatesParameter.Name; 257 op.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name; 258 op.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name; 259 } 260 } 261 private void InitializeMoveGenerators() { 262 foreach (ITwoOptPermutationMoveOperator op in Operators.OfType<ITwoOptPermutationMoveOperator>()) { 263 if (op is IMoveGenerator) { 264 op.TwoOptMoveParameter.ActualNameChanged += new EventHandler(MoveGenerator_TwoOptMoveParameter_ActualNameChanged); 265 } 266 } 267 foreach (IThreeOptPermutationMoveOperator op in Operators.OfType<IThreeOptPermutationMoveOperator>()) { 268 if (op is IMoveGenerator) { 269 op.ThreeOptMoveParameter.ActualNameChanged += new EventHandler(MoveGenerator_ThreeOptMoveParameter_ActualNameChanged); 270 } 271 } 272 } 273 240 274 private void ClearDistanceMatrix() { 241 275 DistanceMatrixParameter.Value = null;
Note: See TracChangeset
for help on using the changeset viewer.