当前位置: 首页>>代码示例>>C#>>正文


C# IVRPProblemInstance类代码示例

本文整理汇总了C#中IVRPProblemInstance的典型用法代码示例。如果您正苦于以下问题:C# IVRPProblemInstance类的具体用法?C# IVRPProblemInstance怎么用?C# IVRPProblemInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IVRPProblemInstance类属于命名空间,在下文中一共展示了IVRPProblemInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateMoves

    protected override AlbaLambdaInterchangeMove[] GenerateMoves(AlbaEncoding individual, IVRPProblemInstance problemInstance, int lambda) {
      List<AlbaLambdaInterchangeMove> moves = new List<AlbaLambdaInterchangeMove>();

      List<Tour> tours = individual.GetTours();

      for (int tour1Index = 0; tour1Index < tours.Count; tour1Index++) {
        Tour tour1 = tours[tour1Index];
        for (int tour2Index = tour1Index + 1; tour2Index < tours.Count; tour2Index++) {
          Tour tour2 = tours[tour2Index];

          for (int length1 = 0; length1 <= Math.Min(lambda, tour1.Stops.Count); length1++) {
            for (int length2 = 0; length2 <= Math.Min(lambda, tour2.Stops.Count); length2++) {
              if (length1 != 0 || length2 != 0) {
                for (int index1 = 0; index1 < tour1.Stops.Count - length1 + 1; index1++) {
                  for (int index2 = 0; index2 < tour2.Stops.Count - length2 + 1; index2++) {
                    moves.Add(new AlbaLambdaInterchangeMove(tour1Index, index1, length1,
                      tour2Index, index2, length2, individual));
                  }
                }
              }
            }
          }
        }
      }

      return moves.ToArray();
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:27,代码来源:AlbaExhaustiveLambdaInterchangeMoveGenerator.cs

示例2: Apply

    public static void Apply(PotvinEncoding solution, PotvinPDShiftMove move, IVRPProblemInstance problemInstance) {
      bool newTour = false;

      if (move.Tour >= solution.Tours.Count) {
        solution.Tours.Add(new Tour());
        newTour = true;
      }
      Tour tour = solution.Tours[move.Tour];

      Tour oldTour = solution.Tours.Find(t => t.Stops.Contains(move.City));
      oldTour.Stops.Remove(move.City);

      if (problemInstance is IPickupAndDeliveryProblemInstance) {
        IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance;

        int location = pdp.GetPickupDeliveryLocation(move.City);
        Tour oldTour2 = solution.Tours.Find(t => t.Stops.Contains(location));
        oldTour2.Stops.Remove(location);

        solution.InsertPair(tour, move.City, location, problemInstance);
      } else {
        int place = solution.FindBestInsertionPlace(tour, move.City);
        tour.Stops.Insert(place, move.City);
      }

      if (newTour) {
        List<int> vehicles = new List<int>();
        for (int i = move.Tour; i < problemInstance.Vehicles.Value; i++) {
          vehicles.Add(solution.GetVehicleAssignment(i));
        }

        double bestQuality = double.MaxValue;
        int bestVehicle = -1;

        int originalVehicle = solution.GetVehicleAssignment(move.Tour);
        foreach (int vehicle in vehicles) {
          solution.VehicleAssignment[move.Tour] = vehicle;

          double quality = problemInstance.EvaluateTour(tour, solution).Quality;
          if (quality < bestQuality) {
            bestQuality = quality;
            bestVehicle = vehicle;
          }
        }

        solution.VehicleAssignment[move.Tour] = originalVehicle;

        int index = -1;
        for (int i = move.Tour; i < solution.VehicleAssignment.Length; i++) {
          if (solution.VehicleAssignment[i] == bestVehicle) {
            index = i;
            break;
          }
        }
        solution.VehicleAssignment[index] = originalVehicle;
        solution.VehicleAssignment[move.Tour] = bestVehicle;
      }

      solution.Repair();
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:60,代码来源:PotvinPDShiftMoveMaker.cs

示例3: SelectRandomTourBiasedByLength

    protected static int SelectRandomTourBiasedByLength(IRandom random, PotvinEncoding individual, IVRPProblemInstance instance) {
      int tourIndex = -1;

      double sum = 0.0;
      double[] probabilities = new double[individual.Tours.Count];
      for (int i = 0; i < individual.Tours.Count; i++) {
        probabilities[i] = 1.0 / ((double)individual.Tours[i].Stops.Count / (double)instance.Cities.Value);
        sum += probabilities[i];
      }

      for (int i = 0; i < probabilities.Length; i++)
        probabilities[i] = probabilities[i] / sum;

      double rand = random.NextDouble();
      double cumulatedProbabilities = 0.0;
      int index = 0;
      while (tourIndex == -1 && index < probabilities.Length) {
        if (cumulatedProbabilities <= rand && rand <= cumulatedProbabilities + probabilities[index])
          tourIndex = index;

        cumulatedProbabilities += probabilities[index];
        index++;
      }

      return tourIndex;
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:26,代码来源:PotvinManipulator.cs

示例4: GenerateMoves

    protected override PotvinPDShiftMove[] GenerateMoves(PotvinEncoding individual, IVRPProblemInstance problemInstance) {
      List<PotvinPDShiftMove> result = new List<PotvinPDShiftMove>();
      IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance;

      int max = individual.Tours.Count;
      if (individual.Tours.Count >= problemInstance.Vehicles.Value)
        max = max - 1;

      for (int i = 0; i < individual.Tours.Count; i++) {
        for (int j = 0; j < individual.Tours[i].Stops.Count; j++) {
          for (int k = 0; k <= max; k++) {
            if (k != i) {
              int city = individual.Tours[i].Stops[j];
              if (pdp == null || pdp.GetDemand(city) >= 0) {
                PotvinPDShiftMove move = new PotvinPDShiftMove(
                  city, i, k, individual);

                result.Add(move);
              }
            }
          }
        }
      }

      return result.ToArray();
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:26,代码来源:PotvinPDShiftExhaustiveMoveGenerator.cs

示例5: EvaluateTour

    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) {
      TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));
      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);

      double distance = 0.0;
      double quality = 0.0;

      //simulate a tour, start and end at depot
      for (int i = 0; i <= tour.Stops.Count; i++) {
        int start = 0;
        if (i > 0)
          start = tour.Stops[i - 1];
        int end = 0;
        if (i < tour.Stops.Count)
          end = tour.Stops[i];

        //drive there
        double currentDistace = instance.GetDistance(start, end, solution);
        distance += currentDistace;

        StopInsertionInfo stopInfo = new StopInsertionInfo(start, end);
        tourInfo.AddStopInsertionInfo(stopInfo);
      }

      //Fleet usage
      quality += instance.FleetUsageFactor.Value;
      //Distance
      quality += instance.DistanceFactor.Value * distance;

      eval.Distance += distance;
      eval.VehicleUtilization += 1;

      tourInfo.Quality = quality;
      eval.Quality += quality;
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:35,代码来源:SingleDepotVRPEvaluator.cs

示例6: GenerateMoves

    protected override AlbaIntraRouteInversionMove[] GenerateMoves(AlbaEncoding individual, IVRPProblemInstance problemInstance) {
      List<AlbaIntraRouteInversionMove> moves = new List<AlbaIntraRouteInversionMove>();

      int currentTourStart = 0;
      int currentTourEnd = 0;
      while (currentTourEnd != individual.Length) {
        currentTourEnd = currentTourStart;
        while (individual[currentTourEnd] < problemInstance.Cities.Value &&
          currentTourEnd < individual.Length) {
          currentTourEnd++;
        }

        int tourLength = currentTourEnd - currentTourStart;
        if (tourLength >= 4) {
          for (int i = 0; i <= tourLength - 4; i++) {
            for (int j = i + 2; j <= tourLength - 2; j++) {
              AlbaIntraRouteInversionMove move = new AlbaIntraRouteInversionMove(
                currentTourStart + i,
                currentTourStart + j,
                individual);

              moves.Add(move);
            }
          }
        }

        currentTourStart = currentTourEnd;
      }

      return moves.ToArray();
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:31,代码来源:AlbaExhaustiveIntraRouteInversionMoveGenerator.cs

示例7: Apply

    public static void Apply(PotvinEncoding solution, PotvinVehicleAssignmentMove move, IVRPProblemInstance problemInstance) {
      int vehicle1 = solution.VehicleAssignment[move.Tour1];
      int vehicle2 = solution.VehicleAssignment[move.Tour2];

      solution.VehicleAssignment[move.Tour1] = vehicle2;
      solution.VehicleAssignment[move.Tour2] = vehicle1;
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:7,代码来源:PotvinVehicleAssignmentMoveMaker.cs

示例8: Apply

    public static void Apply(PotvinEncoding solution, PotvinPDExchangeMove move, IVRPProblemInstance problemInstance) {
      if (move.Tour >= solution.Tours.Count)
        solution.Tours.Add(new Tour());
      Tour tour = solution.Tours[move.Tour];

      Tour oldTour = solution.Tours.Find(t => t.Stops.Contains(move.City));
      oldTour.Stops.Remove(move.City);

      if (problemInstance is IPickupAndDeliveryProblemInstance) {
        IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance;

        int location = pdp.GetPickupDeliveryLocation(move.City);
        Tour oldTour2 = solution.Tours.Find(t => t.Stops.Contains(location));
        oldTour2.Stops.Remove(location);

        location = pdp.GetPickupDeliveryLocation(move.Replaced);
        oldTour2 = solution.Tours.Find(t => t.Stops.Contains(location));

        oldTour2.Stops.Remove(location);
        tour.Stops.Remove(move.Replaced);

        solution.InsertPair(tour, move.City, pdp.GetPickupDeliveryLocation(move.City), problemInstance);
        solution.InsertPair(oldTour, move.Replaced, pdp.GetPickupDeliveryLocation(move.Replaced), problemInstance);
      } else {
        tour.Stops.Remove(move.Replaced);

        int place = solution.FindBestInsertionPlace(tour, move.City);
        tour.Stops.Insert(place, move.City);

        place = solution.FindBestInsertionPlace(oldTour, move.Replaced);
        oldTour.Stops.Insert(place, move.Replaced);
      }

      solution.Repair();
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:35,代码来源:PotvinPDExchangeMoveMaker.cs

示例9: Apply

    public static PotvinPDShiftMove Apply(PotvinEncoding individual, IVRPProblemInstance problemInstance, IRandom rand) {
      List<int> cities = new List<int>();

      IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance;
      for (int i = 1; i <= individual.Cities; i++) {
        if (pdp == null || pdp.GetDemand(i) >= 0)
          cities.Add(i);
      }

      if (cities.Count >= 1) {
        int city = cities[rand.Next(cities.Count)];
        Tour oldTour = individual.Tours.Find(t => t.Stops.Contains(city));
        int oldTourIndex = individual.Tours.IndexOf(oldTour);

        int max = individual.Tours.Count;
        if (individual.Tours.Count >= problemInstance.Vehicles.Value)
          max = max - 1;

        int newTourIndex = rand.Next(max);
        if (newTourIndex >= oldTourIndex)
          newTourIndex++;

        return new PotvinPDShiftMove(city, oldTourIndex, newTourIndex, individual);
      } else {
        return null;
      }
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:27,代码来源:PotvinPDShiftSingleMoveGenerator.cs

示例10: ApplyManipulation

    public static void ApplyManipulation(IRandom random, PotvinEncoding individual, IVRPProblemInstance instance, bool allowInfeasible) {
      int selectedIndex = SelectRandomTourBiasedByLength(random, individual, instance);
      if (selectedIndex >= 0) {
        Tour route1 =
          individual.Tours[selectedIndex];

        int count = route1.Stops.Count;
        int i = 0;
        while (i < count) {
          int insertedRoute, insertedPlace;

          int city = route1.Stops[i];
          route1.Stops.Remove(city);

          if (FindInsertionPlace(individual, city, selectedIndex, allowInfeasible, out insertedRoute, out insertedPlace)) {
            individual.Tours[insertedRoute].Stops.Insert(insertedPlace, city);
          } else {
            route1.Stops.Insert(i, city);
            i++;
          }

          count = route1.Stops.Count;
        }
      }
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:25,代码来源:PotvinOneLevelExchangeManipulator.cs

示例11: VRPSolution

    public VRPSolution(IVRPProblemInstance problemInstance, IVRPEncoding solution, DoubleValue quality)
      : base() {
      this.problemInstance = problemInstance;
      this.solution = solution;
      this.quality = quality;

      Initialize();
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:8,代码来源:VRPSolution.cs

示例12: PermutationEncoding

    public PermutationEncoding(Permutation permutation, IVRPProblemInstance problemInstance)
      : base(PermutationTypes.RelativeUndirected) {
      this.array = new int[permutation.Length];
      for (int i = 0; i < array.Length; i++)
        this.array[i] = permutation[i];

      this.ProblemInstance = problemInstance;
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:8,代码来源:PermutationEncoding.cs

示例13: CreateSolution

    public static PotvinEncoding CreateSolution(IVRPProblemInstance instance, IRandom random, bool adhereTimeWindows) {
      PotvinEncoding result = new PotvinEncoding(instance);

      IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance;

      List<int> customers = new List<int>();
      for (int i = 1; i <= instance.Cities.Value; i++)
        if (pdp == null || pdp.GetDemand(i) >= 0)
          customers.Add(i);

      customers.Sort((city1, city2) => {
        double angle1 = CalculateAngleToDepot(instance, city1);
        double angle2 = CalculateAngleToDepot(instance, city2);

        return angle1.CompareTo(angle2);
      });

      Tour currentTour = new Tour();
      result.Tours.Add(currentTour);

      int j = random.Next(customers.Count);
      for (int i = 0; i < customers.Count; i++) {
        int index = (i + j) % customers.Count;

        int stopIdx = 0;
        if (currentTour.Stops.Count > 0)
          stopIdx = result.FindBestInsertionPlace(currentTour, customers[index]);
        currentTour.Stops.Insert(stopIdx, customers[index]);

        if (pdp != null) {
          stopIdx = result.FindBestInsertionPlace(currentTour, pdp.GetPickupDeliveryLocation(customers[index]));
          currentTour.Stops.Insert(stopIdx, pdp.GetPickupDeliveryLocation(customers[index]));
        }

        CVRPEvaluation evaluation = instance.EvaluateTour(currentTour, result) as CVRPEvaluation;
        if (result.Tours.Count < instance.Vehicles.Value &&
          ((adhereTimeWindows && !instance.Feasible(evaluation)) || ((!adhereTimeWindows) && evaluation.Overload > double.Epsilon))) {
          currentTour.Stops.Remove(customers[index]);
          if (pdp != null)
            currentTour.Stops.Remove(pdp.GetPickupDeliveryLocation(customers[index]));

          if (currentTour.Stops.Count == 0)
            result.Tours.Remove(currentTour);
          currentTour = new Tour();
          result.Tours.Add(currentTour);

          currentTour.Stops.Add(customers[index]);
          if (pdp != null) {
            currentTour.Stops.Add(pdp.GetPickupDeliveryLocation(customers[index]));
          }
        }
      }

      if (currentTour.Stops.Count == 0)
        result.Tours.Remove(currentTour);

      return result;
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:58,代码来源:IterativeInsertionCreator.cs

示例14: GenerateAllMoves

    public static AlbaLambdaInterchangeMove[] GenerateAllMoves(AlbaEncoding individual, IVRPProblemInstance problemInstance, int lambda, int sampleSize, IRandom rand) {
      AlbaLambdaInterchangeMove[] moves = new AlbaLambdaInterchangeMove[sampleSize];
      for (int i = 0; i < sampleSize; i++) {
        moves[i] = AlbaStochasticLambdaInterchangeSingleMoveGenerator.Apply(
          individual, problemInstance.Cities.Value, lambda, rand);
      }

      return moves;
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:9,代码来源:AlbaStochasticLambdaInterchangeMutliMoveGenerator.cs

示例15: GenerateMoves

    protected override PotvinCustomerRelocationMove[] GenerateMoves(PotvinEncoding individual, IVRPProblemInstance problemInstance) {
      List<PotvinCustomerRelocationMove> result = new List<PotvinCustomerRelocationMove>();

      for (int i = 0; i < SampleSizeParameter.ActualValue.Value; i++) {
        result.Add(PotvinCustomerRelocationSingleMoveGenerator.Apply(individual, ProblemInstance, RandomParameter.ActualValue));
      }

      return result.ToArray();
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:9,代码来源:PotvinCustomerRelocationMultiMoveGenerator.cs


注:本文中的IVRPProblemInstance类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。