Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/03/20 18:06:16 (4 years ago)
Author:
abeham
Message:

#2521: working on VRP

Location:
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP
Files:
4 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPProblemInstance.cs

    r17226 r17711  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Data;
    28 using HeuristicLab.Optimization;
    2929using HeuristicLab.Parameters;
    30 using HEAL.Attic;
    31 using HeuristicLab.PluginInfrastructure;
    3230using HeuristicLab.Problems.VehicleRouting.Interfaces;
    3331using HeuristicLab.Problems.VehicleRouting.Variants;
     
    6765    }
    6866
    69     protected override IEnumerable<IOperator> GetOperators() {
    70       return base.GetOperators()
    71         .Where(o => o is IHeterogenousCapacitatedOperator).Cast<IOperator>();
    72     }
    73 
    74     protected override IEnumerable<IOperator> GetAnalyzers() {
    75       return ApplicationManager.Manager.GetInstances<ICapacitatedOperator>()
    76         .Where(o => o is IAnalyzer)
    77         .Cast<IOperator>().Union(base.GetAnalyzers());
    78     }
    79 
    80     protected override IVRPEvaluator Evaluator {
    81       get {
    82         return new MDCVRPEvaluator();
    83       }
     67    public override IEnumerable<IOperator> FilterOperators(IEnumerable<IOperator> operators) {
     68      return base.FilterOperators(operators).Where(x => x is IHeterogenousCapacitatedOperator);
     69    }
     70
     71    protected override VRPEvaluation CreateTourEvaluation() {
     72      return new CVRPEvaluation();
     73    }
     74
     75    protected override void EvaluateTour(VRPEvaluation eval, Tour tour, IVRPEncodedSolution solution) {
     76      TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));
     77      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
     78      double originalQuality = eval.Quality;
     79
     80      double delivered = 0.0;
     81      double overweight = 0.0;
     82      double distance = 0.0;
     83
     84      int tourIndex = solution.GetTourIndex(tour);
     85      int vehicle = solution.GetVehicleAssignment(tourIndex);
     86
     87      double capacity = Capacity[vehicle];
     88      for (int i = 0; i < tour.Stops.Count; i++) {
     89        delivered += GetDemand(tour.Stops[i]);
     90      }
     91
     92      double spareCapacity = capacity - delivered;
     93
     94      //simulate a tour, start and end at depot
     95      for (int i = 0; i <= tour.Stops.Count; i++) {
     96        int start = 0;
     97        if (i > 0)
     98          start = tour.Stops[i - 1];
     99        int end = 0;
     100        if (i < tour.Stops.Count)
     101          end = tour.Stops[i];
     102
     103        //drive there
     104        double currentDistace = GetDistance(start, end, solution);
     105        distance += currentDistace;
     106
     107        CVRPInsertionInfo stopInfo = new CVRPInsertionInfo(start, end, spareCapacity);
     108        tourInfo.AddStopInsertionInfo(stopInfo);
     109      }
     110
     111      eval.Quality += FleetUsageFactor.Value;
     112      eval.Quality += DistanceFactor.Value * distance;
     113
     114      eval.Distance += distance;
     115      eval.VehicleUtilization += 1;
     116
     117      if (delivered > capacity) {
     118        overweight = delivered - capacity;
     119      }
     120
     121      (eval as CVRPEvaluation).Overload += overweight;
     122      double penalty = overweight * OverloadPenalty.Value;
     123      eval.Penalty += penalty;
     124      eval.Quality += penalty;
     125      tourInfo.Penalty = penalty;
     126      tourInfo.Quality = eval.Quality - originalQuality;
     127    }
     128
     129    protected override double GetTourInsertionCosts(IVRPEncodedSolution solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
     130      out bool feasible) {
     131      CVRPInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPInsertionInfo;
     132
     133      double costs = 0;
     134      feasible = tourInsertionInfo.Penalty < double.Epsilon;
     135
     136      double overloadPenalty = OverloadPenalty.Value;
     137
     138      double startDistance, endDistance;
     139      costs += GetInsertionDistance(insertionInfo.Start, customer, insertionInfo.End, solution, out startDistance, out endDistance);
     140
     141      double demand = GetDemand(customer);
     142      if (demand > insertionInfo.SpareCapacity) {
     143        feasible = false;
     144
     145        if (insertionInfo.SpareCapacity >= 0)
     146          costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty;
     147        else
     148          costs += demand * overloadPenalty;
     149      }
     150
     151      return costs;
    84152    }
    85153
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPTW/MDCVRPPDTW/MDCVRPPDTWProblemInstance.cs

    r17226 r17711  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Data;
    28 using HeuristicLab.Optimization;
    2929using HeuristicLab.Parameters;
    30 using HEAL.Attic;
    31 using HeuristicLab.PluginInfrastructure;
    3230using HeuristicLab.Problems.VehicleRouting.Interfaces;
    3331using HeuristicLab.Problems.VehicleRouting.Variants;
     
    6765    }
    6866
    69     protected override IEnumerable<IOperator> GetOperators() {
    70       return
    71         ApplicationManager.Manager.GetInstances<IPickupAndDeliveryOperator>()
    72         .Where(o => !(o is IAnalyzer))
    73         .Cast<IOperator>().Union(base.GetOperators());
    74     }
    75 
    76     protected override IEnumerable<IOperator> GetAnalyzers() {
    77       return ApplicationManager.Manager.GetInstances<IPickupAndDeliveryOperator>()
    78         .Where(o => o is IAnalyzer)
    79         .Cast<IOperator>().Union(base.GetAnalyzers());
    80     }
    81 
    82     protected override IVRPEvaluator Evaluator {
    83       get {
    84         return new MDCVRPPDTWEvaluator();
    85       }
    86     }
    87 
    8867    public int GetPickupDeliveryLocation(int city) {
    8968      return PickupDeliveryLocation[city - 1];
     69    }
     70
     71    public override IEnumerable<IOperator> FilterOperators(IEnumerable<IOperator> operators) {
     72      return base.FilterOperators(operators).Where(x => x is IPickupAndDeliveryOperator);
     73    }
     74
     75    protected override VRPEvaluation CreateTourEvaluation() {
     76      return new CVRPPDTWEvaluation();
     77    }
     78
     79    protected override void EvaluateTour(VRPEvaluation eval, Tour tour, IVRPEncodedSolution solution) {
     80      TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));
     81      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
     82      double originalQuality = eval.Quality;
     83
     84      int depots = Depots.Value;
     85
     86      double time = 0.0;
     87      double waitingTime = 0.0;
     88      double serviceTime = 0.0;
     89      double tardiness = 0.0;
     90      double overweight = 0.0;
     91      double distance = 0.0;
     92
     93      int tourIndex = solution.GetTourIndex(tour);
     94      int vehicle = solution.GetVehicleAssignment(tourIndex);
     95      int depot = VehicleDepotAssignment[vehicle];
     96
     97      double capacity = Capacity[vehicle];
     98
     99      double currentLoad = 0.0;
     100      Dictionary<int, bool> stops = new Dictionary<int, bool>();
     101      int pickupViolations = 0;
     102
     103      double tourStartTime = ReadyTime[0];
     104      time = tourStartTime;
     105
     106      //simulate a tour, start and end at depot
     107      for (int i = 0; i <= tour.Stops.Count; i++) {
     108        int start = 0;
     109        if (i > 0)
     110          start = tour.Stops[i - 1];
     111        int end = 0;
     112        if (i < tour.Stops.Count)
     113          end = tour.Stops[i];
     114
     115        //drive there
     116        double currentDistace = GetDistance(start, end, solution);
     117        time += currentDistace;
     118        distance += currentDistace;
     119
     120        double arrivalTime = time;
     121
     122        int endIndex;
     123        if (end == 0)
     124          endIndex = depot;
     125        else
     126          endIndex = end + depots - 1;
     127
     128        //check if it was serviced on time
     129        if (time > DueTime[endIndex])
     130          tardiness += time - DueTime[endIndex];
     131
     132        //wait
     133        double currentWaitingTime = 0.0;
     134        if (time < ReadyTime[endIndex])
     135          currentWaitingTime = ReadyTime[endIndex] - time;
     136
     137        double waitTime = ReadyTime[endIndex] - time;
     138
     139        waitingTime += currentWaitingTime;
     140        time += currentWaitingTime;
     141
     142        double spareTime = DueTime[endIndex] - time;
     143        double arrivalSpareCapacity = capacity - currentLoad;
     144
     145        if (end > 0) {
     146          //service
     147          double currentServiceTime = ServiceTime[end - 1];
     148          serviceTime += currentServiceTime;
     149          time += currentServiceTime;
     150
     151          //Pickup / deliver
     152          bool validPickupDelivery =
     153            validPickupDelivery =
     154            ((Demand[end - 1] >= 0) ||
     155             (stops.ContainsKey(PickupDeliveryLocation[end - 1])));
     156
     157          if (validPickupDelivery) {
     158            currentLoad += Demand[end - 1];
     159          } else {
     160            pickupViolations++;
     161          }
     162
     163          if (currentLoad > capacity)
     164            overweight += currentLoad - capacity;
     165        }
     166
     167        double spareCapacity = capacity - currentLoad;
     168        CVRPPDTWInsertionInfo stopInfo = new CVRPPDTWInsertionInfo(start, end, spareCapacity, tourStartTime,
     169          arrivalTime, time, spareTime, waitTime, new List<int>(stops.Keys), arrivalSpareCapacity);
     170        tourInfo.AddStopInsertionInfo(stopInfo);
     171
     172        stops.Add(end, true);
     173      }
     174
     175      eval.Quality += FleetUsageFactor.Value;
     176      eval.Quality += DistanceFactor.Value * distance;
     177      eval.Distance += distance;
     178      eval.VehicleUtilization += 1;
     179
     180      (eval as CVRPEvaluation).Overload += overweight;
     181      double tourPenalty = 0;
     182      double penalty = overweight * OverloadPenalty.Value;
     183      eval.Penalty += penalty;
     184      eval.Quality += penalty;
     185      tourPenalty += penalty;
     186
     187      (eval as CVRPTWEvaluation).Tardiness += tardiness;
     188      (eval as CVRPTWEvaluation).TravelTime += time;
     189
     190      penalty = tardiness * TardinessPenalty.Value;
     191      eval.Penalty += penalty;
     192      eval.Quality += penalty;
     193      tourPenalty += penalty;
     194
     195      (eval as CVRPPDTWEvaluation).PickupViolations += pickupViolations;
     196      penalty = pickupViolations * PickupViolationPenalty.Value;
     197      eval.Penalty += penalty;
     198      tourPenalty += penalty;
     199
     200      eval.Quality += penalty;
     201      eval.Quality += time * TimeFactor.Value;
     202      tourInfo.Penalty = tourPenalty;
     203      tourInfo.Quality = eval.Quality - originalQuality;
     204
     205      eval.IsFeasible = overweight == 0 && tardiness == 0 && pickupViolations == 0;
     206    }
     207
     208    protected override double GetTourInsertionCosts(IVRPEncodedSolution solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
     209      out bool feasible) {
     210      CVRPPDTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPPDTWInsertionInfo;
     211
     212      double costs = 0;
     213      feasible = tourInsertionInfo.Penalty < double.Epsilon;
     214      bool tourFeasible = true;
     215
     216      double overloadPenalty = OverloadPenalty.Value;
     217      double tardinessPenalty = TardinessPenalty.Value;
     218
     219      int depots = Depots.Value;
     220
     221      double pickupPenalty = PickupViolationPenalty.Value;
     222
     223      double startDistance, endDistance;
     224      costs += GetInsertionDistance(insertionInfo.Start, customer, insertionInfo.End, solution, out startDistance, out endDistance);
     225
     226      double demand = GetDemand(customer);
     227      if (demand > insertionInfo.ArrivalSpareCapacity) {
     228        tourFeasible = feasible = false;
     229        if (insertionInfo.ArrivalSpareCapacity >= 0)
     230          costs += (demand - insertionInfo.ArrivalSpareCapacity) * overloadPenalty;
     231        else
     232          costs += demand * overloadPenalty;
     233      }
     234      int destination = PickupDeliveryLocation[customer - 1];
     235
     236      bool validPickup = true;
     237      if (demand < 0 && !insertionInfo.Visited.Contains(destination)) {
     238        tourFeasible = feasible = false;
     239        validPickup = false;
     240        costs += pickupPenalty;
     241      }
     242
     243      double time = 0;
     244      double tardiness = 0;
     245
     246      if (index > 0)
     247        time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime;
     248      else
     249        time = insertionInfo.TourStartTime;
     250
     251      time += startDistance;
     252
     253      int customerIndex = customer + depots - 1;
     254
     255      if (time > DueTime[customerIndex]) {
     256        tardiness += time - DueTime[customerIndex];
     257      }
     258      if (time < ReadyTime[customerIndex])
     259        time += ReadyTime[customerIndex] - time;
     260      time += ServiceTime[customer - 1];
     261      time += endDistance;
     262
     263      double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime;
     264      for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) {
     265        CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo;
     266
     267        if (demand >= 0) {
     268          if (nextStop.End == destination) {
     269            demand = 0;
     270            costs -= pickupPenalty;
     271            if (tourInsertionInfo.Penalty == pickupPenalty && tourFeasible)
     272              feasible = true;
     273          } else if (nextStop.SpareCapacity < 0) {
     274            costs += demand * overloadPenalty;
     275          } else if (nextStop.SpareCapacity < demand) {
     276            tourFeasible = feasible = false;
     277            costs += (demand - nextStop.SpareCapacity) * overloadPenalty;
     278          }
     279        } else if (validPickup) {
     280          if (nextStop.SpareCapacity < 0) {
     281            costs += Math.Max(demand, nextStop.SpareCapacity) * overloadPenalty;
     282          }
     283        }
     284
     285        if (additionalTime < 0) {
     286          //arrive earlier than before
     287          //wait probably
     288          if (nextStop.WaitingTime < 0) {
     289            double wait = nextStop.WaitingTime - additionalTime;
     290            if (wait > 0)
     291              additionalTime += wait;
     292          } else {
     293            additionalTime = 0;
     294          }
     295
     296          //check due date, decrease tardiness
     297          if (nextStop.SpareTime < 0) {
     298            costs += Math.Max(nextStop.SpareTime, additionalTime) * tardinessPenalty;
     299          }
     300        } else {
     301          //arrive later than before, probably don't have to wait
     302          if (nextStop.WaitingTime > 0) {
     303            additionalTime -= Math.Min(additionalTime, nextStop.WaitingTime);
     304          }
     305
     306          //check due date
     307          if (nextStop.SpareTime > 0) {
     308            double spare = nextStop.SpareTime - additionalTime;
     309            if (spare < 0)
     310              tardiness += -spare;
     311          } else {
     312            tardiness += additionalTime;
     313          }
     314        }
     315      }
     316
     317      costs += additionalTime * TimeFactor.Value;
     318
     319      if (tardiness > 0) {
     320        tourFeasible = feasible = false;
     321      }
     322
     323      costs += tardiness * tardinessPenalty;
     324
     325      return costs;
    90326    }
    91327
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPTW/MDCVRPTWProblemInstance.cs

    r17226 r17711  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Data;
    28 using HeuristicLab.Optimization;
    2929using HeuristicLab.Parameters;
    30 using HEAL.Attic;
    31 using HeuristicLab.PluginInfrastructure;
    3230using HeuristicLab.Problems.VehicleRouting.Interfaces;
    3331using HeuristicLab.Problems.VehicleRouting.Variants;
     
    8987    }
    9088
    91     protected override IEnumerable<IOperator> GetOperators() {
    92       return base.GetOperators()
    93         .Where(o => o is ITimeWindowedOperator).Cast<IOperator>();
    94     }
    95 
    96     protected override IEnumerable<IOperator> GetAnalyzers() {
    97       return ApplicationManager.Manager.GetInstances<ITimeWindowedOperator>()
    98         .Where(o => o is IAnalyzer)
    99         .Cast<IOperator>().Union(base.GetAnalyzers());
    100     }
    101 
    102     protected override IVRPEvaluator Evaluator {
    103       get {
    104         return new MDCVRPTWEvaluator();
    105       }
     89    public override IEnumerable<IOperator> FilterOperators(IEnumerable<IOperator> operators) {
     90      return base.FilterOperators(operators).Where(x => x is ITimeWindowedOperator);
     91    }
     92
     93    protected override VRPEvaluation CreateTourEvaluation() {
     94      return new CVRPTWEvaluation();
     95    }
     96
     97    protected override void EvaluateTour(VRPEvaluation eval, Tour tour, IVRPEncodedSolution solution) {
     98      TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));
     99      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
     100      double originalQuality = eval.Quality;
     101
     102      int depots = Depots.Value;
     103
     104      double time = 0.0;
     105      double waitingTime = 0.0;
     106      double serviceTime = 0.0;
     107      double tardiness = 0.0;
     108      double delivered = 0.0;
     109      double overweight = 0.0;
     110      double distance = 0.0;
     111
     112      int tourIndex = solution.GetTourIndex(tour);
     113      int vehicle = solution.GetVehicleAssignment(tourIndex);
     114      int depot = VehicleDepotAssignment[vehicle];
     115
     116      double capacity = Capacity[vehicle];
     117      for (int i = 0; i < tour.Stops.Count; i++) {
     118        delivered += GetDemand(tour.Stops[i]);
     119      }
     120
     121      double spareCapacity = capacity - delivered;
     122
     123      double tourStartTime = ReadyTime[depot];
     124      time = tourStartTime;
     125
     126      //simulate a tour, start and end at depot
     127      for (int i = 0; i <= tour.Stops.Count; i++) {
     128        int start = 0;
     129        if (i > 0)
     130          start = tour.Stops[i - 1];
     131        int end = 0;
     132        if (i < tour.Stops.Count)
     133          end = tour.Stops[i];
     134
     135        //drive there
     136        double currentDistace = GetDistance(start, end, solution);
     137        time += currentDistace;
     138        distance += currentDistace;
     139
     140        double arrivalTime = time;
     141
     142        int endIndex;
     143        if (end == 0)
     144          endIndex = depot;
     145        else
     146          endIndex = end + depots - 1;
     147
     148        //check if it was serviced on time
     149        if (time > DueTime[endIndex])
     150          tardiness += time - DueTime[endIndex];
     151
     152        //wait
     153        double currentWaitingTime = 0.0;
     154        if (time < ReadyTime[endIndex])
     155          currentWaitingTime = ReadyTime[endIndex] - time;
     156
     157        double waitTime = ReadyTime[endIndex] - time;
     158
     159        waitingTime += currentWaitingTime;
     160        time += currentWaitingTime;
     161
     162        double spareTime = DueTime[endIndex] - time;
     163
     164        //service
     165        double currentServiceTime = 0;
     166        if (end > 0)
     167          currentServiceTime = ServiceTime[end - 1];
     168        serviceTime += currentServiceTime;
     169        time += currentServiceTime;
     170
     171        CVRPTWInsertionInfo stopInfo = new CVRPTWInsertionInfo(start, end, spareCapacity, tourStartTime, arrivalTime, time, spareTime, waitTime);
     172        tourInfo.AddStopInsertionInfo(stopInfo);
     173      }
     174
     175      eval.Quality += FleetUsageFactor.Value;
     176      eval.Quality += DistanceFactor.Value * distance;
     177      eval.Distance += distance;
     178      eval.VehicleUtilization += 1;
     179
     180      if (delivered > capacity) {
     181        overweight = delivered - capacity;
     182      }
     183
     184      (eval as CVRPEvaluation).Overload += overweight;
     185      double tourPenalty = 0;
     186      double penalty = overweight * OverloadPenalty.Value;
     187      eval.Penalty += penalty;
     188      eval.Quality += penalty;
     189      tourPenalty += penalty;
     190
     191      (eval as CVRPTWEvaluation).Tardiness += tardiness;
     192      (eval as CVRPTWEvaluation).TravelTime += time;
     193
     194      penalty = tardiness * TardinessPenalty.Value;
     195      eval.Penalty += penalty;
     196      eval.Quality += penalty;
     197      tourPenalty += penalty;
     198      eval.Quality += time * TimeFactor.Value;
     199      tourInfo.Penalty = tourPenalty;
     200      tourInfo.Quality = eval.Quality - originalQuality;
     201
     202      eval.IsFeasible = overweight == 0 && tardiness == 0;
     203    }
     204
     205    protected override double GetTourInsertionCosts(IVRPEncodedSolution solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
     206      out bool feasible) {
     207      CVRPTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo;
     208
     209      double costs = 0;
     210      feasible = tourInsertionInfo.Penalty < double.Epsilon;
     211
     212      double overloadPenalty = OverloadPenalty.Value;
     213      double tardinessPenalty = TardinessPenalty.Value;
     214      int depots = Depots.Value;
     215
     216      double startDistance, endDistance;
     217      costs += GetInsertionDistance(insertionInfo.Start, customer, insertionInfo.End, solution, out startDistance, out endDistance);
     218
     219      double demand = GetDemand(customer);
     220      if (demand > insertionInfo.SpareCapacity) {
     221        feasible = false;
     222
     223        if (insertionInfo.SpareCapacity >= 0)
     224          costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty;
     225        else
     226          costs += demand * overloadPenalty;
     227      }
     228
     229      double time = 0;
     230      double tardiness = 0;
     231
     232      if (index > 0)
     233        time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime;
     234      else
     235        time = insertionInfo.TourStartTime;
     236
     237      time += startDistance;
     238
     239      int customerIndex = customer + depots - 1;
     240
     241      if (time > DueTime[customerIndex]) {
     242        tardiness += time - DueTime[customerIndex];
     243      }
     244      if (time < ReadyTime[customerIndex])
     245        time += ReadyTime[customerIndex] - time;
     246      time += ServiceTime[customer - 1];
     247      time += endDistance;
     248
     249      double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime;
     250      for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) {
     251        CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo;
     252
     253        if (additionalTime < 0) {
     254          //arrive earlier than before
     255          //wait probably
     256          if (nextStop.WaitingTime < 0) {
     257            double wait = nextStop.WaitingTime - additionalTime;
     258            if (wait > 0)
     259              additionalTime += wait;
     260          } else {
     261            additionalTime = 0;
     262          }
     263
     264          //check due date, decrease tardiness
     265          if (nextStop.SpareTime < 0) {
     266            costs += Math.Max(nextStop.SpareTime, additionalTime) * tardinessPenalty;
     267          }
     268        } else {
     269          //arrive later than before, probably don't have to wait
     270          if (nextStop.WaitingTime > 0) {
     271            additionalTime -= Math.Min(additionalTime, nextStop.WaitingTime);
     272          }
     273
     274          //check due date
     275          if (nextStop.SpareTime > 0) {
     276            double spare = nextStop.SpareTime - additionalTime;
     277            if (spare < 0)
     278              tardiness += -spare;
     279          } else {
     280            tardiness += additionalTime;
     281          }
     282        }
     283      }
     284
     285      costs += additionalTime * TimeFactor.Value;
     286
     287      if (tardiness > 0) {
     288        feasible = false;
     289      }
     290
     291      costs += tardiness * tardinessPenalty;
     292
     293      return costs;
    106294    }
    107295
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MultiDepotVRPProblemInstance.cs

    r17698 r17711  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Data;
    28 using HeuristicLab.Optimization;
    2929using HeuristicLab.Parameters;
    30 using HEAL.Attic;
    31 using HeuristicLab.PluginInfrastructure;
    3230using HeuristicLab.Problems.VehicleRouting.Interfaces;
    3331using HeuristicLab.Problems.VehicleRouting.Variants;
     
    6058    }
    6159
    62     protected override IEnumerable<IOperator> GetOperators() {
    63       return ApplicationManager.Manager.GetInstances<IMultiDepotOperator>().Cast<IOperator>();
    64     }
    65 
    66     protected override IEnumerable<IOperator> GetAnalyzers() {
    67       return ApplicationManager.Manager.GetInstances<IMultiDepotOperator>()
    68         .Where(o => o is IAnalyzer)
    69         .Cast<IOperator>();
    70     }
    71 
    72     public override IntValue Cities {
    73       get {
    74         return new IntValue(Demand.Length);
    75       }
    76     }
    77 
    78     protected override IVRPEvaluator Evaluator {
    79       get {
    80         return new MultiDepotVRPEvaluator();
    81       }
    82     }
    83 
    84     protected override IVRPCreator Creator {
    85       get {
    86         return new HeuristicLab.Problems.VehicleRouting.Encodings.Alba.RandomCreator();
    87       }
    88     }
     60    public override IEnumerable<IOperator> FilterOperators(IEnumerable<IOperator> operators) {
     61      return base.FilterOperators(operators).Where(x => x is IMultiDepotOperator);
     62    }
     63
     64    public override IntValue Cities => new IntValue(Demand.Length);
     65
    8966
    9067    public override double GetDemand(int city) {
     
    172149      return newDistance - distance;
    173150    }
     151    protected override void EvaluateTour(VRPEvaluation eval, Tour tour, IVRPEncodedSolution solution) {
     152      TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));
     153      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
     154
     155      double distance = 0.0;
     156      double quality = 0.0;
     157
     158      //simulate a tour, start and end at depot
     159      for (int i = 0; i <= tour.Stops.Count; i++) {
     160        int start = 0;
     161        if (i > 0)
     162          start = tour.Stops[i - 1];
     163        int end = 0;
     164        if (i < tour.Stops.Count)
     165          end = tour.Stops[i];
     166
     167        //drive there
     168        double currentDistace = GetDistance(start, end, solution);
     169        distance += currentDistace;
     170
     171        StopInsertionInfo stopInfo = new StopInsertionInfo(start, end);
     172        tourInfo.AddStopInsertionInfo(stopInfo);
     173      }
     174
     175      //Fleet usage
     176      quality += FleetUsageFactor.Value;
     177      //Distance
     178      quality += DistanceFactor.Value * distance;
     179
     180      eval.Distance += distance;
     181      eval.VehicleUtilization += 1;
     182
     183      eval.Quality += quality;
     184      tourInfo.Quality = quality;
     185    }
     186
     187    protected override double GetTourInsertionCosts(IVRPEncodedSolution solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
     188      out bool feasible) {
     189      StopInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index);
     190
     191      double costs = 0;
     192      feasible = true;
     193      double startDistance, endDistance;
     194
     195      costs += GetInsertionDistance(insertionInfo.Start, customer, insertionInfo.End, solution, out startDistance, out endDistance);
     196
     197      return costs;
     198    }
    174199
    175200    [StorableConstructor]
Note: See TracChangeset for help on using the changeset viewer.