Ejemplo n.º 1
0
    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;
    }
Ejemplo n.º 2
0
        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;

            IHeterogenousCapacitatedProblemInstance cvrpInstance = instance as IHeterogenousCapacitatedProblemInstance;

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

            int tourIndex = solution.GetTourIndex(tour);
            int vehicle   = solution.GetVehicleAssignment(tourIndex);

            double capacity = cvrpInstance.Capacity[vehicle];

            for (int i = 0; i < tour.Stops.Count; i++)
            {
                delivered += instance.GetDemand(tour.Stops[i]);
            }

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