Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/03/11 16:19:17 (14 years ago)
Author:
svonolfe
Message:

Added usage of the TS memory in the customer relocation move (#1177)

Location:
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/CustomerRelocation/PotvinCustomerRelocationMoveEvaluator.cs

    r5127 r5202  
    4040    }
    4141
    42     public ILookupParameter<IMemory> MemoryParameter {
    43       get { return (ILookupParameter<IMemory>)Parameters["Memory"]; }
     42    public ILookupParameter<VariableCollection> MemoriesParameter {
     43      get { return (ILookupParameter<VariableCollection>)Parameters["Memories"]; }
    4444    }
    4545
    46     public IValueParameter<StringValue> AdditionFrequencyParameter {
    47       get { return (IValueParameter<StringValue>)Parameters["AdditionFrequency"]; }
     46    public IValueParameter<StringValue> AdditionFrequencyMemoryKeyParameter {
     47      get { return (IValueParameter<StringValue>)Parameters["AdditionFrequencyMemoryKey"]; }
    4848    }
    4949
     
    5959       Parameters.Add(new LookupParameter<PotvinCustomerRelocationMove>("PotvinCustomerRelocationMove", "The move that should be evaluated."));
    6060
    61        Parameters.Add(new LookupParameter<IMemory>("Memory", "The TS memory."));
    62        Parameters.Add(new ValueParameter<StringValue>("AdditionFrequency", "The key that is used for the addition frequency in the TS memory.", new StringValue("AdditionFrequency")));
     61       Parameters.Add(new LookupParameter<VariableCollection>("Memories", "The TS memory collection."));
     62       Parameters.Add(new ValueParameter<StringValue>("AdditionFrequencyMemoryKey", "The key that is used for the addition frequency in the TS memory.", new StringValue("AdditionFrequency")));
    6363       Parameters.Add(new ValueParameter<DoubleValue>("Lambda", "The lambda parameter.", new DoubleValue(0.015)));
    6464    }
     
    8282      //Apply memory, only if move is worse
    8383      if (MoveQualityParameter.ActualValue.Value >= QualityParameter.ActualValue.Value) {
    84         IMemory memory = MemoryParameter.ActualValue;
    85         string key = AdditionFrequencyParameter.Value.Value;
    86         ItemDictionary<PotvinCustomerRelocationMoveAttribute, IntValue> additionFrequency =
    87           memory.Get(key) as ItemDictionary<PotvinCustomerRelocationMoveAttribute, IntValue>;
    88         if (additionFrequency != null) {
     84        VariableCollection memory = MemoriesParameter.ActualValue;
     85        string key = AdditionFrequencyMemoryKeyParameter.Value.Value;
     86
     87        if (memory.ContainsKey(key)) {
     88          ItemDictionary<PotvinCustomerRelocationMoveAttribute, IntValue> additionFrequency =
     89               memory[key].Value as ItemDictionary<PotvinCustomerRelocationMoveAttribute, IntValue>;
    8990          PotvinCustomerRelocationMoveAttribute attr = new PotvinCustomerRelocationMoveAttribute(0, move.Tour, move.City);
    9091          if (additionFrequency.ContainsKey(attr)) {
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/CustomerRelocation/PotvinCustomerRelocationMoveMaker.cs

    r5127 r5202  
    5353    }
    5454
    55     public ILookupParameter<IMemory> MemoryParameter {
    56       get { return (ILookupParameter<IMemory>)Parameters["Memory"]; }
     55    public ILookupParameter<VariableCollection> MemoriesParameter {
     56      get { return (ILookupParameter<VariableCollection>)Parameters["Memories"]; }
    5757    }
    5858
    59     public IValueParameter<StringValue> AdditionFrequencyParameter {
    60       get { return (IValueParameter<StringValue>)Parameters["AdditionFrequency"]; }
     59    public IValueParameter<StringValue> AdditionFrequencyMemoryKeyParameter {
     60      get { return (IValueParameter<StringValue>)Parameters["AdditionFrequencyMemoryKey"]; }
    6161    }
    6262
     
    7171      Parameters.Add(new ValueParameter<DoubleValue>("MaxPenaltyFactor", "The maximum penalty factor.", new DoubleValue(1000.0)));
    7272
    73       Parameters.Add(new LookupParameter<IMemory>("Memory", "The TS memory."));
    74       Parameters.Add(new ValueParameter<StringValue>("AdditionFrequency", "The key that is used for the addition frequency in the TS memory.", new StringValue("AdditionFrequency")));
     73      Parameters.Add(new LookupParameter<VariableCollection>("Memories", "The TS memory collection."));
     74      Parameters.Add(new ValueParameter<StringValue>("AdditionFrequencyMemoryKey", "The key that is used for the addition frequency in the TS memory.", new StringValue("AdditionFrequency")));
    7575    }
    7676
     
    122122
    123123      //update memory
    124       IMemory memory = MemoryParameter.ActualValue;
    125       string key = AdditionFrequencyParameter.Value.Value;
     124      VariableCollection memory = MemoriesParameter.ActualValue;
     125      string key = AdditionFrequencyMemoryKeyParameter.Value.Value;
     126
     127      if (!memory.ContainsKey(key)) {
     128        memory.Add(new Variable(key,
     129            new ItemDictionary<PotvinCustomerRelocationMoveAttribute, IntValue>()));
     130      }
    126131      ItemDictionary<PotvinCustomerRelocationMoveAttribute, IntValue> additionFrequency =
    127         memory.Get(key) as ItemDictionary<PotvinCustomerRelocationMoveAttribute, IntValue>;
    128       if (additionFrequency == null) {
    129         additionFrequency = new ItemDictionary<PotvinCustomerRelocationMoveAttribute, IntValue>();
    130         memory.Put(key, additionFrequency);
    131       }
     132        memory[key].Value as ItemDictionary<PotvinCustomerRelocationMoveAttribute, IntValue>;
     133
    132134      PotvinCustomerRelocationMoveAttribute attr = new PotvinCustomerRelocationMoveAttribute(0, move.Tour, move.City);
    133135      if (!additionFrequency.ContainsKey(attr))
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/PotvinEncoding.cs

    r5127 r5202  
    7979    }
    8080
    81     public double EvaluateTour(Tour tour) {
    82       return ProblemInstance.Evaluate(tour);
    83     }
    84 
    8581    public double GetTourLength(Tour tour) {
    8682      double length = 0;
     
    109105        tour.Stops.Insert(i, city);
    110106
    111         double quality = EvaluateTour(tour);
     107        VRPEvaluation eval = ProblemInstance.EvaluatorParameter.Value.Evaluate(ProblemInstance, tour);
     108        double quality = eval.Quality + eval.Penalty * (PenaltyFactor - 1.0);
    112109
    113110        if (place < 0 || quality < minQuality) {
Note: See TracChangeset for help on using the changeset viewer.