• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IVRPProblemInstance类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: GenerateMoves

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

      PotvinPDShiftMove move = Apply(individual, ProblemInstance, RandomParameter.ActualValue);
      if (move != null)
        result.Add(move);

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


示例17: 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 originalQuality = eval.Quality;

      IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance;
      DoubleArray demand = instance.Demand;

      double delivered = 0.0;
      double overweight = 0.0;
      double distance = 0.0;

      double capacity = cvrpInstance.Capacity.Value;
      for (int i = 0; i <= tour.Stops.Count; i++) {
        int end = 0;
        if (i < tour.Stops.Count)
          end = tour.Stops[i];

        delivered += demand[end];
      }

      double spareCapacity = capacity - delivered;

      //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;

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

      eval.Quality += instance.FleetUsageFactor.Value;
      eval.Quality += instance.DistanceFactor.Value * distance;

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

      if (delivered > capacity) {
        overweight = delivered - capacity;
      }

      (eval as CVRPEvaluation).Overload += overweight;
      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
      eval.Penalty += penalty;
      eval.Quality += penalty;
      tourInfo.Penalty = penalty;
      tourInfo.Quality = eval.Quality - originalQuality;
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:57,代码来源:CVRPEvaluator.cs


示例18: GenerateMoves

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

      for (int i = 0; i < SampleSizeParameter.ActualValue.Value; i++) {
        var move = PotvinVehicleAssignmentSingleMoveGenerator.Apply(individual, ProblemInstance, RandomParameter.ActualValue);
        if (move != null)
          result.Add(move);
      }

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


示例19: GenerateMoves

    protected override AlbaIntraRouteInversionMove[] GenerateMoves(AlbaEncoding individual, IVRPProblemInstance problemInstance) {
      int sampleSize = SampleSizeParameter.ActualValue.Value;

      AlbaIntraRouteInversionMove[] moves = new AlbaIntraRouteInversionMove[sampleSize];
      for (int i = 0; i < sampleSize; i++) {
        moves[i] = AlbaStochasticIntraRouteInversionSingleMoveGenerator.Apply(
          individual, problemInstance.Cities.Value, RandomParameter.ActualValue);
      }

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


示例20: GetTourInsertionCosts

    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
      out bool feasible) {
      StopInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index);

      double costs = 0;
      feasible = true;
      double startDistance, endDistance;

      costs += instance.GetInsertionDistance(insertionInfo.Start, customer, insertionInfo.End, solution, out startDistance, out endDistance);

      return costs;
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:12,代码来源:MultiDepotVRPEvaluator.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IValidationErrors类代码示例发布时间:2022-05-24
下一篇:
C# IUuidGenerator类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap