Changeset 7516
- Timestamp:
- 02/24/12 11:39:50 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearch.cs
r7259 r7516 348 348 private void UpdateMoveGenerator() { 349 349 IMoveGenerator oldMoveGenerator = MoveGenerator; 350 IMoveGenerator defaultMoveGenerator = Problem.Operators.OfType<IMoveGenerator>().FirstOrDefault(); 350 351 MoveGeneratorParameter.ValidValues.Clear(); 351 352 if (Problem != null) { … … 356 357 if (oldMoveGenerator != null && MoveGeneratorParameter.ValidValues.Any(x => x.GetType() == oldMoveGenerator.GetType())) 357 358 MoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType()); 359 if (MoveGenerator == null && defaultMoveGenerator != null) 360 MoveGenerator = defaultMoveGenerator; 361 358 362 if (MoveGenerator == null) { 359 363 ClearMoveParameters(); … … 363 367 IMoveMaker oldMoveMaker = MoveMaker; 364 368 ISingleObjectiveMoveEvaluator oldMoveEvaluator = MoveEvaluator; 365 ITabuChecker oldTabu MoveEvaluator = TabuChecker;369 ITabuChecker oldTabuChecker = TabuChecker; 366 370 ITabuMaker oldTabuMoveMaker = TabuMaker; 367 371 ClearMoveParameters(); … … 372 376 moveTypes.Remove(type); 373 377 } 374 foreach (Type type in moveTypes) { 375 var operators = Problem.Operators.Where(x => type.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name); 376 foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>()) 377 MoveMakerParameter.ValidValues.Add(moveMaker); 378 foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>()) 379 MoveEvaluatorParameter.ValidValues.Add(moveEvaluator); 380 foreach (ITabuChecker tabuMoveEvaluator in operators.OfType<ITabuChecker>()) 381 TabuCheckerParameter.ValidValues.Add(tabuMoveEvaluator); 382 foreach (ITabuMaker tabuMoveMaker in operators.OfType<ITabuMaker>()) 383 TabuMakerParameter.ValidValues.Add(tabuMoveMaker); 384 } 378 379 var operators = Problem.Operators.Where(op => moveTypes.Any(m => m.IsInstanceOfType(op))).ToList(); 380 IMoveMaker defaultMoveMaker = operators.OfType<IMoveMaker>().FirstOrDefault(); 381 ISingleObjectiveMoveEvaluator defaultMoveEvaluator = operators.OfType<ISingleObjectiveMoveEvaluator>().FirstOrDefault(); 382 ITabuChecker defaultTabuChecker = operators.OfType<ITabuChecker>().FirstOrDefault(); 383 ITabuMaker defaultTabuMaker = operators.OfType<ITabuMaker>().FirstOrDefault(); 384 385 foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>()) 386 MoveMakerParameter.ValidValues.Add(moveMaker); 387 foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>()) 388 MoveEvaluatorParameter.ValidValues.Add(moveEvaluator); 389 foreach (ITabuChecker tabuMoveEvaluator in operators.OfType<ITabuChecker>()) 390 TabuCheckerParameter.ValidValues.Add(tabuMoveEvaluator); 391 foreach (ITabuMaker tabuMoveMaker in operators.OfType<ITabuMaker>()) 392 TabuMakerParameter.ValidValues.Add(tabuMoveMaker); 393 385 394 if (oldMoveMaker != null) { 386 395 IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType()); 387 396 if (mm != null) MoveMaker = mm; 388 } 397 else oldMoveMaker = null; 398 } 399 if (oldMoveMaker == null && defaultMoveMaker != null) 400 MoveMaker = defaultMoveMaker; 401 389 402 if (oldMoveEvaluator != null) { 390 403 ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType()); 391 404 if (me != null) MoveEvaluator = me; 392 } 405 else oldMoveEvaluator = null; 406 } 407 if (oldMoveEvaluator == null && defaultMoveEvaluator != null) 408 MoveEvaluator = defaultMoveEvaluator; 409 393 410 if (oldTabuMoveMaker != null) { 394 411 ITabuMaker tmm = TabuMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTabuMoveMaker.GetType()); 395 412 if (tmm != null) TabuMaker = tmm; 396 } 397 if (oldTabuMoveEvaluator != null) { 398 ITabuChecker tme = TabuCheckerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTabuMoveEvaluator.GetType()); 413 else oldTabuMoveMaker = null; 414 } 415 if (oldTabuMoveMaker == null && defaultTabuMaker != null) 416 TabuMaker = defaultTabuMaker; 417 418 if (oldTabuChecker != null) { 419 ITabuChecker tme = TabuCheckerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTabuChecker.GetType()); 399 420 if (tme != null) TabuChecker = tme; 400 } 421 else oldTabuChecker = null; 422 } 423 if (oldTabuChecker == null && defaultTabuChecker != null) 424 TabuChecker = defaultTabuChecker; 401 425 } 402 426 }
Note: See TracChangeset
for help on using the changeset viewer.