Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/06/10 16:08:46 (14 years ago)
Author:
svonolfe
Message:

Refactored VRP, added some Potvin operators (WIP) (#1039)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Tour.cs

    r4068 r4174  
    2222using HeuristicLab.Core;
    2323using HeuristicLab.Data;
     24using System.Collections.Generic;
     25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using HeuristicLab.Common;
    2427
    2528namespace HeuristicLab.Problems.VehicleRouting.Encodings {
    26   public class Tour : ItemList<IntValue> {
     29  [StorableClass]
     30  public class Tour : Item {
     31    [Storable]
     32    public List<int> Cities { get; private set; }
     33
     34    public Tour() {
     35      Cities = new List<int>();
     36    }
     37
     38    public override IDeepCloneable Clone(Cloner cloner) {
     39      Tour clone = base.Clone(cloner) as Tour;
     40      clone.Cities = new List<int>(Cities);
     41
     42      return clone;
     43    }
     44
     45    public bool Feasible(DoubleArray dueTimeArray,
     46      DoubleArray serviceTimeArray, DoubleArray readyTimeArray, DoubleArray demandArray, DoubleValue capacity,
     47      DoubleMatrix coordinates, ILookupParameter<DoubleMatrix> distanceMatrix, BoolValue useDistanceMatrix) {
     48      TourEvaluation eval = VRPEvaluator.EvaluateTour(this,
     49        dueTimeArray,
     50        serviceTimeArray,
     51        readyTimeArray,
     52        demandArray,
     53        capacity,
     54        new DoubleValue(0),
     55        new DoubleValue(0),
     56        new DoubleValue(0),
     57        new DoubleValue(1),
     58        new DoubleValue(1),
     59        coordinates,
     60        distanceMatrix,
     61        useDistanceMatrix);
     62
     63      return eval.Overload < double.Epsilon && eval.Tardiness < double.Epsilon;
     64    }
     65   
     66    public double GetLength(DoubleMatrix coordinates,
     67      ILookupParameter<DoubleMatrix> distanceMatrix,
     68      BoolValue useDistanceMatrix) {
     69      double length = 0;
     70
     71      if (Cities.Count > 0) {
     72        List<int> cities = new List<int>();
     73        cities.Add(0);
     74        foreach (int city in Cities) {
     75          cities.Add(city);
     76        }
     77        cities.Add(0);
     78
     79        for (int i = 1; i < cities.Count; i++) {
     80          length += VRPUtilities.GetDistance(
     81            cities[i - 1], cities[i], coordinates, distanceMatrix, useDistanceMatrix);
     82        }
     83      }
     84
     85      return length;
     86    }
    2787  }
    2888}
Note: See TracChangeset for help on using the changeset viewer.