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


C# IVRPProblemInstance.GetInsertionCosts方法代码示例

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


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

示例1: CreateSolution

    public static PotvinEncoding CreateSolution(IVRPProblemInstance problemInstance, IRandom random,
      double alphaValue = 0.7, double betaValue = 0.1, double gammaValue = 0.2,
      double alphaVariance = 0.5, double betaVariance = 0.07, double gammaVariance = 0.14) {
      PotvinEncoding result = new PotvinEncoding(problemInstance);

      IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance;
      IMultiDepotProblemInstance mdp = problemInstance as IMultiDepotProblemInstance;

      double alpha, beta, gamma;
      alpha = N(alphaValue, Math.Sqrt(alphaVariance), random);
      beta = N(betaValue, Math.Sqrt(betaVariance), random);
      gamma = N(gammaValue, Math.Sqrt(gammaVariance), random);

      List<int> unroutedCustomers = new List<int>();
      for (int i = 1; i <= problemInstance.Cities.Value; i++) {
        if (pdp == null || (problemInstance.GetDemand(i) >= 0))
          unroutedCustomers.Add(i);
      }

      List<int> depots = new List<int>();
      if (mdp != null) {
        for (int i = 0; i < mdp.Depots.Value; i++) {
          depots.Add(i);
        }
      } else {
        depots.Add(0);
      }

      Dictionary<int, List<int>> vehicles = new Dictionary<int, List<int>>();
      foreach (int depot in depots) {
        vehicles[depot] = new List<int>();

        int vehicleCount = problemInstance.Vehicles.Value;
        if (mdp != null) {
          for (int vehicle = 0; vehicle < mdp.VehicleDepotAssignment.Length; vehicle++) {
            if (mdp.VehicleDepotAssignment[vehicle] == depot) {
              vehicles[depot].Add(vehicle);
            }
          }
        } else {
          for (int vehicle = 0; vehicle < vehicleCount; vehicle++) {
            vehicles[depot].Add(vehicle);
          }
        }
      }

      RemoveUnusedDepots(depots, vehicles);
      Dictionary<int, int> depotAssignment = new Dictionary<int, int>();

      unroutedCustomers = SortCustomers(
        problemInstance, unroutedCustomers, depots, depotAssignment,
        alpha, beta, gamma);

      /////////
      Tour tour = new Tour();
      result.Tours.Add(tour);
      int currentCustomer = unroutedCustomers[0];
      unroutedCustomers.RemoveAt(0);

      int currentDepot = depotAssignment[currentCustomer];
      int currentVehicle = vehicles[currentDepot][0];
      vehicles[currentDepot].RemoveAt(0);
      if (RemoveUnusedDepots(depots, vehicles)) {
        unroutedCustomers = SortCustomers(
        problemInstance, unroutedCustomers, depots, depotAssignment,
        alpha, beta, gamma);
      }

      result.VehicleAssignment[result.Tours.Count - 1] = currentVehicle;

      tour.Stops.Add(currentCustomer);
      if (pdp != null) {
        tour.Stops.Add(pdp.GetPickupDeliveryLocation(currentCustomer));
      }
      ////////

      while (unroutedCustomers.Count > 0) {
        double minimumCost = double.MaxValue;
        int customer = -1;
        int indexOfMinimumCost = -1;
        int indexOfMinimumCost2 = -1;

        foreach (int unrouted in unroutedCustomers) {
          VRPEvaluation eval = problemInstance.EvaluateTour(tour, result);
          double originalCosts = eval.Quality;

          for (int i = 0; i <= tour.Stops.Count; i++) {
            tour.Stops.Insert(i, unrouted);
            eval = problemInstance.EvaluateTour(tour, result);
            double tourCost = eval.Quality - originalCosts;

            if (pdp != null) {
              for (int j = i + 1; j <= tour.Stops.Count; j++) {
                bool feasible;
                double cost = tourCost +
                  problemInstance.GetInsertionCosts(eval, result, pdp.GetPickupDeliveryLocation(unrouted), 0, j, out feasible);
                if (cost < minimumCost && feasible) {
                  customer = unrouted;
                  minimumCost = cost;
                  indexOfMinimumCost = i;
//.........这里部分代码省略.........
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:101,代码来源:PushForwardInsertionCreator.cs

示例2: InsertPair

    public void InsertPair(Tour tour, int source, int target, IVRPProblemInstance problemInstance, int positionToAvoid = -1, int positionToAvoid2 = -1) {
      int stops = tour.Stops.Count;
      VRPEvaluation eval = problemInstance.EvaluateTour(tour, this);
      double minCosts = double.MaxValue;
      int sourceLocation = -1;
      int targetLocation = -1;

      for (int i = 0; i <= stops; i++) {
        tour.Stops.Insert(i, source);
        VRPEvaluation tourEval = problemInstance.EvaluateTour(tour, this);
        double sourceCosts = tourEval.Quality - eval.Quality;

        for (int j = i + 1; j <= stops + 1; j++) {
          if (positionToAvoid != i || positionToAvoid2 != j || stops == 0) {
            bool feasible;
            double targetCosts = problemInstance.GetInsertionCosts(tourEval, this, target, 0, j, out feasible);

            double costs = sourceCosts + targetCosts;
            if (costs < minCosts) {
              minCosts = costs;
              sourceLocation = i;
              targetLocation = j;
            }
          }
        }
        tour.Stops.Remove(source);
      }

      tour.Stops.Insert(sourceLocation, source);
      tour.Stops.Insert(targetLocation, target);
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:31,代码来源:PotvinEncoding.cs


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