Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/15/12 09:11:17 (13 years ago)
Author:
gkronber
Message:

#1081 merged r7462:7609 from trunk into time series branch

Location:
branches/HeuristicLab.TimeSeries
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.TimeSeries

  • branches/HeuristicLab.TimeSeries/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs

    r7268 r7615  
    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.