Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/26/14 11:12:16 (10 years ago)
Author:
pfleck
Message:

#2232
Introduced ILocalImprovementAlgorithmOperator to separate single operators for local improvement and operator graphs/algorithms for local improvement.
This way the ILocalImprovementOperator does not have to specify a problem type and does not store a problem any more.

The LocalSearchImprovementOperator and SimulatedAnnealingImprovementOperator implement the new ILocalImprovementAlgorithmOperator as they represent an operator graph for local improvement.
The QAP and VRP local improvement operators implement the ILocalImprovementOperator which does not store a problem anymore.

File:
1 edited

Legend:

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

    r11171 r11300  
    283283    private void ParameterizeLocalImprovementOperators() {
    284284      foreach (ILocalImprovementOperator op in LocalImprovementParameter.ValidValues) {
    285         if (op != LocalImprovementParameter.Value) op.Problem = null;
    286285        op.MaximumIterationsParameter.Value = null;
    287286        op.MaximumIterationsParameter.ActualName = LocalImprovementMaximumIterationsParameter.Name;
    288       }
    289       if (LocalImprovementParameter.Value != null)
    290         LocalImprovementParameter.Value.Problem = Problem;
     287
     288        var algOp = op as ILocalImprovementAlgorithmOperator;
     289        if (algOp != null && algOp != LocalImprovementParameter.Value) algOp.Problem = null;
     290      }
     291      if (LocalImprovementParameter.Value is ILocalImprovementAlgorithmOperator)
     292        ((ILocalImprovementAlgorithmOperator)LocalImprovementParameter.Value).Problem = Problem;
    291293    }
    292294    private void InitializeLocalImprovementOperators() {
     
    294296        LocalImprovementParameter.ValidValues.Clear();
    295297      } else {
    296         foreach (var entry in LocalImprovementParameter.ValidValues.ToList()) {
    297           if (!entry.ProblemType.IsAssignableFrom(Problem.GetType())) {
    298             LocalImprovementParameter.ValidValues.Remove(entry);
     298        foreach (var algOp in LocalImprovementParameter.ValidValues.OfType<ILocalImprovementAlgorithmOperator>()) {
     299          if (!algOp.ProblemType.IsInstanceOfType(Problem)) {
     300            LocalImprovementParameter.ValidValues.Remove(algOp);
    299301          }
    300302        }
    301         foreach (ILocalImprovementOperator op in ApplicationManager.Manager.GetInstances<ILocalImprovementOperator>().Where(x => x.ProblemType.IsAssignableFrom(Problem.GetType()))) {
    302           if (!LocalImprovementParameter.ValidValues.Any(x => x.GetType() == op.GetType()))
     303        // Regular ILocalImprovementOperators queried from Problem
     304        foreach (var op in Problem.Operators.OfType<ILocalImprovementOperator>().Where(x => !(x is ILocalImprovementAlgorithmOperator))) {
     305          LocalImprovementParameter.ValidValues.Add(op);
     306        }
     307        // ILocalImprovementAlgorithmOperators queried from ApplicationManager
     308        var algOps = ApplicationManager.Manager.GetInstances<ILocalImprovementAlgorithmOperator>()
     309                                               .Where(x => x.ProblemType.IsInstanceOfType(Problem));
     310        foreach (var op in algOps) {
     311          if (LocalImprovementParameter.ValidValues.All(x => x.GetType() != op.GetType()))
    303312            LocalImprovementParameter.ValidValues.Add(op);
    304313        }
Note: See TracChangeset for help on using the changeset viewer.