Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/09/10 09:55:31 (14 years ago)
Author:
svonolfe
Message:

Merged relevant changes from the trunk into the branch (cloning,...) (#1177)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/Manipulators/AlbaLambdaInterchangeManipulator.cs

    r4365 r4752  
    2727using System;
    2828using System.Collections.Generic;
     29using HeuristicLab.Common;
    2930
    3031namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
     
    4344        Parameters.Add(new ValueParameter<IntValue>("Lambda", "The lambda value.", new IntValue(1)));
    4445     }
     46
     47    public override IDeepCloneable Clone(Cloner cloner) {
     48      return new AlbaLambdaInterchangeManipulator(this, cloner);
     49    }
     50
     51    private AlbaLambdaInterchangeManipulator(AlbaLambdaInterchangeManipulator original, Cloner cloner)
     52      : base(original, cloner) {
     53    }
    4554
    4655    public static void Apply(AlbaEncoding individual, int tour1Index, int position1, int length1,
     
    100109    protected override void Manipulate(IRandom rand, AlbaEncoding individual) {
    101110      List<Tour> tours = individual.GetTours();
    102       int lambda = LambdaParameter.Value.Value;
     111      if (tours.Count > 1) {
     112        int lambda = LambdaParameter.Value.Value;
    103113
    104       int route1Index = rand.Next(tours.Count);
    105       Tour route1 = tours[route1Index];
     114        int route1Index = rand.Next(tours.Count);
     115        Tour route1 = tours[route1Index];
    106116
    107       int route2Index = rand.Next(tours.Count - 1);
    108       if (route2Index >= route1Index)
    109         route2Index += 1;
    110       Tour route2 = tours[route2Index];
    111117
    112       int length1 = rand.Next(Math.Min(lambda + 1, route1.Stops.Count + 1));
    113       int index1 = rand.Next(route1.Stops.Count - length1 + 1);
     118        int route2Index = rand.Next(tours.Count - 1);
     119        if (route2Index >= route1Index)
     120          route2Index += 1;
     121        Tour route2 = tours[route2Index];
    114122
    115       int l2Min = 0;
    116       if (length1 == 0)
    117         l2Min = 1;
    118       int length2 = rand.Next(l2Min, Math.Min(lambda + 1, route2.Stops.Count + 1));
    119       int index2 = rand.Next(route2.Stops.Count - length2 + 1);
     123        int length1 = rand.Next(Math.Min(lambda + 1, route1.Stops.Count + 1));
     124        int index1 = rand.Next(route1.Stops.Count - length1 + 1);
    120125
    121       Apply(individual, route1Index, index1, length1,
    122         route2Index, index2, length2);
     126        int l2Min = 0;
     127        if (length1 == 0)
     128          l2Min = 1;
     129        int length2 = rand.Next(l2Min, Math.Min(lambda + 1, route2.Stops.Count + 1));
     130        int index2 = rand.Next(route2.Stops.Count - length2 + 1);
     131
     132        Apply(individual, route1Index, index1, length1,
     133          route2Index, index2, length2);
     134      }
    123135    }
    124136  }
Note: See TracChangeset for help on using the changeset viewer.