Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/16/10 15:20:29 (14 years ago)
Author:
svonolfe
Message:

Added GVR encoding (#1039)

Location:
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3
Files:
11 added
11 edited

Legend:

Unmodified
Added
Removed
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/AlbaEncoding.cs

    r4204 r4230  
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2727using System.Collections.Generic;
     28using HeuristicLab.Problems.VehicleRouting.Encodings.General;
    2829
    2930namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
     
    3536   
    3637    #region IVRPEncoding Members
    37     public ItemList<Tour> Tours {
    38       get {
    39         ItemList<Tour> result = new ItemList<Tour>();
    40        
    41         Tour tour = new Tour();
    42         for (int i = 0; i < this.array.Length; i++) {
    43           if (this.array[i] >= cities) {
    44             if (tour.Cities.Count > 0) {
    45               result.Add(tour);
     38    public List<Tour> GetTours() {
     39      List<Tour> result = new List<Tour>();
    4640
    47               tour = new Tour();
    48             }
    49           } else {
    50             tour.Cities.Add(this.array[i] + 1);
     41      Tour tour = new Tour();
     42      for (int i = 0; i < this.array.Length; i++) {
     43        if (this.array[i] >= cities) {
     44          if (tour.Cities.Count > 0) {
     45            result.Add(tour);
     46
     47            tour = new Tour();
    5148          }
     49        } else {
     50          tour.Cities.Add(this.array[i] + 1);
    5251        }
     52      }
    5353
    54         if (tour.Cities.Count > 0) {
    55           result.Add(tour);
    56         }
     54      if (tour.Cities.Count > 0) {
     55        result.Add(tour);
     56      }
    5757
    58         return result;
    59       }
     58      return result;
    6059    }
    6160
     
    9392
    9493    public static AlbaEncoding ConvertFrom(IVRPEncoding encoding, int vehicles) {
    95       ItemList<Tour> tours = encoding.Tours;
     94      List<Tour> tours = encoding.GetTours();
    9695
    9796      int cities = 0;
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Manipulators/IntraRouteInversionManipulator.cs

    r4206 r4230  
    5656
    5757      List<Tour> validTours = new List<Tour>();
    58       foreach (Tour tour in individual.Tours) {
     58      foreach (Tour tour in individual.GetTours()) {
    5959        if (tour.Cities.Count >= 4)
    6060          validTours.Add(tour);
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Manipulators/LambdaInterchangeManipulator.cs

    r4206 r4230  
    2626using HeuristicLab.Data;
    2727using System;
     28using System.Collections.Generic;
    2829
    2930namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
     
    4546    public static void Apply(AlbaEncoding individual, int tour1Index, int position1, int length1,
    4647      int tour2Index, int position2, int length2) {
    47       Tour tour1 = individual.Tours[tour1Index];
     48      List<Tour> tours = individual.GetTours();
     49
     50      Tour tour1 = tours[tour1Index];
    4851      int tour1Start = -1;
    4952      for (int i = 0; i < individual.Length; i++) {
     
    5457      }
    5558
    56       Tour tour2 = individual.Tours[tour2Index];
     59      Tour tour2 = tours[tour2Index];
    5760      int tour2Start = -1;
    5861      for (int i = 0; i < individual.Length; i++) {
     
    9699
    97100    protected override void Manipulate(IRandom rand, AlbaEncoding individual) {
     101      List<Tour> tours = individual.GetTours();
    98102      int lambda = LambdaParameter.Value.Value;
    99      
    100       int route1Index = rand.Next(individual.Tours.Count);
    101       Tour route1 = individual.Tours[route1Index];
    102103
    103       int route2Index = rand.Next(individual.Tours.Count - 1);
     104      int route1Index = rand.Next(tours.Count);
     105      Tour route1 = tours[route1Index];
     106
     107      int route2Index = rand.Next(tours.Count - 1);
    104108      if (route2Index >= route1Index)
    105109        route2Index += 1;
    106       Tour route2 = individual.Tours[route2Index];
     110      Tour route2 = tours[route2Index];
    107111
    108112      int length1 = rand.Next(Math.Min(lambda + 1, route1.Cities.Count + 1));
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/IntraRouteInversion/StochasticIntraRouteInversionSingleMoveGenerator.cs

    r4206 r4230  
    5959
    6060      List<Tour> validTours = new List<Tour>();
    61       foreach (Tour tour in individual.Tours) {
     61      foreach (Tour tour in individual.GetTours()) {
    6262        if (tour.Cities.Count >= 4)
    6363          validTours.Add(tour);
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/LambdaInterchange/ExhaustiveLambdaInterchangeMoveGenerator.cs

    r4206 r4230  
    4242      List<LambdaInterchangeMove> moves = new List<LambdaInterchangeMove>();
    4343
    44       for (int tour1Index = 0; tour1Index < individual.Tours.Count; tour1Index++) {
    45         Tour tour1 = individual.Tours[tour1Index];
    46         for (int tour2Index = tour1Index + 1; tour2Index < individual.Tours.Count; tour2Index++) {
    47           Tour tour2 = individual.Tours[tour2Index];
     44      List<Tour> tours = individual.GetTours();
     45
     46      for (int tour1Index = 0; tour1Index < tours.Count; tour1Index++) {
     47        Tour tour1 = tours[tour1Index];
     48        for (int tour2Index = tour1Index + 1; tour2Index < tours.Count; tour2Index++) {
     49          Tour tour2 = tours[tour2Index];
    4850
    4951          for (int length1 = 0; length1 <= Math.Min(lambda, tour1.Cities.Count); length1++) {
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/LambdaInterchange/StochasticLambdaInterchangeSingleMoveGenerator.cs

    r4206 r4230  
    5555
    5656    public static LambdaInterchangeMove Apply(AlbaEncoding individual, int cities, int lambda, IRandom rand) {
    57       int route1Index = rand.Next(individual.Tours.Count);
    58       Tour route1 = individual.Tours[route1Index];
     57      List<Tour> tours = individual.GetTours();
    5958
    60       int route2Index = rand.Next(individual.Tours.Count - 1);
     59      int route1Index = rand.Next(tours.Count);
     60      Tour route1 = tours[route1Index];
     61
     62      int route2Index = rand.Next(tours.Count - 1);
    6163      if (route2Index >= route1Index)
    6264        route2Index += 1;
    63       Tour route2 = individual.Tours[route2Index];
     65      Tour route2 = tours[route2Index];
    6466
    6567      int length1 = rand.Next(Math.Min(lambda + 1, route1.Cities.Count + 1));
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/PotvinEncoding.cs

    r4177 r4230  
    2727using System.Drawing;
    2828using System.Collections.Generic;
     29using HeuristicLab.Problems.VehicleRouting.Encodings.General;
    2930
    3031namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
    3132  [Item("PotvinEncoding", "Represents a potvin encoding of VRP solutions. It is implemented as described in Potvin, J.-Y. and Bengio, S. (1996). The Vehicle Routing Problem with Time Windows - Part II: Genetic Search. INFORMS Journal of Computing, 8:165–172.")]
    3233  [StorableClass]
    33   public class PotvinEncoding : Item, IVRPEncoding {
    34     public override Image ItemImage {
    35       get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Class; }
    36     }
    37    
    38     #region IVRPEncoding Members
    39     [Storable]
    40     public ItemList<Tour> Tours { get; set; }
    41 
    42     public int Cities {
    43       get
    44       {
    45         int cities = 0;
    46 
    47         foreach (Tour tour in Tours) {
    48           cities += tour.Cities.Count;
    49         }
    50 
    51         return cities;
    52       }
    53     }
    54     #endregion
    55 
     34  public class PotvinEncoding : TourEncoding {   
    5635    [Storable]
    5736    public List<int> Unrouted { get; set; }
     
    6544    }
    6645
    67     public PotvinEncoding() {
    68       Tours = new ItemList<Tour>();
     46    public PotvinEncoding(): base() {
    6947      Unrouted = new List<int>();
     48    }
     49
     50    [StorableConstructor]
     51    private PotvinEncoding(bool serializing)
     52      : base() {
    7053    }
    7154   
     
    7356      PotvinEncoding solution = new PotvinEncoding();
    7457
    75       solution.Tours.AddRange(
    76         encoding.Tours);
     58      TourEncoding.ConvertFrom(encoding, solution);
    7759
    7860      return solution;
     
    8264      PotvinEncoding solution = new PotvinEncoding();
    8365
    84       Tour tour = new Tour();
    85       for (int i = 0; i < route.Count; i++) {
    86         if (route[i] == 0) {
    87           if (tour.Cities.Count > 0) {
    88             solution.Tours.Add(tour);
    89             tour = new Tour();
    90           }
    91         } else {
    92           tour.Cities.Add(route[i]);
    93         }
    94       }
     66      TourEncoding.ConvertFrom(route, solution);
    9567
    9668      return solution;
     
    11587            if (Tours[tour].Feasible(dueTimeArray, serviceTimeArray, readyTimeArray, demandArray,
    11688              capacity, coordinates, distanceMatrix, useDistanceMatrix)) {
    117               double newLength = Tours[tour].GetLength(coordinates, distanceMatrix, useDistanceMatrix);
     89                double newLength = Tours[tour].GetLength(coordinates, distanceMatrix, useDistanceMatrix);
    11890
    11991              double detour = newLength - length;
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Evaluators/VRPEvaluator.cs

    r4179 r4230  
    101101      IVRPEncoding vrpSolution = VRPToursParameter.ActualValue;
    102102
    103       return vrpSolution.Tours.Count;
     103      return vrpSolution.GetTours().Count;
    104104    }
    105105
     
    190190      sumEval.Tardiness = 0;
    191191
    192       foreach (Tour tour in solution.Tours) {
     192      foreach (Tour tour in solution.GetTours()) {
    193193        TourEvaluation eval = EvaluateTour(tour, dueTimeArray, serviceTimeArray, readyTimeArray, demandArray, capacity,
    194194          fleetUsageFactor, timeFactor, distanceFactor, overloadPenalty, tardinessPenalty,
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/HeuristicLab.Problems.VehicleRouting-3.3.csproj

    r4210 r4230  
    140140    <Compile Include="Encodings\General\Moves\MultiVRPMoveOperator\MultiVRPMoveMaker.cs" />
    141141    <Compile Include="Encodings\General\Moves\MultiVRPMoveOperator\MultiVRPMoveGenerator.cs" />
     142    <Compile Include="Encodings\General\TourEncoding.cs" />
     143    <Compile Include="Encodings\GVR\Crossovers\GVRCrossover.cs" />
     144    <Compile Include="Encodings\GVR\GVREncoding.cs" />
     145    <Compile Include="Encodings\GVR\Manipulators\GVRDisplacementManipulator.cs" />
     146    <Compile Include="Encodings\GVR\Manipulators\GVRInsertionManipulator.cs" />
     147    <Compile Include="Encodings\GVR\Manipulators\GVRInversionManipulator.cs" />
     148    <Compile Include="Encodings\GVR\Manipulators\GVRSwapManipulator.cs" />
     149    <Compile Include="Encodings\GVR\Manipulators\GVRManipulator.cs" />
    142150    <Compile Include="Encodings\Potvin\Crossovers\RouteBasedCrossover.cs" />
    143151    <Compile Include="Encodings\Potvin\Crossovers\SequenceBasedCrossover.cs" />
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Interfaces/IVRPEncoding.cs

    r4154 r4230  
    2222using HeuristicLab.Core;
    2323using HeuristicLab.Problems.VehicleRouting.Encodings;
     24using System.Collections.Generic;
    2425
    2526namespace HeuristicLab.Problems.VehicleRouting {
    2627  public interface IVRPEncoding : IItem {
    27     ItemList<Tour> Tours {
    28       get;
    29     }
     28    List<Tour> GetTours();
    3029  }
    3130}
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/VRPOperator.cs

    r4186 r4230  
    140140      bool feasible = true;
    141141
    142       foreach (Tour tour in solution.Tours) {
     142      foreach (Tour tour in solution.GetTours()) {
    143143        if (!Feasible(tour)) {
    144144          feasible = false;
Note: See TracChangeset for help on using the changeset viewer.