Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11300 for trunk/sources


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.

Location:
trunk/sources
Files:
1 added
11 edited

Legend:

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

    r11171 r11300  
    3838  [Item("LocalSearchImprovementOperator", "A local search improvement operator.")]
    3939  [StorableClass]
    40   public sealed class LocalSearchImprovementOperator : SingleSuccessorOperator, ILocalImprovementOperator, IStochasticOperator {
     40  public sealed class LocalSearchImprovementOperator : SingleSuccessorOperator, ILocalImprovementAlgorithmOperator, IStochasticOperator {
    4141    #region IGenericLocalImprovementOperator Properties
    4242    public Type ProblemType { get { return typeof(ISingleObjectiveHeuristicOptimizationProblem); } }
  • trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealingImprovementOperator.cs

    r11171 r11300  
    3838  [Item("SimulatedAnnealingImprovementOperator", "A simulated annealing improvement operator.")]
    3939  [StorableClass]
    40   public sealed class SimulatedAnnealingImprovementOperator : SingleSuccessorOperator, ILocalImprovementOperator, IStochasticOperator {
     40  public sealed class SimulatedAnnealingImprovementOperator : SingleSuccessorOperator, ILocalImprovementAlgorithmOperator, IStochasticOperator {
    4141    #region IGenericLocalImprovementOperator Properties
    4242    public Type ProblemType { get { return typeof(ISingleObjectiveHeuristicOptimizationProblem); } }
  • 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        }
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r9438 r11300  
    114114  </ItemGroup>
    115115  <ItemGroup>
     116    <Compile Include="Interfaces\ILocalImprovementAlgorithmOperator.cs" />
    116117    <Compile Include="Interfaces\ISingleObjectivePathRelinker.cs" />
    117118    <Compile Include="Interfaces\ISingleObjectiveImprovementOperator.cs" />
  • trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/ILocalImprovementOperator.cs

    r11171 r11300  
    2020#endregion
    2121
    22 using System;
    2322using HeuristicLab.Core;
    2423using HeuristicLab.Data;
     
    2625namespace HeuristicLab.Optimization {
    2726  public interface ILocalImprovementOperator : IOperator {
    28     Type ProblemType { get; }
    29     IProblem Problem { get; set; }
    3027    IValueLookupParameter<IntValue> MaximumIterationsParameter { get; }
    3128    ILookupParameter<IntValue> EvaluatedSolutionsParameter { get; }
  • trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/LocalImprovement/QAPExhaustiveInsertionLocalImprovement.cs

    r11171 r11300  
    3535  [StorableClass]
    3636  public class QAPExhaustiveInsertionLocalImprovement : SingleSuccessorOperator, ILocalImprovementOperator {
    37 
    38     public Type ProblemType {
    39       get { return typeof(QuadraticAssignmentProblem); }
    40     }
    41 
    42     [Storable]
    43     private QuadraticAssignmentProblem problem;
    44     public IProblem Problem {
    45       get { return problem; }
    46       set { problem = (QuadraticAssignmentProblem)value; }
    47     }
    4837
    4938    public ILookupParameter<IntValue> LocalIterationsParameter {
     
    8776    protected QAPExhaustiveInsertionLocalImprovement(QAPExhaustiveInsertionLocalImprovement original, Cloner cloner)
    8877      : base(original, cloner) {
    89       this.problem = cloner.Clone(original.problem);
    9078    }
    9179    public QAPExhaustiveInsertionLocalImprovement()
  • trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/LocalImprovement/QAPExhaustiveInversionLocalImprovement.cs

    r11171 r11300  
    3535  [StorableClass]
    3636  public class QAPExhaustiveInversionLocalImprovement : SingleSuccessorOperator, ILocalImprovementOperator {
    37 
    38     public Type ProblemType {
    39       get { return typeof(QuadraticAssignmentProblem); }
    40     }
    41 
    42     [Storable]
    43     private QuadraticAssignmentProblem problem;
    44     public IProblem Problem {
    45       get { return problem; }
    46       set { problem = (QuadraticAssignmentProblem)value; }
    47     }
    4837
    4938    public ILookupParameter<IntValue> LocalIterationsParameter {
     
    8776    protected QAPExhaustiveInversionLocalImprovement(QAPExhaustiveInversionLocalImprovement original, Cloner cloner)
    8877      : base(original, cloner) {
    89       this.problem = cloner.Clone(original.problem);
    9078    }
    9179    public QAPExhaustiveInversionLocalImprovement()
  • trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/LocalImprovement/QAPExhaustiveSwap2LocalImprovement.cs

    r11171 r11300  
    3535  [StorableClass]
    3636  public class QAPExhaustiveSwap2LocalImprovement : SingleSuccessorOperator, ILocalImprovementOperator {
    37 
    38     public Type ProblemType {
    39       get { return typeof(QuadraticAssignmentProblem); }
    40     }
    41 
    42     [Storable]
    43     private QuadraticAssignmentProblem problem;
    44     public IProblem Problem {
    45       get { return problem; }
    46       set { problem = (QuadraticAssignmentProblem)value; }
    47     }
    4837
    4938    public ILookupParameter<IntValue> LocalIterationsParameter {
     
    9180    protected QAPExhaustiveSwap2LocalImprovement(QAPExhaustiveSwap2LocalImprovement original, Cloner cloner)
    9281      : base(original, cloner) {
    93       this.problem = cloner.Clone(original.problem);
    9482    }
    9583    public QAPExhaustiveSwap2LocalImprovement()
  • trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/LocalImprovement/QAPStochasticScrambleLocalImprovement.cs

    r11171 r11300  
    3535  [StorableClass]
    3636  public class QAPStochasticScrambleLocalImprovement : SingleSuccessorOperator, ILocalImprovementOperator, IStochasticOperator {
    37 
    38     public Type ProblemType {
    39       get { return typeof(QuadraticAssignmentProblem); }
    40     }
    41 
    42     [Storable]
    43     private QuadraticAssignmentProblem problem;
    44     public IProblem Problem {
    45       get { return problem; }
    46       set { problem = (QuadraticAssignmentProblem)value; }
    47     }
    4837
    4938    public ILookupParameter<IntValue> LocalIterationsParameter {
     
    9584    protected QAPStochasticScrambleLocalImprovement(QAPStochasticScrambleLocalImprovement original, Cloner cloner)
    9685      : base(original, cloner) {
    97       this.problem = cloner.Clone(original.problem);
    9886    }
    9987    public QAPStochasticScrambleLocalImprovement()
  • trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs

    r11171 r11300  
    302302      Operators.Add(new QAPAlleleFrequencyAnalyzer());
    303303      Operators.Add(new QAPPopulationDiversityAnalyzer());
     304
     305      Operators.Add(new QAPExhaustiveInsertionLocalImprovement());
     306      Operators.Add(new QAPExhaustiveInversionLocalImprovement());
     307      Operators.Add(new QAPStochasticScrambleLocalImprovement());
    304308      Operators.Add(new QAPExhaustiveSwap2LocalImprovement());
     309
    305310      Operators.Add(new QAPSimilarityCalculator());
    306311      ParameterizeAnalyzers();
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/LocalImprovement/AlbaLambdaInterchangeLocalImprovementOperator.cs

    r11171 r11300  
    3737  [StorableClass]
    3838  public class AlbaLambdaInterchangeLocalImprovementOperator : VRPOperator, IStochasticOperator, ILocalImprovementOperator {
    39     public Type ProblemType {
    40       get { return typeof(VehicleRoutingProblem); }
    41     }
    42 
    43     [Storable]
    44     private VehicleRoutingProblem problem;
    45     public IProblem Problem {
    46       get { return problem; }
    47       set { problem = (VehicleRoutingProblem)value; }
    48     }
    4939
    5040    public IValueLookupParameter<IntValue> MaximumIterationsParameter {
     
    8474    protected AlbaLambdaInterchangeLocalImprovementOperator(AlbaLambdaInterchangeLocalImprovementOperator original, Cloner cloner)
    8575      : base(original, cloner) {
    86         this.problem = cloner.Clone(original.problem);
    8776    }
    8877    public AlbaLambdaInterchangeLocalImprovementOperator()
     
    10291    }
    10392
    104     public static void Apply(AlbaEncoding solution, int maxIterations, 
     93    public static void Apply(AlbaEncoding solution, int maxIterations,
    10594      int lambda, int samples, IRandom random, IVRPProblemInstance problemInstance, ref double quality, out int evaluatedSolutions) {
    10695      evaluatedSolutions = 0;
     
    120109          }
    121110        }
    122         if (bestMove != null) 
     111        if (bestMove != null)
    123112          AlbaLambdaInterchangeMoveMaker.Apply(solution, bestMove);
    124113      }
Note: See TracChangeset for help on using the changeset viewer.