Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5202 for branches/VRP


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
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/BestSolution/BestVRPSolutionAnalyzer.cs

    r4860 r5202  
    5858      get { return (LookupParameter<VRPSolution>)Parameters["BestSolution"]; }
    5959    }
     60    public LookupParameter<VRPSolution> BestValidSolutionParameter {
     61      get { return (LookupParameter<VRPSolution>)Parameters["BestValidSolution"]; }
     62    }
    6063    public ValueLookupParameter<ResultCollection> ResultsParameter {
    6164      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
     
    8487        Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("VehiclesUtilized", "The utilized vehicles of the VRP solutions which should be analyzed."));
    8588
    86         Parameters.Add(new LookupParameter<VRPSolution>("BestSolution", "The best TSP solution."));
     89        Parameters.Add(new LookupParameter<VRPSolution>("BestSolution", "The best VRP solution."));
     90        Parameters.Add(new LookupParameter<VRPSolution>("BestValidSolution", "The best valid VRP solution."));
    8791        Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best VRP solution should be stored."));
    8892    }
     
    140144      }
    141145
     146      VRPSolution validSolution = BestValidSolutionParameter.ActualValue;
     147      if (validSolution == null) {
     148        if (ProblemInstanceParameter.ActualValue.Feasible(best)) {
     149          validSolution = new VRPSolution(problemInstance, best.Clone() as IVRPEncoding, new DoubleValue(qualities[i].Value));
     150          BestValidSolutionParameter.ActualValue = validSolution;
     151          results.Add(new Result("Best valid VRP Solution", validSolution));
     152        }
     153      } else {
     154        if (qualities[i].Value <= validSolution.Quality.Value) {
     155          if (ProblemInstanceParameter.ActualValue.Feasible(best)) {
     156            validSolution.ProblemInstance = problemInstance;
     157            validSolution.Solution = best.Clone() as IVRPEncoding;
     158            validSolution.Quality.Value = qualities[i].Value;
     159          }
     160        }
     161      }
     162
    142163      if (bestKnownQuality == null ||
    143164          qualities[i].Value < bestKnownQuality.Value) {
  • 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.