Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7517


Ignore:
Timestamp:
02/24/12 11:44:23 (13 years ago)
Author:
mkommend
Message:

#1691: Updated SimulatedAnnealing to use default operators.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs

    r7259 r7517  
    317317    private void UpdateMoveGenerator() {
    318318      IMultiMoveGenerator oldMoveGenerator = MoveGenerator;
     319      IMultiMoveGenerator defaultMoveGenerator = Problem.Operators.OfType<IMultiMoveGenerator>().FirstOrDefault();
    319320      MoveGeneratorParameter.ValidValues.Clear();
    320321      if (Problem != null) {
     
    325326        IMultiMoveGenerator newMoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType());
    326327        if (newMoveGenerator != null) MoveGenerator = newMoveGenerator;
    327       }
     328        else oldMoveGenerator = null;
     329      }
     330      if (oldMoveGenerator == null && defaultMoveGenerator != null)
     331        MoveGenerator = defaultMoveGenerator;
    328332      if (MoveGenerator == null) {
    329333        ClearMoveParameters();
     
    350354      ISingleObjectiveMoveEvaluator oldMoveEvaluator = MoveEvaluator;
    351355      ClearMoveParameters();
     356
    352357      if (MoveGenerator != null) {
    353358        List<Type> moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList();
     
    356361            moveTypes.Remove(type);
    357362        }
    358         foreach (Type type in moveTypes) {
    359           var operators = Problem.Operators.Where(x => type.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name);
    360           foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>())
    361             MoveMakerParameter.ValidValues.Add(moveMaker);
    362           foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>())
    363             MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
    364         }
     363        var operators = Problem.Operators.Where(op => moveTypes.Any(m => m.IsInstanceOfType(op))).ToList();
     364        IMoveMaker defaultMoveMaker = operators.OfType<IMoveMaker>().FirstOrDefault();
     365        ISingleObjectiveMoveEvaluator defaultMoveEvaluator = operators.OfType<ISingleObjectiveMoveEvaluator>().FirstOrDefault();
     366
     367        foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>().OrderBy(op => op.Name))
     368          MoveMakerParameter.ValidValues.Add(moveMaker);
     369        foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>().OrderBy(op => op.Name))
     370          MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
     371
    365372        if (oldMoveMaker != null) {
    366373          IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
    367374          if (mm != null) MoveMaker = mm;
    368         }
     375          else oldMoveMaker = null;
     376        }
     377        if (oldMoveMaker == null && defaultMoveMaker != null)
     378          MoveMaker = defaultMoveMaker;
     379
    369380        if (oldMoveEvaluator != null) {
    370381          ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
    371382          if (me != null) MoveEvaluator = me;
    372         }
     383          else oldMoveEvaluator = null;
     384        }
     385        if (oldMoveEvaluator == null & defaultMoveEvaluator != null)
     386          MoveEvaluator = defaultMoveEvaluator;
    373387      }
    374388    }
Note: See TracChangeset for help on using the changeset viewer.