Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14677


Ignore:
Timestamp:
02/16/17 15:16:55 (7 years ago)
Author:
abeham
Message:

#2205: added results tab to solution view to analyze vrp solution in more detail

  • reorganized insertion infos and adapted some evaluators and instances
Location:
branches/OptimizationNetworks
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPSolutionView.Designer.cs

    r14185 r14677  
    5151      this.tourGroupBox = new System.Windows.Forms.GroupBox();
    5252      this.valueTextBox = new System.Windows.Forms.TextBox();
     53      this.tabPage3 = new System.Windows.Forms.TabPage();
     54      this.resultsTextBox = new System.Windows.Forms.TextBox();
    5355      this.tabControl1.SuspendLayout();
    5456      this.tabPage1.SuspendLayout();
    5557      this.tabPage2.SuspendLayout();
    5658      this.tourGroupBox.SuspendLayout();
     59      this.tabPage3.SuspendLayout();
    5760      this.SuspendLayout();
    5861      //
    5962      // tabControl1
    6063      //
     64      this.tabControl1.AllowDrop = true;
    6165      this.tabControl1.Controls.Add(this.tabPage1);
    6266      this.tabControl1.Controls.Add(this.tabPage2);
     67      this.tabControl1.Controls.Add(this.tabPage3);
    6368      this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
    6469      this.tabControl1.Location = new System.Drawing.Point(0, 0);
     
    8489      this.problemInstanceView.Content = null;
    8590      this.problemInstanceView.Dock = System.Windows.Forms.DockStyle.Fill;
     91      this.problemInstanceView.Enabled = false;
    8692      this.problemInstanceView.Location = new System.Drawing.Point(3, 3);
    8793      this.problemInstanceView.Name = "problemInstanceView";
     
    8995      this.problemInstanceView.Size = new System.Drawing.Size(454, 383);
    9096      this.problemInstanceView.TabIndex = 0;
     97      this.problemInstanceView.ViewsLabelVisible = true;
    9198      this.problemInstanceView.ViewType = null;
    9299      //
     
    119126      this.valueTextBox.Multiline = true;
    120127      this.valueTextBox.Name = "valueTextBox";
    121       this.valueTextBox.Size = new System.Drawing.Size(403, 507);
     128      this.valueTextBox.ReadOnly = true;
     129      this.valueTextBox.Size = new System.Drawing.Size(448, 364);
    122130      this.valueTextBox.TabIndex = 0;
    123       this.valueTextBox.ReadOnly = true;
     131      //
     132      // tabPage3
     133      //
     134      this.tabPage3.Controls.Add(this.resultsTextBox);
     135      this.tabPage3.Location = new System.Drawing.Point(4, 22);
     136      this.tabPage3.Name = "tabPage3";
     137      this.tabPage3.Padding = new System.Windows.Forms.Padding(3);
     138      this.tabPage3.Size = new System.Drawing.Size(460, 389);
     139      this.tabPage3.TabIndex = 2;
     140      this.tabPage3.Text = "Results";
     141      this.tabPage3.UseVisualStyleBackColor = true;
     142      //
     143      // resultsTextBox
     144      //
     145      this.resultsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     146            | System.Windows.Forms.AnchorStyles.Left)
     147            | System.Windows.Forms.AnchorStyles.Right)));
     148      this.resultsTextBox.Location = new System.Drawing.Point(6, 6);
     149      this.resultsTextBox.Multiline = true;
     150      this.resultsTextBox.Name = "resultsTextBox";
     151      this.resultsTextBox.ReadOnly = true;
     152      this.resultsTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
     153      this.resultsTextBox.Size = new System.Drawing.Size(448, 377);
     154      this.resultsTextBox.TabIndex = 0;
    124155      //
    125156      // VRPSolutionView
    126157      //
    127       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    128158      this.Controls.Add(this.tabControl1);
    129159      this.Name = "VRPSolutionView";
     
    133163      this.tabPage2.ResumeLayout(false);
    134164      this.tourGroupBox.ResumeLayout(false);
     165      this.tourGroupBox.PerformLayout();
     166      this.tabPage3.ResumeLayout(false);
     167      this.tabPage3.PerformLayout();
    135168      this.ResumeLayout(false);
    136169
     
    145178    private System.Windows.Forms.GroupBox tourGroupBox;
    146179    private System.Windows.Forms.TextBox valueTextBox;
     180    private System.Windows.Forms.TabPage tabPage3;
     181    private System.Windows.Forms.TextBox resultsTextBox;
    147182  }
    148183}
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPSolutionView.cs

    r14185 r14677  
    2121
    2222using System;
     23using System.Linq;
    2324using System.Text;
    2425using System.Windows.Forms;
     
    5859
    5960      UpdateTourView();
     61      UpdateResultsView();
    6062    }
    6163
     
    8991
    9092    private void UpdateTourView() {
    91       StringBuilder sb = new StringBuilder();
     93      var sb = new StringBuilder();
    9294
    9395      if (Content != null && Content.Solution != null) {
    94         foreach (Tour tour in Content.Solution.GetTours()) {
    95           foreach (int city in tour.Stops) {
     96        foreach (var tour in Content.Solution.GetTours()) {
     97          foreach (var city in tour.Stops) {
    9698            sb.Append(city);
    9799            sb.Append(" ");
     
    103105      valueTextBox.Text = sb.ToString();
    104106    }
     107   
     108    private void UpdateResultsView() {
     109      var builder = new StringBuilder();
     110      if (Content != null && Content.Solution != null) {
     111        var evaluationInfo = Content.ProblemInstance.Evaluate(Content.Solution);
     112        evaluationInfo.GetReport(builder);
     113      }
     114      resultsTextBox.Text = builder.ToString();
     115    }
    105116  }
    106117}
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPEvaluator.cs

    r14185 r14677  
    4141
    4242    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) {
    43       TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));
    44       eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
    4543      double originalQuality = eval.Quality;
    4644
     
    5553
    5654      double capacity = cvrpInstance.Capacity[vehicle];
    57       for (int i = 0; i < tour.Stops.Count; i++) {
    58         delivered += instance.GetDemand(tour.Stops[i]);
    59       }
    6055
    61       double spareCapacity = capacity - delivered;
     56      var tourInfo = new CVRPTourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)), capacity);
     57      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
    6258
    6359      //simulate a tour, start and end at depot
     
    6763          start = tour.Stops[i - 1];
    6864        int end = 0;
    69         if (i < tour.Stops.Count)
     65        if (i < tour.Stops.Count) {
    7066          end = tour.Stops[i];
     67          delivered += instance.GetDemand(end);
     68        }
     69        //drive there
     70        double currentDistance = instance.GetDistance(start, end, solution);
     71        distance += currentDistance;
    7172
    72         //drive there
    73         double currentDistace = instance.GetDistance(start, end, solution);
    74         distance += currentDistace;
    75 
    76         CVRPInsertionInfo stopInfo = new CVRPInsertionInfo(start, end, spareCapacity);
     73        var stopInfo = new CVRPStopInsertionInfo(start, end, currentDistance, capacity - delivered);
    7774        tourInfo.AddStopInsertionInfo(stopInfo);
    7875      }
     
    8885      }
    8986
    90       (eval as CVRPEvaluation).Overload += overweight;
     87      ((CVRPEvaluation)eval).Overload += overweight;
    9188      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
    9289      eval.Penalty += penalty;
     
    9895    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
    9996      out bool feasible) {
    100       CVRPInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPInsertionInfo;
     97      var insertionInfo = (CVRPStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index);
    10198
    10299      double costs = 0;
    103100      feasible = tourInsertionInfo.Penalty < double.Epsilon;
    104101
    105       IHeterogenousCapacitatedProblemInstance cvrp = instance as IHeterogenousCapacitatedProblemInstance;
     102      var cvrp = (IHeterogenousCapacitatedProblemInstance)instance;
    106103      double overloadPenalty = cvrp.OverloadPenalty.Value;
    107104
     
    131128      base.SetResultParameters(tourEvaluation);
    132129
    133       OverloadParameter.ActualValue.Value = (tourEvaluation as CVRPEvaluation).Overload;
     130      OverloadParameter.ActualValue.Value = ((CVRPEvaluation)tourEvaluation).Overload;
    134131    }
    135132
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPTW/MDCVRPPDTW/MDCVRPPDTWEvaluator.cs

    r14185 r14677  
    4343
    4444    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) {
    45       TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));
    46       eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
    4745      double originalQuality = eval.Quality;
    4846
    49       IHeterogenousCapacitatedProblemInstance cvrpInstance = instance as IHeterogenousCapacitatedProblemInstance;
     47      var cvrpInstance = (IHeterogenousCapacitatedProblemInstance)instance;
    5048      DoubleArray demand = instance.Demand;
    5149
    52       ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
     50      var vrptw = (ITimeWindowedProblemInstance)instance;
    5351      DoubleArray dueTime = vrptw.DueTime;
    5452      DoubleArray readyTime = vrptw.ReadyTime;
    5553      DoubleArray serviceTimes = vrptw.ServiceTime;
    5654
    57       IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance;
     55      var pdp = (IPickupAndDeliveryProblemInstance)instance;
    5856      IntArray pickupDeliveryLocation = pdp.PickupDeliveryLocation;
    5957
    60       IMultiDepotProblemInstance mdp = instance as IMultiDepotProblemInstance;
     58      var mdp = (IMultiDepotProblemInstance)instance;
    6159      IntArray vehicleAssignment = mdp.VehicleDepotAssignment;
    6260      int depots = mdp.Depots.Value;
     
    8179      double tourStartTime = readyTime[0];
    8280      time = tourStartTime;
     81
     82      var tourInfo = new CVRPTWTourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)), capacity, tourStartTime);
     83      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
    8384
    8485      //simulate a tour, start and end at depot
     
    9293
    9394        //drive there
    94         double currentDistace = vrptw.GetDistance(start, end, solution);
    95         time += currentDistace;
    96         distance += currentDistace;
     95        double currentDistance = vrptw.GetDistance(start, end, solution);
     96        time += currentDistance;
     97        distance += currentDistance;
    9798
    9899        double arrivalTime = time;
     
    129130          //Pickup / deliver
    130131          bool validPickupDelivery =
    131             validPickupDelivery =
    132132            ((demand[end - 1] >= 0) ||
    133133             (stops.ContainsKey(pickupDeliveryLocation[end - 1])));
     
    144144
    145145        double spareCapacity = capacity - currentLoad;
    146         CVRPPDTWInsertionInfo stopInfo = new CVRPPDTWInsertionInfo(start, end, spareCapacity, tourStartTime,
     146        var stopInfo = new CVRPPDTWStopInsertionInfo(start, end, currentDistance, spareCapacity,
    147147          arrivalTime, time, spareTime, waitTime, new List<int>(stops.Keys), arrivalSpareCapacity);
    148148        tourInfo.AddStopInsertionInfo(stopInfo);
     
    156156      eval.VehicleUtilization += 1;
    157157
    158       (eval as CVRPEvaluation).Overload += overweight;
     158      ((CVRPEvaluation)eval).Overload += overweight;
    159159      double tourPenalty = 0;
    160160      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
     
    163163      tourPenalty += penalty;
    164164
    165       (eval as CVRPTWEvaluation).Tardiness += tardiness;
     165      ((CVRPTWEvaluation)eval).Tardiness += tardiness;
    166166      (eval as CVRPTWEvaluation).TravelTime += time;
    167167
     
    171171      tourPenalty += penalty;
    172172
    173       (eval as CVRPPDTWEvaluation).PickupViolations += pickupViolations;
     173      ((CVRPPDTWEvaluation)eval).PickupViolations += pickupViolations;
    174174      penalty = pickupViolations * pdp.PickupViolationPenalty.Value;
    175175      eval.Penalty += penalty;
     
    184184    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
    185185      out bool feasible) {
    186       CVRPPDTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPPDTWInsertionInfo;
     186      var tourInfo = (CVRPTWTourInsertionInfo)tourInsertionInfo;
     187      var insertionInfo = (CVRPPDTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index);
    187188
    188189      double costs = 0;
     
    230231
    231232      if (index > 0)
    232         time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime;
     233        time = ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index - 1)).LeaveTime;
    233234      else
    234         time = insertionInfo.TourStartTime;
     235        time = tourInfo.TourStartTime;
    235236
    236237      time += startDistance;
     
    246247      time += endDistance;
    247248
    248       double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime;
     249      double additionalTime = time - ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index)).ArrivalTime;
    249250      for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) {
    250         CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo;
     251        var nextStop = (CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(i);
    251252
    252253        if (demand >= 0) {
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPTW/MDCVRPTWEvaluator.cs

    r14185 r14677  
    4646
    4747    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) {
    48       TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));
    49       eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
    5048      double originalQuality = eval.Quality;
    5149
    52       IHeterogenousCapacitatedProblemInstance cvrpInstance = instance as IHeterogenousCapacitatedProblemInstance;
     50      var cvrpInstance = (IHeterogenousCapacitatedProblemInstance)instance;
    5351      DoubleArray demand = instance.Demand;
    54 
    55       ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
     52     
     53      var vrptw = (ITimeWindowedProblemInstance)instance;
    5654      DoubleArray dueTime = vrptw.DueTime;
    5755      DoubleArray readyTime = vrptw.ReadyTime;
    5856      DoubleArray serviceTimes = vrptw.ServiceTime;
    5957
    60       IMultiDepotProblemInstance mdp = instance as IMultiDepotProblemInstance;
     58      var mdp = (IMultiDepotProblemInstance)instance;
    6159      IntArray vehicleAssignment = mdp.VehicleDepotAssignment;
    6260      int depots = mdp.Depots.Value;
     
    7573
    7674      double capacity = cvrpInstance.Capacity[vehicle];
    77       for (int i = 0; i < tour.Stops.Count; i++) {
    78         delivered += instance.GetDemand(tour.Stops[i]);
    79       }
    80 
    81       double spareCapacity = capacity - delivered;
    8275
    8376      double tourStartTime = vrptw.ReadyTime[depot];
    8477      time = tourStartTime;
     78
     79      var tourInfo = new CVRPTWTourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)), capacity, tourStartTime);
     80      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
    8581
    8682      //simulate a tour, start and end at depot
     
    9086          start = tour.Stops[i - 1];
    9187        int end = 0;
    92         if (i < tour.Stops.Count)
     88        if (i < tour.Stops.Count) {
    9389          end = tour.Stops[i];
     90          delivered += instance.GetDemand(end);
     91        }
    9492
    9593        //drive there
    96         double currentDistace = vrptw.GetDistance(start, end, solution);
    97         time += currentDistace;
    98         distance += currentDistace;
     94        double currentDistance = vrptw.GetDistance(start, end, solution);
     95        time += currentDistance;
     96        distance += currentDistance;
    9997
    10098        double arrivalTime = time;
     
    129127        time += currentServiceTime;
    130128
    131         CVRPTWInsertionInfo stopInfo = new CVRPTWInsertionInfo(start, end, spareCapacity, tourStartTime, arrivalTime, time, spareTime, waitTime);
     129        var stopInfo = new CVRPTWStopInsertionInfo(start, end, currentDistance, capacity - delivered, arrivalTime, time, spareTime, waitTime);
    132130        tourInfo.AddStopInsertionInfo(stopInfo);
    133131      }
     
    142140      }
    143141
    144       (eval as CVRPEvaluation).Overload += overweight;
     142      ((CVRPEvaluation)eval).Overload += overweight;
    145143      double tourPenalty = 0;
    146144      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
     
    149147      tourPenalty += penalty;
    150148
    151       (eval as CVRPTWEvaluation).Tardiness += tardiness;
    152       (eval as CVRPTWEvaluation).TravelTime += time;
     149      ((CVRPTWEvaluation)eval).Tardiness += tardiness;
     150      ((CVRPTWEvaluation)eval).TravelTime += time;
    153151
    154152      penalty = tardiness * vrptw.TardinessPenalty.Value;
     
    163161    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
    164162      out bool feasible) {
    165       CVRPTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo;
     163      var tourInfo = (CVRPTWTourInsertionInfo)tourInsertionInfo;
     164      var insertionInfo = (CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index);
    166165
    167166      double costs = 0;
    168167      feasible = tourInsertionInfo.Penalty < double.Epsilon;
    169168
    170       ICapacitatedProblemInstance cvrp = instance as ICapacitatedProblemInstance;
     169      var cvrp = (ICapacitatedProblemInstance)instance;
    171170      double overloadPenalty = cvrp.OverloadPenalty.Value;
    172171
    173       ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
     172      var vrptw = (ITimeWindowedProblemInstance)instance;
    174173      DoubleArray dueTime = vrptw.DueTime;
    175174      DoubleArray readyTime = vrptw.ReadyTime;
     
    177176      double tardinessPenalty = vrptw.TardinessPenalty.Value;
    178177
    179       IMultiDepotProblemInstance mdp = instance as IMultiDepotProblemInstance;
     178      var mdp = (IMultiDepotProblemInstance)instance;
    180179      int depots = mdp.Depots.Value;
    181180
     
    184183
    185184      double demand = instance.GetDemand(customer);
    186       if (demand > insertionInfo.SpareCapacity) {
     185      if (demand > tourInfo.SpareCapacity) {
    187186        feasible = false;
    188187
    189         if (insertionInfo.SpareCapacity >= 0)
    190           costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty;
     188        if (tourInfo.SpareCapacity >= 0)
     189          costs += (demand - tourInfo.SpareCapacity) * overloadPenalty;
    191190        else
    192191          costs += demand * overloadPenalty;
     
    197196
    198197      if (index > 0)
    199         time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime;
     198        time = ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index - 1)).LeaveTime;
    200199      else
    201         time = insertionInfo.TourStartTime;
     200        time = tourInfo.TourStartTime;
    202201
    203202      time += startDistance;
     
    213212      time += endDistance;
    214213
    215       double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime;
     214      double additionalTime = time - ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index)).ArrivalTime;
    216215      for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) {
    217         CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo;
     216        var nextStop = (CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(i);
    218217
    219218        if (additionalTime < 0) {
     
    270269      base.SetResultParameters(tourEvaluation);
    271270
    272       TardinessParameter.ActualValue.Value = (tourEvaluation as CVRPTWEvaluation).Tardiness;
    273       TravelTimeParameter.ActualValue.Value = (tourEvaluation as CVRPTWEvaluation).TravelTime;
     271      TardinessParameter.ActualValue.Value = ((CVRPTWEvaluation)tourEvaluation).Tardiness;
     272      TravelTimeParameter.ActualValue.Value = ((CVRPTWEvaluation)tourEvaluation).TravelTime;
    274273    }
    275274
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MultiDepotVRPEvaluator.cs

    r14185 r14677  
    4747
    4848        //drive there
    49         double currentDistace = instance.GetDistance(start, end, solution);
    50         distance += currentDistace;
     49        double currentDistance = instance.GetDistance(start, end, solution);
     50        distance += currentDistance;
    5151
    52         StopInsertionInfo stopInfo = new StopInsertionInfo(start, end);
     52        var stopInfo = new StopInsertionInfo(start, end, currentDistance);
    5353        tourInfo.AddStopInsertionInfo(stopInfo);
    5454      }
     
    6868    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
    6969      out bool feasible) {
    70       StopInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index);
     70      var insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index);
    7171
    7272      double costs = 0;
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPEvaluation.cs

    r14185 r14677  
    2020#endregion
    2121
     22using System.Globalization;
     23using System.Linq;
     24using System.Text;
    2225
    2326namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
    24   public class CVRPInsertionInfo : StopInsertionInfo {
     27  public class CVRPStopInsertionInfo : StopInsertionInfo {
    2528    private double spareCapacity;
    2629
     
    2932    }
    3033
    31     public CVRPInsertionInfo(int start, int end, double spareCapacity)
    32       : base(start, end) {
     34    public CVRPStopInsertionInfo(int start, int end, double distance, double spareCapacity)
     35      : base(start, end, distance) {
    3336      this.spareCapacity = spareCapacity;
     37    }
     38
     39    protected override void GetStopInsertionReport(StringBuilder builder) {
     40      base.GetStopInsertionReport(builder);
     41      builder.Append("Capacity left:\t");
     42      builder.AppendLine(SpareCapacity.ToString(CultureInfo.CurrentCulture));
     43    }
     44  }
     45
     46  public class CVRPTourInsertionInfo : TourInsertionInfo {
     47    private double capacity;
     48
     49    public virtual double SpareCapacity {
     50      get { return stopInsertionInfos.Count == 0 ? capacity : ((CVRPStopInsertionInfo)stopInsertionInfos.Last()).SpareCapacity; }
     51    }
     52   
     53    public CVRPTourInsertionInfo(int vehicle, double capacity)
     54      : base(vehicle) {
     55      this.capacity = capacity;
     56    }
     57
     58    protected override void GetTourInsertionReport(StringBuilder builder) {
     59      base.GetTourInsertionReport(builder);
     60      builder.Append("Capacity left:\t");
     61      builder.AppendLine(SpareCapacity.ToString(CultureInfo.CurrentCulture));
    3462    }
    3563  }
     
    3765  public class CVRPEvaluation : VRPEvaluation {
    3866    public double Overload { get; set; }
     67
     68    protected override void GetEvaluationReport(StringBuilder builder) {
     69      base.GetEvaluationReport(builder);
     70      builder.Append("Overload:\t");
     71      builder.AppendLine(Overload.ToString(CultureInfo.CurrentCulture));
     72    }
    3973  }
    4074}
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPEvaluator.cs

    r14185 r14677  
    4141
    4242    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) {
    43       TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour))); ;
     43      var cvrpInstance = (IHomogenousCapacitatedProblemInstance)instance;
     44      double capacity = cvrpInstance.Capacity.Value;
     45      var tourInfo = new CVRPTourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)), capacity);
    4446      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
    4547      double originalQuality = eval.Quality;
    4648
    47       IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance;
    4849      DoubleArray demand = instance.Demand;
    4950
     
    5152      double overweight = 0.0;
    5253      double distance = 0.0;
    53 
    54       double capacity = cvrpInstance.Capacity.Value;
    55       for (int i = 0; i <= tour.Stops.Count; i++) {
    56         int end = 0;
    57         if (i < tour.Stops.Count)
    58           end = tour.Stops[i];
    59 
    60         delivered += demand[end];
    61       }
    62 
    63       double spareCapacity = capacity - delivered;
    6454
    6555      //simulate a tour, start and end at depot
     
    7262          end = tour.Stops[i];
    7363
     64        delivered += demand[end];
     65
    7466        //drive there
    75         double currentDistace = instance.GetDistance(start, end, solution);
    76         distance += currentDistace;
     67        double currentDistance = instance.GetDistance(start, end, solution);
     68        distance += currentDistance;
    7769
    78         CVRPInsertionInfo stopInfo = new CVRPInsertionInfo(start, end, spareCapacity);
     70        var stopInfo = new CVRPStopInsertionInfo(start, end, currentDistance, capacity - delivered);
    7971        tourInfo.AddStopInsertionInfo(stopInfo);
    8072      }
     
    9082      }
    9183
    92       (eval as CVRPEvaluation).Overload += overweight;
     84      ((CVRPEvaluation)eval).Overload += overweight;
    9385      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
    9486      eval.Penalty += penalty;
     
    10092    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
    10193      out bool feasible) {
    102       CVRPInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPInsertionInfo;
     94      var tourInfo = (CVRPTourInsertionInfo)tourInsertionInfo;
     95      var insertionInfo = (CVRPStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index);
    10396
    10497      double costs = 0;
    10598      feasible = tourInsertionInfo.Penalty < double.Epsilon;
    10699
    107       ICapacitatedProblemInstance cvrp = instance as ICapacitatedProblemInstance;
     100      var cvrp = (ICapacitatedProblemInstance)instance;
    108101      double overloadPenalty = cvrp.OverloadPenalty.Value;
    109102
     
    115108
    116109      double demand = instance.Demand[customer];
    117       if (demand > insertionInfo.SpareCapacity) {
     110      if (demand > tourInfo.SpareCapacity) {
    118111        feasible = false;
    119112
    120         if (insertionInfo.SpareCapacity >= 0)
    121           costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty;
     113        if (tourInfo.SpareCapacity >= 0)
     114          costs += (demand - tourInfo.SpareCapacity) * overloadPenalty;
    122115        else
    123116          costs += demand * overloadPenalty;
     
    136129      base.SetResultParameters(tourEvaluation);
    137130
    138       OverloadParameter.ActualValue.Value = (tourEvaluation as CVRPEvaluation).Overload;
     131      OverloadParameter.ActualValue.Value = ((CVRPEvaluation)tourEvaluation).Overload;
    139132    }
    140133
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWEvaluation.cs

    r14185 r14677  
    2323
    2424namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
    25   public class CVRPPDTWInsertionInfo : CVRPTWInsertionInfo {
     25  public class CVRPPDTWStopInsertionInfo : CVRPTWStopInsertionInfo {
    2626    private List<int> visited;
    2727
     
    3636    }
    3737
    38     public CVRPPDTWInsertionInfo(int start, int end, double spareCapacity, double tourStartTime,
     38    public CVRPPDTWStopInsertionInfo(int start, int end, double distance, double spareCapacity,
    3939      double arrivalTime, double leaveTime, double spareTime, double waitingTime, List<int> visited, double arrivalSpareCapacity)
    40       : base(start, end, spareCapacity, tourStartTime, arrivalTime, leaveTime, spareTime, waitingTime) {
     40      : base(start, end, distance, spareCapacity, arrivalTime, leaveTime, spareTime, waitingTime) {
    4141      this.visited = visited;
    4242      this.arrivalSpareCapacity = arrivalSpareCapacity;
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWEvaluator.cs

    r14185 r14677  
    4343
    4444    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) {
    45       TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));
    46       eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
     45      var cvrpInstance = (IHomogenousCapacitatedProblemInstance)instance;
     46      double capacity = cvrpInstance.Capacity.Value;
    4747      double originalQuality = eval.Quality;
    4848
    49       IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance;
    5049      DoubleArray demand = instance.Demand;
    5150
    52       ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
     51      var vrptw = (ITimeWindowedProblemInstance)instance;
    5352      DoubleArray dueTime = vrptw.DueTime;
    5453      DoubleArray readyTime = vrptw.ReadyTime;
    5554      DoubleArray serviceTimes = vrptw.ServiceTime;
    5655
    57       IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance;
     56      var pdp = (IPickupAndDeliveryProblemInstance)instance;
    5857      IntArray pickupDeliveryLocation = pdp.PickupDeliveryLocation;
    5958
    60       double capacity = cvrpInstance.Capacity.Value;
    6159
    6260      double time = 0.0;
     
    7371      double tourStartTime = readyTime[0];
    7472      time = tourStartTime;
     73
     74      var tourInfo = new CVRPTWTourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)), capacity, tourStartTime);
     75      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
    7576
    7677      //simulate a tour, start and end at depot
     
    8485
    8586        //drive there
    86         double currentDistace = vrptw.GetDistance(start, end, solution);
    87         time += currentDistace;
    88         distance += currentDistace;
     87        double currentDistance = vrptw.GetDistance(start, end, solution);
     88        time += currentDistance;
     89        distance += currentDistance;
    8990
    9091        double arrivalTime = time;
     
    115116
    116117        bool validPickupDelivery =
    117           validPickupDelivery =
    118118          ((demand[end] >= 0) ||
    119119           (stops.ContainsKey(pickupDeliveryLocation[end])));
     
    129129
    130130        double spareCapacity = capacity - currentLoad;
    131         CVRPPDTWInsertionInfo stopInfo = new CVRPPDTWInsertionInfo(start, end, spareCapacity, tourStartTime,
     131        var stopInfo = new CVRPPDTWStopInsertionInfo(start, end, currentDistance, spareCapacity,
    132132          arrivalTime, time, spareTime, waitTime, new List<int>(stops.Keys), arrivalSpareCapacity);
    133133        tourInfo.AddStopInsertionInfo(stopInfo);
     
    141141      eval.VehicleUtilization += 1;
    142142
    143       (eval as CVRPEvaluation).Overload += overweight;
     143      ((CVRPEvaluation)eval).Overload += overweight;
    144144      double tourPenalty = 0;
    145145      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
     
    148148      tourPenalty += penalty;
    149149
    150       (eval as CVRPTWEvaluation).Tardiness += tardiness;
    151       (eval as CVRPTWEvaluation).TravelTime += time;
     150      ((CVRPTWEvaluation)eval).Tardiness += tardiness;
     151      ((CVRPTWEvaluation)eval).TravelTime += time;
    152152
    153153      penalty = tardiness * vrptw.TardinessPenalty.Value;
     
    156156      tourPenalty += penalty;
    157157
    158       (eval as CVRPPDTWEvaluation).PickupViolations += pickupViolations;
     158      ((CVRPPDTWEvaluation)eval).PickupViolations += pickupViolations;
    159159      penalty = pickupViolations * pdp.PickupViolationPenalty.Value;
    160160      eval.Penalty += penalty;
     
    169169    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
    170170      out bool feasible) {
    171       CVRPPDTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPPDTWInsertionInfo;
     171      var tourInfo = (CVRPTWTourInsertionInfo)tourInsertionInfo;
     172      var insertionInfo = (CVRPPDTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index);
    172173
    173174      double costs = 0;
     
    175176      bool tourFeasible = true;
    176177
    177       ICapacitatedProblemInstance cvrp = instance as ICapacitatedProblemInstance;
     178      var cvrp = (ICapacitatedProblemInstance)instance;
    178179      double overloadPenalty = cvrp.OverloadPenalty.Value;
    179180
    180       ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
     181      var vrptw = (ITimeWindowedProblemInstance)instance;
    181182      DoubleArray dueTime = vrptw.DueTime;
    182183      DoubleArray readyTime = vrptw.ReadyTime;
     
    184185      double tardinessPenalty = vrptw.TardinessPenalty.Value;
    185186
    186       IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance;
     187      IPickupAndDeliveryProblemInstance pdp = (IPickupAndDeliveryProblemInstance)instance;
    187188      IntArray pickupDeliveryLocation = pdp.PickupDeliveryLocation;
    188189      double pickupPenalty = pdp.PickupViolationPenalty.Value;
     
    215216
    216217      if (index > 0)
    217         time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime;
     218        time = ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index - 1)).LeaveTime;
    218219      else
    219         time = insertionInfo.TourStartTime;
     220        time = tourInfo.TourStartTime;
    220221
    221222      time += instance.GetDistance(insertionInfo.Start, customer, solution);
     
    228229      time += instance.GetDistance(customer, insertionInfo.End, solution);
    229230
    230       double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime;
     231      double additionalTime = time - ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index)).ArrivalTime;
    231232      for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) {
    232         CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo;
     233        var nextStop = (CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(i);
    233234
    234235        if (demand >= 0) {
     
    246247        } else if (validPickup) {
    247248          if (nextStop.SpareCapacity < 0) {
     249            // ABE: The costs decrease when there is overload!?
    248250            costs += Math.Max(demand, nextStop.SpareCapacity) * overloadPenalty;
    249251          }
     
    263265          //check due date, decrease tardiness
    264266          if (nextStop.SpareTime < 0) {
     267            // ABE: Again, the costs decrease when there is tardiness!?
    265268            costs += Math.Max(nextStop.SpareTime, additionalTime) * tardinessPenalty;
    266269          }
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWEvaluation.cs

    r14185 r14677  
    2020#endregion
    2121
     22using System;
     23using System.Globalization;
     24using System.Text;
    2225
    2326namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
    24   public class CVRPTWInsertionInfo : CVRPInsertionInfo {
    25     private double tourStartTime;
    26 
    27     public double TourStartTime {
    28       get { return tourStartTime; }
    29     }
     27  public class CVRPTWStopInsertionInfo : CVRPStopInsertionInfo {
    3028
    3129    private double arrivalTime;
     
    5351    }
    5452
    55     public CVRPTWInsertionInfo(int start, int end, double spareCapacity, double tourStartTime, double arrivalTime, double leaveTime, double spareTime, double waitingTime)
    56       : base(start, end, spareCapacity) {
    57       this.tourStartTime = tourStartTime;
     53    public CVRPTWStopInsertionInfo(int start, int end, double distance, double spareCapacity, double arrivalTime, double leaveTime, double spareTime, double waitingTime)
     54      : base(start, end, distance, spareCapacity) {
    5855      this.arrivalTime = arrivalTime;
    5956      this.leaveTime = leaveTime;
    6057      this.spareTime = spareTime;
    6158      this.waitingTime = waitingTime;
     59    }
     60
     61    protected override void GetStopInsertionReport(StringBuilder builder) {
     62      base.GetStopInsertionReport(builder);
     63      builder.Append("SpareTime:\t");
     64      builder.AppendLine(SpareTime.ToString(CultureInfo.CurrentCulture));
     65      builder.Append("ArrivalTime:\t");
     66      builder.AppendLine(ArrivalTime.ToString(CultureInfo.CurrentCulture));
     67      builder.Append("WaitingTime:\t");
     68      builder.AppendLine(Math.Max(0, WaitingTime).ToString(CultureInfo.CurrentCulture));
     69      builder.Append("LeaveTime:\t");
     70      builder.AppendLine(LeaveTime.ToString(CultureInfo.CurrentCulture));
     71    }
     72  }
     73
     74  public class CVRPTWTourInsertionInfo : CVRPTourInsertionInfo {
     75    private double tourStartTime;
     76
     77    public double TourStartTime {
     78      get { return tourStartTime; }
     79    }
     80
     81    public CVRPTWTourInsertionInfo(int vehicle, double capacity, double tourStartTime)
     82      : base(vehicle, capacity) {
     83      this.tourStartTime = tourStartTime;
     84    }
     85
     86    protected override void GetTourInsertionReport(StringBuilder builder) {
     87      base.GetTourInsertionReport(builder);
     88      builder.Append("Tour start:\t");
     89      builder.AppendLine(TourStartTime.ToString(CultureInfo.CurrentCulture));
    6290    }
    6391  }
     
    6694    public double Tardiness { get; set; }
    6795    public double TravelTime { get; set; }
     96
     97    protected override void GetEvaluationReport(StringBuilder builder) {
     98      base.GetEvaluationReport(builder);
     99      builder.Append("TravelTime:\t");
     100      builder.AppendLine(TravelTime.ToString(CultureInfo.CurrentCulture));
     101      builder.Append("Tardiness:\t");
     102      builder.AppendLine(Tardiness.ToString(CultureInfo.CurrentCulture));
     103    }
    68104  }
    69105}
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWEvaluator.cs

    r14185 r14677  
    4646
    4747    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) {
    48       TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));
    49       eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
     48      var cvrpInstance = (IHomogenousCapacitatedProblemInstance)instance;
     49
    5050      double originalQuality = eval.Quality;
    5151
    52       IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance;
    5352      DoubleArray demand = instance.Demand;
    5453
    55       ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
     54      var vrptw = (ITimeWindowedProblemInstance)instance;
    5655      DoubleArray dueTime = vrptw.DueTime;
    5756      DoubleArray readyTime = vrptw.ReadyTime;
     
    6766
    6867      double capacity = cvrpInstance.Capacity.Value;
    69       for (int i = 0; i <= tour.Stops.Count; i++) {
    70         int end = 0;
    71         if (i < tour.Stops.Count)
    72           end = tour.Stops[i];
    73 
    74         delivered += demand[end];
    75       }
    76 
    77       double spareCapacity = capacity - delivered;
    78 
     68     
    7969      double tourStartTime = readyTime[0];
    8070      time = tourStartTime;
     71
     72      var tourInfo = new CVRPTWTourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)), cvrpInstance.Capacity.Value, tourStartTime);
     73      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
    8174
    8275      //simulate a tour, start and end at depot
     
    9083
    9184        //drive there
    92         double currentDistace = vrptw.GetDistance(start, end, solution);
    93         time += currentDistace;
    94         distance += currentDistace;
     85        double currentDistance = vrptw.GetDistance(start, end, solution);
     86        time += currentDistance;
     87        distance += currentDistance;
     88        delivered += demand[end];
    9589
    9690        double arrivalTime = time;
     
    117111        time += currentServiceTime;
    118112
    119         CVRPTWInsertionInfo stopInfo = new CVRPTWInsertionInfo(start, end, spareCapacity, tourStartTime, arrivalTime, time, spareTime, waitTime);
     113        var stopInfo = new CVRPTWStopInsertionInfo(start, end, currentDistance, capacity - delivered, arrivalTime, time, spareTime, waitTime);
    120114        tourInfo.AddStopInsertionInfo(stopInfo);
    121115      }
     
    130124      }
    131125
    132       (eval as CVRPEvaluation).Overload += overweight;
     126      ((CVRPEvaluation)eval).Overload += overweight;
    133127      double tourPenalty = 0;
    134128      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
     
    151145    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
    152146      out bool feasible) {
    153       CVRPTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo;
     147      var tourInfo = (CVRPTWTourInsertionInfo)tourInsertionInfo;
     148      var insertionInfo = (CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index);
    154149
    155150      double costs = 0;
    156151      feasible = tourInsertionInfo.Penalty < double.Epsilon;
    157152
    158       ICapacitatedProblemInstance cvrp = instance as ICapacitatedProblemInstance;
     153      var cvrp = (ICapacitatedProblemInstance)instance;
    159154      double overloadPenalty = cvrp.OverloadPenalty.Value;
    160155
    161       ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
     156      var vrptw = (ITimeWindowedProblemInstance)instance;
    162157      DoubleArray dueTime = vrptw.DueTime;
    163158      DoubleArray readyTime = vrptw.ReadyTime;
     
    172167
    173168      double demand = instance.Demand[customer];
    174       if (demand > insertionInfo.SpareCapacity) {
     169      if (demand > tourInfo.SpareCapacity) {
    175170        feasible = false;
    176         if (insertionInfo.SpareCapacity >= 0)
    177           costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty;
     171        if (tourInfo.SpareCapacity >= 0)
     172          costs += (demand - tourInfo.SpareCapacity) * overloadPenalty;
    178173        else
    179174          costs += demand * overloadPenalty;
     
    184179
    185180      if (index > 0)
    186         time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime;
     181        time = ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index - 1)).LeaveTime;
    187182      else
    188         time = insertionInfo.TourStartTime;
     183        time = tourInfo.TourStartTime;
    189184
    190185      time += instance.GetDistance(insertionInfo.Start, customer, solution);
     
    197192      time += instance.GetDistance(customer, insertionInfo.End, solution);
    198193
    199       double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime;
     194      double additionalTime = time - ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index)).ArrivalTime;
    200195      for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) {
    201         CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo;
     196        var nextStop = (CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(i);
    202197
    203198        if (additionalTime < 0) {
     
    254249      base.SetResultParameters(tourEvaluation);
    255250
    256       TardinessParameter.ActualValue.Value = (tourEvaluation as CVRPTWEvaluation).Tardiness;
    257       TravelTimeParameter.ActualValue.Value = (tourEvaluation as CVRPTWEvaluation).TravelTime;
     251      TardinessParameter.ActualValue.Value = ((CVRPTWEvaluation)tourEvaluation).Tardiness;
     252      TravelTimeParameter.ActualValue.Value = ((CVRPTWEvaluation)tourEvaluation).TravelTime;
    258253    }
    259254
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/SingleDepotVRPEvaluator.cs

    r14185 r14677  
    3131  public class SingleDepotVRPEvaluator : VRPEvaluator {
    3232    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) {
    33       TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));
     33      var tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));
    3434      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
    3535
     
    4747
    4848        //drive there
    49         double currentDistace = instance.GetDistance(start, end, solution);
    50         distance += currentDistace;
     49        double currentDistance = instance.GetDistance(start, end, solution);
     50        distance += currentDistance;
    5151
    52         StopInsertionInfo stopInfo = new StopInsertionInfo(start, end);
     52        var stopInfo = new StopInsertionInfo(start, end, currentDistance);
    5353        tourInfo.AddStopInsertionInfo(stopInfo);
    5454      }
     
    6868    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
    6969      out bool feasible) {
    70       StopInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index);
     70      var insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index);
    7171
    7272      double costs = 0;
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPEvaluation.cs

    r14185 r14677  
    2121
    2222using System.Collections.Generic;
     23using System.Globalization;
     24using System.Linq;
     25using System.Text;
    2326
    2427namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
    2528  public class StopInsertionInfo {
    2629    private int start;
    27 
    2830    public int Start {
    2931      get { return start; }
     
    3133
    3234    private int end;
    33 
    3435    public int End {
    3536      get { return end; }
    3637    }
    3738
    38     public StopInsertionInfo(int start, int end)
     39    private double distance;
     40    public double Distance {
     41      get { return distance; }
     42    }
     43
     44    public StopInsertionInfo(int start, int end, double distance)
    3945      : base() {
    4046      this.start = start;
    4147      this.end = end;
     48      this.distance = distance;
     49    }
     50
     51    protected virtual void GetStopInsertionReport(StringBuilder builder) {
     52      builder.Append("From\t");
     53      builder.Append(Start.ToString(CultureInfo.CurrentCulture));
     54      builder.Append("\tto\t");
     55      builder.AppendLine(End.ToString(CultureInfo.CurrentCulture));
     56      builder.Append("Distance:\t");
     57      builder.AppendLine(Distance.ToString(CultureInfo.CurrentCulture));
     58    }
     59
     60    public virtual void GetReport(StringBuilder builder) {
     61      GetStopInsertionReport(builder);
    4262    }
    4363  }
     
    4666    public double Penalty { get; set; }
    4767    public double Quality { get; set; }
     68    public double Distance { get { return stopInsertionInfos.Count > 0 ? stopInsertionInfos.Sum(x => x.Distance) : 0; } }
    4869
    4970    public int Vehicle { get; set; }
    5071
    51     private List<StopInsertionInfo> stopInsertionInfos;
     72    protected List<StopInsertionInfo> stopInsertionInfos;
    5273
    5374    public TourInsertionInfo(int vehicle)
     
    6889      return stopInsertionInfos.Count;
    6990    }
     91
     92    protected virtual void GetTourInsertionReport(StringBuilder builder) {
     93      builder.AppendLine("=== Tour ===");
     94      builder.Append("Vehicle:\t");
     95      builder.AppendLine(Vehicle.ToString(CultureInfo.CurrentCulture));
     96      builder.Append("Distance:\t");
     97      builder.AppendLine(Distance.ToString(CultureInfo.CurrentCulture));
     98      builder.Append("Quality:\t");
     99      builder.AppendLine(Quality.ToString(CultureInfo.CurrentCulture));
     100      builder.Append("Penalty:\t");
     101      builder.AppendLine(Penalty.ToString(CultureInfo.CurrentCulture));
     102    }
     103
     104    public virtual void GetReport(StringBuilder builder) {
     105      GetTourInsertionReport(builder);
     106      builder.AppendLine("==== Stops ====");
     107      for (var i = 0; i < stopInsertionInfos.Count; i++) {
     108        stopInsertionInfos[i].GetReport(builder);
     109      }
     110    }
    70111  }
    71112
     
    85126      return tourInsertionInfos[tour];
    86127    }
     128
     129    protected virtual void GetInsertionReport(StringBuilder builder) {
     130      builder.AppendLine("== VRP Route Report ==");
     131    }
     132
     133    public virtual void GetReport(StringBuilder builder) {
     134      GetInsertionReport(builder);
     135      for (var i = 0; i < tourInsertionInfos.Count; i++) {
     136        tourInsertionInfos[i].GetReport(builder);
     137      }
     138    }
    87139  }
    88140
     
    98150      InsertionInfo = new InsertionInfo();
    99151    }
     152
     153    protected virtual void GetEvaluationReport(StringBuilder builder) {
     154      builder.AppendLine("= VRP Solution Report =");
     155      builder.Append("Quality:\t");
     156      builder.AppendLine(Quality.ToString(CultureInfo.CurrentCulture));
     157      builder.Append("Penalty:\t");
     158      builder.AppendLine(Penalty.ToString(CultureInfo.CurrentCulture));
     159      builder.Append("Distance:\t");
     160      builder.AppendLine(Distance.ToString(CultureInfo.CurrentCulture));
     161      builder.Append("Vehicles used:\t");
     162      builder.AppendLine(VehicleUtilization.ToString(CultureInfo.CurrentCulture));
     163    }
     164
     165    public virtual void GetReport(StringBuilder builder) {
     166      GetEvaluationReport(builder);
     167      InsertionInfo.GetReport(builder);
     168    }
    100169  }
    101170}
Note: See TracChangeset for help on using the changeset viewer.