Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/24/20 00:58:42 (4 years ago)
Author:
abeham
Message:

#2521: working on VRP (WIP)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/PathRelinkers/VRPPathRelinker.cs

    r17226 r17698  
    7272    }
    7373
    74     public static ItemArray<IItem> Apply(PotvinEncoding initiator, PotvinEncoding guide, PercentValue n, int sampleSize, int iterations, IRandom rand, IVRPProblemInstance problemInstance) {
     74    public static ItemArray<IItem> Apply(PotvinEncodedSolution initiator, PotvinEncodedSolution guide, PercentValue n, int sampleSize, int iterations, IRandom rand, IVRPProblemInstance problemInstance) {
    7575      if (initiator == null || guide == null)
    7676        throw new ArgumentException("Cannot relink path because one of the provided solutions or both are null.");
     
    8787        originalTardinessPenalty.Value = (problemInstance as ITimeWindowedProblemInstance).TardinessPenalty.Value;
    8888
    89       PotvinEncoding current = MatchTours(initiator, guide, problemInstance);
     89      PotvinEncodedSolution current = MatchTours(initiator, guide, problemInstance);
    9090      double currentSimilarity = VRPSimilarityCalculator.CalculateSimilarity(current, guide);
    9191
    92       IList<PotvinEncoding> solutions = new List<PotvinEncoding>();
     92      IList<PotvinEncodedSolution> solutions = new List<PotvinEncodedSolution>();
    9393      int i = 0;
    9494      while (i < iterations && !currentSimilarity.IsAlmost(1.0)) {
     
    9898        if (currentSimilarity < 1.0) {
    9999          for (int sample = 0; sample < sampleSize; sample++) {
    100             var next = current.Clone() as PotvinEncoding;
     100            var next = current.Clone() as PotvinEncodedSolution;
    101101
    102102            int neighborhood = rand.Next(3);
     
    159159    }
    160160
    161     private static IList<IItem> ChooseSelection(IList<PotvinEncoding> solutions, PercentValue n) {
     161    private static IList<IItem> ChooseSelection(IList<PotvinEncodedSolution> solutions, PercentValue n) {
    162162      IList<IItem> selection = new List<IItem>();
    163163      if (solutions.Count > 0) {
     
    176176        throw new ArgumentException("The number of parents is not equal to 2.");
    177177
    178       if (!(parents[0] is PotvinEncoding))
    179         parents[0] = PotvinEncoding.ConvertFrom(parents[0] as IVRPEncoding, ProblemInstanceParameter.ActualValue);
    180       if (!(parents[1] is PotvinEncoding))
    181         parents[1] = PotvinEncoding.ConvertFrom(parents[1] as IVRPEncoding, ProblemInstanceParameter.ActualValue);
    182 
    183       return Apply(parents[0] as PotvinEncoding, parents[1] as PotvinEncoding, n,
     178      if (!(parents[0] is PotvinEncodedSolution))
     179        parents[0] = PotvinEncodedSolution.ConvertFrom(parents[0] as IVRPEncodedSolution, ProblemInstanceParameter.ActualValue);
     180      if (!(parents[1] is PotvinEncodedSolution))
     181        parents[1] = PotvinEncodedSolution.ConvertFrom(parents[1] as IVRPEncodedSolution, ProblemInstanceParameter.ActualValue);
     182
     183      return Apply(parents[0] as PotvinEncodedSolution, parents[1] as PotvinEncodedSolution, n,
    184184        SampleSizeParameter.Value.Value, IterationsParameter.Value.Value, RandomParameter.ActualValue, ProblemInstanceParameter.ActualValue);
    185185    }
     
    189189    }
    190190
    191     private static PotvinEncoding MatchTours(PotvinEncoding initiator, PotvinEncoding guide, IVRPProblemInstance problemInstance) {
    192       var result = new PotvinEncoding(problemInstance);
     191    private static PotvinEncodedSolution MatchTours(PotvinEncodedSolution initiator, PotvinEncodedSolution guide, IVRPProblemInstance problemInstance) {
     192      var result = new PotvinEncodedSolution(problemInstance);
    193193
    194194      var used = new List<bool>();
     
    226226
    227227    #region moves
    228     public static PotvinEncoding RouteBasedXOver(PotvinEncoding initiator, PotvinEncoding guide, IRandom random, IVRPProblemInstance problemInstance) {
     228    public static PotvinEncodedSolution RouteBasedXOver(PotvinEncodedSolution initiator, PotvinEncodedSolution guide, IRandom random, IVRPProblemInstance problemInstance) {
    229229      return PotvinRouteBasedCrossover.Apply(random, initiator, guide, problemInstance, false);
    230230    }
    231231
    232     public static PotvinEncoding SequenceBasedXOver(PotvinEncoding initiator, PotvinEncoding guide, IRandom random, IVRPProblemInstance problemInstance) {
     232    public static PotvinEncodedSolution SequenceBasedXOver(PotvinEncodedSolution initiator, PotvinEncodedSolution guide, IRandom random, IVRPProblemInstance problemInstance) {
    233233      return PotvinSequenceBasedCrossover.Apply(random, initiator, guide, problemInstance, false);
    234234    }
    235235
    236     public static void GuidedRelocateMove(PotvinEncoding initiator, PotvinEncoding guide, IRandom random) {
     236    public static void GuidedRelocateMove(PotvinEncodedSolution initiator, PotvinEncodedSolution guide, IRandom random) {
    237237      List<int> cities = new List<int>();
    238238      foreach (Tour tour in initiator.Tours) {
     
    291291    }
    292292
    293     public static void RelocateMove(PotvinEncoding individual, IRandom random) {
     293    public static void RelocateMove(PotvinEncodedSolution individual, IRandom random) {
    294294      int cities = individual.Cities;
    295295      int city = 1 + random.Next(cities);
Note: See TracChangeset for help on using the changeset viewer.