Ignore:
Timestamp:
02/24/12 09:04:07 (8 years ago)
Author:
mkommend
Message:

#1691: Updated LocalSearch to use default operators.

File:
1 edited

Legend:

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

    r7259 r7510  
    289289    private void UpdateMoveGenerator() {
    290290      IMoveGenerator oldMoveGenerator = MoveGenerator;
     291      IMoveGenerator defaultMoveGenerator = Problem.Operators.OfType<IMoveGenerator>().FirstOrDefault();
    291292      MoveGeneratorParameter.ValidValues.Clear();
    292293      if (Problem != null) {
     
    297298        IMoveGenerator newMoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType());
    298299        if (newMoveGenerator != null) MoveGenerator = newMoveGenerator;
    299       }
     300        else oldMoveGenerator = null;
     301      }
     302      if (oldMoveGenerator == null && defaultMoveGenerator != null)
     303        MoveGenerator = defaultMoveGenerator;
    300304      if (MoveGenerator == null) {
    301305        ClearMoveParameters();
     
    312316            moveTypes.Remove(type);
    313317        }
    314         foreach (Type type in moveTypes) {
    315           var operators = Problem.Operators.Where(x => type.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name);
    316           foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>())
    317             MoveMakerParameter.ValidValues.Add(moveMaker);
    318           foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>())
    319             MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
    320         }
     318
     319        var operators = Problem.Operators.Where(op => moveTypes.Any(m => m.IsInstanceOfType(op))).ToList();
     320        IMoveMaker defaultMoveMaker = operators.OfType<IMoveMaker>().FirstOrDefault();
     321        ISingleObjectiveMoveEvaluator defaultMoveEvaluator = operators.OfType<ISingleObjectiveMoveEvaluator>().FirstOrDefault();
     322        foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>().OrderBy(op => op.Name))
     323          MoveMakerParameter.ValidValues.Add(moveMaker);
     324        foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>().OrderBy(op => op.Name))
     325          MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
     326
    321327        if (oldMoveMaker != null) {
    322328          IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
    323329          if (mm != null) MoveMaker = mm;
    324         }
     330          else oldMoveMaker = null;
     331        }
     332        if (oldMoveMaker == null && defaultMoveMaker != null)
     333          MoveMaker = defaultMoveMaker;
     334
    325335        if (oldMoveEvaluator != null) {
    326336          ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
    327337          if (me != null) MoveEvaluator = me;
    328         }
     338          else oldMoveEvaluator = null;
     339        }
     340        if (oldMoveEvaluator == null && defaultMoveEvaluator != null)
     341          MoveEvaluator = defaultMoveEvaluator;
    329342      }
    330343    }
Note: See TracChangeset for help on using the changeset viewer.