Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3131 for trunk


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

Location:
trunk/sources
Files:
3 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    }
  • trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs

    r3101 r3131  
    293293      ISingleObjectiveMoveEvaluator oldMoveEvaluator = MoveEvaluator;
    294294      ClearMoveParameters();
    295       List<Type> moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList();
    296       foreach (Type type in moveTypes.ToList()) {
    297         if (moveTypes.Any(t => t != type && type.IsAssignableFrom(t)))
    298           moveTypes.Remove(type);
    299       }
    300       foreach (Type type in moveTypes) {
    301         var operators = Problem.Operators.Where(x => type.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name);
    302         foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>())
    303           MoveMakerParameter.ValidValues.Add(moveMaker);
    304         foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>())
    305           MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
    306       }
    307       if (oldMoveMaker != null) {
    308         IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
    309         if (mm != null) MoveMaker = mm;
    310       }
    311       if (oldMoveEvaluator != null) {
    312         ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
    313         if (me != null) MoveEvaluator = me;
     295      if (MoveGenerator != null) {
     296        List<Type> moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList();
     297        foreach (Type type in moveTypes.ToList()) {
     298          if (moveTypes.Any(t => t != type && type.IsAssignableFrom(t)))
     299            moveTypes.Remove(type);
     300        }
     301        foreach (Type type in moveTypes) {
     302          var operators = Problem.Operators.Where(x => type.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name);
     303          foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>())
     304            MoveMakerParameter.ValidValues.Add(moveMaker);
     305          foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>())
     306            MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
     307        }
     308        if (oldMoveMaker != null) {
     309          IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
     310          if (mm != null) MoveMaker = mm;
     311        }
     312        if (oldMoveEvaluator != null) {
     313          ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
     314          if (me != null) MoveEvaluator = me;
     315        }
    314316      }
    315317    }
  • trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearch.cs

    r3104 r3131  
    284284      ITabuMoveMaker oldTabuMoveMaker = TabuMoveMaker;
    285285      ClearMoveParameters();
    286       List<Type> moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList();
    287       foreach (Type type in moveTypes.ToList()) {
    288         if (moveTypes.Any(t => t != type && type.IsAssignableFrom(t)))
    289           moveTypes.Remove(type);
    290       }
    291       foreach (Type type in moveTypes) {
    292         var operators = Problem.Operators.Where(x => type.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name);
    293         foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>())
    294           MoveMakerParameter.ValidValues.Add(moveMaker);
    295         foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>())
    296           MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
    297         foreach (ITabuMoveEvaluator tabuMoveEvaluator in operators.OfType<ITabuMoveEvaluator>())
    298           TabuMoveEvaluatorParameter.ValidValues.Add(tabuMoveEvaluator);
    299         foreach (ITabuMoveMaker tabuMoveMaker in operators.OfType<ITabuMoveMaker>())
    300           TabuMoveMakerParameter.ValidValues.Add(tabuMoveMaker);
    301       }
    302       if (oldMoveMaker != null) {
    303         IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
    304         if (mm != null) MoveMaker = mm;
    305       }
    306       if (oldMoveEvaluator != null) {
    307         ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
    308         if (me != null) MoveEvaluator = me;
    309       }
    310       if (oldTabuMoveMaker != null) {
    311         ITabuMoveMaker tmm = TabuMoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTabuMoveMaker.GetType());
    312         if (tmm != null) TabuMoveMaker = tmm;
    313       }
    314       if (oldTabuMoveEvaluator != null) {
    315         ITabuMoveEvaluator tme = TabuMoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTabuMoveEvaluator.GetType());
    316         if (tme != null) TabuMoveEvaluator = tme;
     286      if (MoveGenerator != null) {
     287        List<Type> moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList();
     288        foreach (Type type in moveTypes.ToList()) {
     289          if (moveTypes.Any(t => t != type && type.IsAssignableFrom(t)))
     290            moveTypes.Remove(type);
     291        }
     292        foreach (Type type in moveTypes) {
     293          var operators = Problem.Operators.Where(x => type.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name);
     294          foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>())
     295            MoveMakerParameter.ValidValues.Add(moveMaker);
     296          foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>())
     297            MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
     298          foreach (ITabuMoveEvaluator tabuMoveEvaluator in operators.OfType<ITabuMoveEvaluator>())
     299            TabuMoveEvaluatorParameter.ValidValues.Add(tabuMoveEvaluator);
     300          foreach (ITabuMoveMaker tabuMoveMaker in operators.OfType<ITabuMoveMaker>())
     301            TabuMoveMakerParameter.ValidValues.Add(tabuMoveMaker);
     302        }
     303        if (oldMoveMaker != null) {
     304          IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
     305          if (mm != null) MoveMaker = mm;
     306        }
     307        if (oldMoveEvaluator != null) {
     308          ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
     309          if (me != null) MoveEvaluator = me;
     310        }
     311        if (oldTabuMoveMaker != null) {
     312          ITabuMoveMaker tmm = TabuMoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTabuMoveMaker.GetType());
     313          if (tmm != null) TabuMoveMaker = tmm;
     314        }
     315        if (oldTabuMoveEvaluator != null) {
     316          ITabuMoveEvaluator tme = TabuMoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTabuMoveEvaluator.GetType());
     317          if (tme != null) TabuMoveEvaluator = tme;
     318        }
    317319      }
    318320    }
Note: See TracChangeset for help on using the changeset viewer.