Example #1
0
        public VRPEvaluation EvaluateTour(IVRPProblemInstance instance, Tour tour, IVRPEncoding solution)
        {
            VRPEvaluation evaluation = CreateTourEvaluation();

            EvaluateTour(evaluation, instance, tour, solution);
            return(evaluation);
        }
Example #2
0
 protected virtual void SetResultParameters(VRPEvaluation tourEvaluation)
 {
     QualityParameter.ActualValue.Value          = tourEvaluation.Quality;
     VehcilesUtilizedParameter.ActualValue.Value = tourEvaluation.VehicleUtilization;
     DistanceParameter.ActualValue.Value         = tourEvaluation.Distance;
     PenaltyParameter.ActualValue.Value          = tourEvaluation.Penalty;
 }
    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;
    }
        protected override void SetResultParameters(VRPEvaluation tourEvaluation)
        {
            base.SetResultParameters(tourEvaluation);

            TardinessParameter.ActualValue.Value  = (tourEvaluation as CVRPTWEvaluation).Tardiness;
            TravelTimeParameter.ActualValue.Value = (tourEvaluation as CVRPTWEvaluation).TravelTime;
        }
Example #5
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;
    }
Example #6
0
        public virtual VRPEvaluation Evaluate(IVRPProblemInstance instance, IVRPEncoding solution)
        {
            VRPEvaluation evaluation = CreateTourEvaluation();

            foreach (Tour tour in solution.GetTours())
            {
                EvaluateTour(evaluation, instance, tour, solution);
            }

            return(evaluation);
        }
Example #7
0
        public override IOperation InstrumentedApply()
        {
            InitResultParameters();

            VRPEvaluation evaluation = CreateTourEvaluation();
            IVRPEncoding  solution   = VRPToursParameter.ActualValue;

            foreach (Tour tour in solution.GetTours())
            {
                EvaluateTour(evaluation, ProblemInstance, tour, solution);
            }
            SetResultParameters(evaluation);

            QualityParameter.ActualValue = new DoubleValue(evaluation.Quality);

            return(base.InstrumentedApply());
        }
Example #8
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 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;

            eval.Quality    += quality;
            tourInfo.Quality = quality;
        }
Example #9
0
 protected abstract void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution);
        protected override void SetResultParameters(VRPEvaluation tourEvaluation)
        {
            base.SetResultParameters(tourEvaluation);

            PickupViolationsParameter.ActualValue.Value = (tourEvaluation as CVRPPDTWEvaluation).PickupViolations;
        }
Example #11
0
 protected virtual void SetResultParameters(VRPEvaluation tourEvaluation) {
   QualityParameter.ActualValue.Value = tourEvaluation.Quality;
   VehcilesUtilizedParameter.ActualValue.Value = tourEvaluation.VehicleUtilization;
   DistanceParameter.ActualValue.Value = tourEvaluation.Distance;
   PenaltyParameter.ActualValue.Value = tourEvaluation.Penalty;
 }
Example #12
0
 protected abstract void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution);
Example #13
0
    public double GetInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, VRPEvaluation eval, int customer, int tour, int index, out bool feasible) {
      bool tourFeasible;
      double costs = GetTourInsertionCosts(
        instance,
        solution,
        eval.InsertionInfo.GetTourInsertionInfo(tour),
        index,
        customer, out tourFeasible);

      feasible = tourFeasible;

      return costs;
    }
Example #14
0
 public bool Feasible(VRPEvaluation evaluation) {
   return evaluation.Penalty < double.Epsilon;
 }
Example #15
0
 public bool Feasible(VRPEvaluation evaluation)
 {
     return(evaluation.Penalty < double.Epsilon);
 }
Example #16
0
        public double GetInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, VRPEvaluation eval, int customer, int tour, int index, out bool feasible)
        {
            bool   tourFeasible;
            double costs = GetTourInsertionCosts(
                instance,
                solution,
                eval.InsertionInfo.GetTourInsertionInfo(tour),
                index,
                customer, out tourFeasible);

            feasible = tourFeasible;

            return(costs);
        }
        protected override void SetResultParameters(VRPEvaluation tourEvaluation)
        {
            base.SetResultParameters(tourEvaluation);

            OverloadParameter.ActualValue.Value = (tourEvaluation as CVRPEvaluation).Overload;
        }
 public double GetInsertionCosts(VRPEvaluation eval, IVRPEncoding solution, int customer, int tour, int index, out bool feasible) {
   return evaluator.GetInsertionCosts(this, solution, eval, customer, tour, index, out feasible);
 }
 public bool Feasible(VRPEvaluation eval)
 {
     return(evaluator.Feasible(eval));
 }
        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;

            ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
            DoubleArray dueTime      = vrptw.DueTime;
            DoubleArray readyTime    = vrptw.ReadyTime;
            DoubleArray serviceTimes = vrptw.ServiceTime;

            IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance;
            IntArray pickupDeliveryLocation       = pdp.PickupDeliveryLocation;

            double capacity = cvrpInstance.Capacity.Value;

            double time        = 0.0;
            double waitingTime = 0.0;
            double serviceTime = 0.0;
            double tardiness   = 0.0;
            double overweight  = 0.0;
            double distance    = 0.0;

            double currentLoad           = 0.0;
            Dictionary <int, bool> stops = new Dictionary <int, bool>();
            int pickupViolations         = 0;

            double tourStartTime = readyTime[0];

            time = tourStartTime;

            //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 = vrptw.GetDistance(start, end, solution);
                time     += currentDistace;
                distance += currentDistace;

                double arrivalTime = time;

                //check if it was serviced on time
                if (time > dueTime[end])
                {
                    tardiness += time - dueTime[end];
                }

                //wait
                double currentWaitingTime = 0.0;
                if (time < readyTime[end])
                {
                    currentWaitingTime = readyTime[end] - time;
                }

                double waitTime = readyTime[end] - time;

                waitingTime += currentWaitingTime;
                time        += currentWaitingTime;

                double spareTime = dueTime[end] - time;

                //service
                double currentServiceTime = serviceTimes[end];
                serviceTime += currentServiceTime;
                time        += currentServiceTime;

                //Pickup / deliver
                double arrivalSpareCapacity = capacity - currentLoad;

                bool validPickupDelivery =
                    validPickupDelivery =
                        ((demand[end] >= 0) ||
                         (stops.ContainsKey(pickupDeliveryLocation[end])));

                if (validPickupDelivery)
                {
                    currentLoad += demand[end];
                }
                else
                {
                    pickupViolations++;
                }

                if (currentLoad > capacity)
                {
                    overweight += currentLoad - capacity;
                }

                double spareCapacity           = capacity - currentLoad;
                CVRPPDTWInsertionInfo stopInfo = new CVRPPDTWInsertionInfo(start, end, spareCapacity, tourStartTime,
                                                                           arrivalTime, time, spareTime, waitTime, new List <int>(stops.Keys), arrivalSpareCapacity);
                tourInfo.AddStopInsertionInfo(stopInfo);

                stops.Add(end, true);
            }

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

            (eval as CVRPEvaluation).Overload += overweight;
            double tourPenalty = 0;
            double penalty     = overweight * cvrpInstance.OverloadPenalty.Value;

            eval.Penalty += penalty;
            eval.Quality += penalty;
            tourPenalty  += penalty;

            (eval as CVRPTWEvaluation).Tardiness  += tardiness;
            (eval as CVRPTWEvaluation).TravelTime += time;

            penalty       = tardiness * vrptw.TardinessPenalty.Value;
            eval.Penalty += penalty;
            eval.Quality += penalty;
            tourPenalty  += penalty;

            (eval as CVRPPDTWEvaluation).PickupViolations += pickupViolations;
            penalty       = pickupViolations * pdp.PickupViolationPenalty.Value;
            eval.Penalty += penalty;
            tourPenalty  += penalty;

            eval.Quality    += penalty;
            eval.Quality    += time * vrptw.TimeFactor.Value;
            tourInfo.Penalty = tourPenalty;
            tourInfo.Quality = eval.Quality - originalQuality;
        }
Example #21
0
    protected override void SetResultParameters(VRPEvaluation tourEvaluation) {
      base.SetResultParameters(tourEvaluation);

      PickupViolationsParameter.ActualValue.Value = (tourEvaluation as CVRPPDTWEvaluation).PickupViolations;
    }
Example #22
0
    protected override void SetResultParameters(VRPEvaluation tourEvaluation) {
      base.SetResultParameters(tourEvaluation);

      OverloadParameter.ActualValue.Value = (tourEvaluation as CVRPEvaluation).Overload;
    }
Example #23
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;
      DoubleArray demand = instance.Demand;

      ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
      DoubleArray dueTime = vrptw.DueTime;
      DoubleArray readyTime = vrptw.ReadyTime;
      DoubleArray serviceTimes = vrptw.ServiceTime;

      IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance;
      IntArray pickupDeliveryLocation = pdp.PickupDeliveryLocation;

      IMultiDepotProblemInstance mdp = instance as IMultiDepotProblemInstance;
      IntArray vehicleAssignment = mdp.VehicleDepotAssignment;
      int depots = mdp.Depots.Value;

      double time = 0.0;
      double waitingTime = 0.0;
      double serviceTime = 0.0;
      double tardiness = 0.0;
      double overweight = 0.0;
      double distance = 0.0;

      int tourIndex = solution.GetTourIndex(tour);
      int vehicle = solution.GetVehicleAssignment(tourIndex);
      int depot = vehicleAssignment[vehicle];

      double capacity = cvrpInstance.Capacity[vehicle];

      double currentLoad = 0.0;
      Dictionary<int, bool> stops = new Dictionary<int, bool>();
      int pickupViolations = 0;

      double tourStartTime = readyTime[0];
      time = tourStartTime;

      //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 = vrptw.GetDistance(start, end, solution);
        time += currentDistace;
        distance += currentDistace;

        double arrivalTime = time;

        int endIndex;
        if (end == 0)
          endIndex = depot;
        else
          endIndex = end + depots - 1;

        //check if it was serviced on time
        if (time > dueTime[endIndex])
          tardiness += time - dueTime[endIndex];

        //wait
        double currentWaitingTime = 0.0;
        if (time < readyTime[endIndex])
          currentWaitingTime = readyTime[endIndex] - time;

        double waitTime = readyTime[endIndex] - time;

        waitingTime += currentWaitingTime;
        time += currentWaitingTime;

        double spareTime = dueTime[endIndex] - time;
        double arrivalSpareCapacity = capacity - currentLoad;

        if (end > 0) {
          //service
          double currentServiceTime = serviceTimes[end - 1];
          serviceTime += currentServiceTime;
          time += currentServiceTime;

          //Pickup / deliver
          bool validPickupDelivery =
            validPickupDelivery =
            ((demand[end - 1] >= 0) ||
             (stops.ContainsKey(pickupDeliveryLocation[end - 1])));

          if (validPickupDelivery) {
            currentLoad += demand[end - 1];
          } else {
            pickupViolations++;
          }

          if (currentLoad > capacity)
            overweight += currentLoad - capacity;
        }

        double spareCapacity = capacity - currentLoad;
        CVRPPDTWInsertionInfo stopInfo = new CVRPPDTWInsertionInfo(start, end, spareCapacity, tourStartTime,
          arrivalTime, time, spareTime, waitTime, new List<int>(stops.Keys), arrivalSpareCapacity);
        tourInfo.AddStopInsertionInfo(stopInfo);

        stops.Add(end, true);
      }

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

      (eval as CVRPEvaluation).Overload += overweight;
      double tourPenalty = 0;
      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
      eval.Penalty += penalty;
      eval.Quality += penalty;
      tourPenalty += penalty;

      (eval as CVRPTWEvaluation).Tardiness += tardiness;
      (eval as CVRPTWEvaluation).TravelTime += time;

      penalty = tardiness * vrptw.TardinessPenalty.Value;
      eval.Penalty += penalty;
      eval.Quality += penalty;
      tourPenalty += penalty;

      (eval as CVRPPDTWEvaluation).PickupViolations += pickupViolations;
      penalty = pickupViolations * pdp.PickupViolationPenalty.Value;
      eval.Penalty += penalty;
      tourPenalty += penalty;

      eval.Quality += penalty;
      eval.Quality += time * vrptw.TimeFactor.Value;
      tourInfo.Penalty = tourPenalty;
      tourInfo.Quality = eval.Quality - originalQuality;
    }
        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;
            DoubleArray demand = instance.Demand;

            ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
            DoubleArray dueTime      = vrptw.DueTime;
            DoubleArray readyTime    = vrptw.ReadyTime;
            DoubleArray serviceTimes = vrptw.ServiceTime;

            IMultiDepotProblemInstance mdp = instance as IMultiDepotProblemInstance;
            IntArray vehicleAssignment     = mdp.VehicleDepotAssignment;
            int      depots = mdp.Depots.Value;

            double time        = 0.0;
            double waitingTime = 0.0;
            double serviceTime = 0.0;
            double tardiness   = 0.0;
            double delivered   = 0.0;
            double overweight  = 0.0;
            double distance    = 0.0;

            int tourIndex = solution.GetTourIndex(tour);
            int vehicle   = solution.GetVehicleAssignment(tourIndex);
            int depot     = vehicleAssignment[vehicle];

            double capacity = cvrpInstance.Capacity[vehicle];

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

            double spareCapacity = capacity - delivered;

            double tourStartTime = vrptw.ReadyTime[depot];

            time = tourStartTime;

            //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 = vrptw.GetDistance(start, end, solution);
                time     += currentDistace;
                distance += currentDistace;

                double arrivalTime = time;

                int endIndex;
                if (end == 0)
                {
                    endIndex = depot;
                }
                else
                {
                    endIndex = end + depots - 1;
                }

                //check if it was serviced on time
                if (time > dueTime[endIndex])
                {
                    tardiness += time - dueTime[endIndex];
                }

                //wait
                double currentWaitingTime = 0.0;
                if (time < readyTime[endIndex])
                {
                    currentWaitingTime = readyTime[endIndex] - time;
                }

                double waitTime = readyTime[endIndex] - time;

                waitingTime += currentWaitingTime;
                time        += currentWaitingTime;

                double spareTime = dueTime[endIndex] - time;

                //service
                double currentServiceTime = 0;
                if (end > 0)
                {
                    currentServiceTime = serviceTimes[end - 1];
                }
                serviceTime += currentServiceTime;
                time        += currentServiceTime;

                CVRPTWInsertionInfo stopInfo = new CVRPTWInsertionInfo(start, end, spareCapacity, tourStartTime, arrivalTime, time, spareTime, waitTime);
                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 tourPenalty = 0;
            double penalty     = overweight * cvrpInstance.OverloadPenalty.Value;

            eval.Penalty += penalty;
            eval.Quality += penalty;
            tourPenalty  += penalty;

            (eval as CVRPTWEvaluation).Tardiness  += tardiness;
            (eval as CVRPTWEvaluation).TravelTime += time;

            penalty          = tardiness * vrptw.TardinessPenalty.Value;
            eval.Penalty    += penalty;
            eval.Quality    += penalty;
            tourPenalty     += penalty;
            eval.Quality    += time * vrptw.TimeFactor.Value;
            tourInfo.Penalty = tourPenalty;
            tourInfo.Quality = eval.Quality - originalQuality;
        }
Example #25
0
    protected override void SetResultParameters(VRPEvaluation tourEvaluation) {
      base.SetResultParameters(tourEvaluation);

      TardinessParameter.ActualValue.Value = (tourEvaluation as CVRPTWEvaluation).Tardiness;
      TravelTimeParameter.ActualValue.Value = (tourEvaluation as CVRPTWEvaluation).TravelTime;
    }
 public double GetInsertionCosts(VRPEvaluation eval, IVRPEncoding solution, int customer, int tour, int index, out bool feasible)
 {
     return(evaluator.GetInsertionCosts(this, solution, eval, customer, tour, index, out feasible));
 }
Example #27
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;
      DoubleArray demand = instance.Demand;

      ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
      DoubleArray dueTime = vrptw.DueTime;
      DoubleArray readyTime = vrptw.ReadyTime;
      DoubleArray serviceTimes = vrptw.ServiceTime;

      IMultiDepotProblemInstance mdp = instance as IMultiDepotProblemInstance;
      IntArray vehicleAssignment = mdp.VehicleDepotAssignment;
      int depots = mdp.Depots.Value;

      double time = 0.0;
      double waitingTime = 0.0;
      double serviceTime = 0.0;
      double tardiness = 0.0;
      double delivered = 0.0;
      double overweight = 0.0;
      double distance = 0.0;

      int tourIndex = solution.GetTourIndex(tour);
      int vehicle = solution.GetVehicleAssignment(tourIndex);
      int depot = vehicleAssignment[vehicle];

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

      double spareCapacity = capacity - delivered;

      double tourStartTime = vrptw.ReadyTime[depot];
      time = tourStartTime;

      //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 = vrptw.GetDistance(start, end, solution);
        time += currentDistace;
        distance += currentDistace;

        double arrivalTime = time;

        int endIndex;
        if (end == 0)
          endIndex = depot;
        else
          endIndex = end + depots - 1;

        //check if it was serviced on time
        if (time > dueTime[endIndex])
          tardiness += time - dueTime[endIndex];

        //wait
        double currentWaitingTime = 0.0;
        if (time < readyTime[endIndex])
          currentWaitingTime = readyTime[endIndex] - time;

        double waitTime = readyTime[endIndex] - time;

        waitingTime += currentWaitingTime;
        time += currentWaitingTime;

        double spareTime = dueTime[endIndex] - time;

        //service
        double currentServiceTime = 0;
        if (end > 0)
          currentServiceTime = serviceTimes[end - 1];
        serviceTime += currentServiceTime;
        time += currentServiceTime;

        CVRPTWInsertionInfo stopInfo = new CVRPTWInsertionInfo(start, end, spareCapacity, tourStartTime, arrivalTime, time, spareTime, waitTime);
        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 tourPenalty = 0;
      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
      eval.Penalty += penalty;
      eval.Quality += penalty;
      tourPenalty += penalty;

      (eval as CVRPTWEvaluation).Tardiness += tardiness;
      (eval as CVRPTWEvaluation).TravelTime += time;

      penalty = tardiness * vrptw.TardinessPenalty.Value;
      eval.Penalty += penalty;
      eval.Quality += penalty;
      tourPenalty += penalty;
      eval.Quality += time * vrptw.TimeFactor.Value;
      tourInfo.Penalty = tourPenalty;
      tourInfo.Quality = eval.Quality - originalQuality;
    }
        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;
        }
 public bool Feasible(VRPEvaluation eval) {
   return evaluator.Feasible(eval);
 }