Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/12/12 13:32:46 (12 years ago)
Author:
jkarder
Message:

#1331:

  • improved path relinking and improvement operators for the VehicleRouting problem
  • recreated SS VRP sample
  • corrected SS VRP sample test
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Improver/VRPImprovementOperator.cs

    r8346 r8894  
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2929using HeuristicLab.Problems.VehicleRouting.Encodings;
    30 using HeuristicLab.Problems.VehicleRouting.Encodings.Alba;
    3130using HeuristicLab.Problems.VehicleRouting.Encodings.Potvin;
    3231using HeuristicLab.Problems.VehicleRouting.Interfaces;
     
    3534namespace HeuristicLab.Problems.VehicleRouting {
    3635  /// <summary>
    37   /// An operator that improves vehicle routing solutions.
     36  /// A base class for operators which improve VRP solutions.
    3837  /// </summary>
    39   [Item("VRPImprovementOperator", "An operator that improves vehicle routing solutions.")]
     38  [Item("VRPImprovementOperator", "A base class for operators which improve VRP solutions.")]
    4039  [StorableClass]
    41   public sealed class VRPImprovementOperator : VRPOperator, IGeneralVRPOperator, ISingleObjectiveImprovementOperator {
     40  public abstract class VRPImprovementOperator : VRPOperator, IGeneralVRPOperator, ISingleObjectiveImprovementOperator {
    4241    #region Parameter properties
    4342    public ScopeParameter CurrentScopeParameter {
     
    4746      get { return (IValueParameter<IntValue>)Parameters["ImprovementAttempts"]; }
    4847    }
    49     public IValueParameter<IntValue> LambdaParameter {
    50       get { return (IValueParameter<IntValue>)Parameters["Lambda"]; }
     48    public IValueLookupParameter<IntValue> LocalEvaluatedSolutions {
     49      get { return (IValueLookupParameter<IntValue>)Parameters["LocalEvaluatedSolutions"]; }
    5150    }
    5251    public ILookupParameter<IRandom> RandomParameter {
     
    6261
    6362    [StorableConstructor]
    64     private VRPImprovementOperator(bool deserializing) : base(deserializing) { }
    65     private VRPImprovementOperator(VRPImprovementOperator original, Cloner cloner) : base(original, cloner) { }
    66     public VRPImprovementOperator()
     63    protected VRPImprovementOperator(bool deserializing) : base(deserializing) { }
     64    protected VRPImprovementOperator(VRPImprovementOperator original, Cloner cloner) : base(original, cloner) { }
     65    protected VRPImprovementOperator()
    6766      : base() {
    6867      #region Create parameters
    6968      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the solution to be improved."));
    7069      Parameters.Add(new ValueParameter<IntValue>("ImprovementAttempts", "The number of improvement attempts the operator should perform.", new IntValue(100)));
    71       Parameters.Add(new ValueParameter<IntValue>("Lambda", "The number of neighbors that should be exchanged.", new IntValue(1)));
     70      Parameters.Add(new ValueLookupParameter<IntValue>("LocalEvaluatedSolutions", "The number of evaluated solutions."));
    7271      Parameters.Add(new LookupParameter<IRandom>("Random", "A pseudo random number generator."));
    73       Parameters.Add(new ValueParameter<IntValue>("SampleSize", "The number of moves that should be executed.", new IntValue(100)));
     72      Parameters.Add(new ValueParameter<IntValue>("SampleSize", "The number of moves that should be executed.", new IntValue(25)));
    7473      Parameters.Add(new ValueLookupParameter<IItem>("Solution", "The solution to be improved. This parameter is used for name translation only."));
    7574      #endregion
    7675    }
    7776
    78     public override IDeepCloneable Clone(Cloner cloner) {
    79       return new VRPImprovementOperator(this, cloner);
    80     }
    81 
    8277    public override IOperation Apply() {
    83       AlbaEncoding solution = SolutionParameter.ActualValue is AlbaEncoding
    84                                 ? SolutionParameter.ActualValue as AlbaEncoding
    85                                 : AlbaEncoding.ConvertFrom(SolutionParameter.ActualValue as IVRPEncoding, ProblemInstance);
     78      var solution = SolutionParameter.ActualValue as IVRPEncoding;
     79      var potvinSolution = solution is PotvinEncoding ? solution as PotvinEncoding : PotvinEncoding.ConvertFrom(solution, ProblemInstance);
    8680
    8781      if (solution == null)
    8882        throw new ArgumentException("Cannot improve solution because it has the wrong type.");
    8983
    90       double quality = -1;
    91       int evaluatedSolutions;
     84      int evaluatedSolutions = Improve(potvinSolution);
    9285
    93       AlbaLambdaInterchangeLocalImprovementOperator.Apply(solution, ImprovementAttemptsParameter.Value.Value,
    94                                                           LambdaParameter.Value.Value, SampleSizeParameter.Value.Value,
    95                                                           RandomParameter.ActualValue, ProblemInstance, ref quality,
    96                                                           out evaluatedSolutions);
    97 
    98       SolutionParameter.ActualValue = PotvinEncoding.ConvertFrom(solution, ProblemInstance);
    99       CurrentScopeParameter.ActualValue.Variables.Add(new Variable("LocalEvaluatedSolutions", new IntValue(evaluatedSolutions)));
     86      SolutionParameter.ActualValue = solution;
     87      LocalEvaluatedSolutions.ActualValue = new IntValue(evaluatedSolutions);
    10088
    10189      return base.Apply();
    10290    }
     91
     92    protected abstract int Improve(PotvinEncoding solution);
    10393  }
    10494}
Note: See TracChangeset for help on using the changeset viewer.