Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/19/10 18:20:30 (15 years ago)
Author:
abeham
Message:

fixed wiring in LS, SA, and TS when problem is changed MoveGenerator becomes null which resulted in a NullReferenceException #933

File:
1 edited

Legend:

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

    r3103 r3131  
    242242      ISingleObjectiveMoveEvaluator oldMoveEvaluator = MoveEvaluator;
    243243      ClearMoveParameters();
    244       List<Type> moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList();
    245       foreach (Type type in moveTypes.ToList()) {
    246         if (moveTypes.Any(t => t != type && type.IsAssignableFrom(t)))
    247           moveTypes.Remove(type);
    248       }
    249       foreach (Type type in moveTypes) {
    250         var operators = Problem.Operators.Where(x => type.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name);
    251         foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>())
    252           MoveMakerParameter.ValidValues.Add(moveMaker);
    253         foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>())
    254           MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
    255       }
    256       if (oldMoveMaker != null) {
    257         IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
    258         if (mm != null) MoveMaker = mm;
    259       }
    260       if (oldMoveEvaluator != null) {
    261         ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
    262         if (me != null) MoveEvaluator = me;
     244      if (MoveGenerator != null) {
     245        List<Type> moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList();
     246        foreach (Type type in moveTypes.ToList()) {
     247          if (moveTypes.Any(t => t != type && type.IsAssignableFrom(t)))
     248            moveTypes.Remove(type);
     249        }
     250        foreach (Type type in moveTypes) {
     251          var operators = Problem.Operators.Where(x => type.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name);
     252          foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>())
     253            MoveMakerParameter.ValidValues.Add(moveMaker);
     254          foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>())
     255            MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
     256        }
     257        if (oldMoveMaker != null) {
     258          IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
     259          if (mm != null) MoveMaker = mm;
     260        }
     261        if (oldMoveEvaluator != null) {
     262          ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
     263          if (me != null) MoveEvaluator = me;
     264        }
    263265      }
    264266    }
Note: See TracChangeset for help on using the changeset viewer.