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/Encodings/Alba
Files:
6 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));
Note: See TracChangeset for help on using the changeset viewer.