1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
28 | using HeuristicLab.Core;
|
---|
29 | using HeuristicLab.Parameters;
|
---|
30 | using HeuristicLab.Data;
|
---|
31 | using HeuristicLab.Optimization;
|
---|
32 | using HeuristicLab.PluginInfrastructure;
|
---|
33 | using HeuristicLab.Problems.VehicleRouting.Variants;
|
---|
34 | using HeuristicLab.Problems.VehicleRouting.Encodings;
|
---|
35 | using HeuristicLab.Common;
|
---|
36 |
|
---|
37 | namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
|
---|
38 | [Item("CVRPTWEvaluator", "Represents a single depot CVRPTW evaluator.")]
|
---|
39 | [StorableClass]
|
---|
40 | public class CVRPTWEvaluator: CVRPEvaluator {
|
---|
41 | public ILookupParameter<DoubleValue> TardinessParameter {
|
---|
42 | get { return (ILookupParameter<DoubleValue>)Parameters["Tardiness"]; }
|
---|
43 | }
|
---|
44 |
|
---|
45 | public ILookupParameter<DoubleValue> TravelTimeParameter {
|
---|
46 | get { return (ILookupParameter<DoubleValue>)Parameters["TravelTime"]; }
|
---|
47 | }
|
---|
48 |
|
---|
49 | protected override VRPEvaluation CreateTourEvaluation() {
|
---|
50 | return new CVRPTWEvaluation();
|
---|
51 | }
|
---|
52 |
|
---|
53 | protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour) {
|
---|
54 | IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance;
|
---|
55 | DoubleArray demand = instance.Demand;
|
---|
56 |
|
---|
57 | ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
|
---|
58 | DoubleArray dueTime = vrptw.DueTime;
|
---|
59 | DoubleArray readyTime = vrptw.ReadyTime;
|
---|
60 | DoubleArray serviceTimes = vrptw.ServiceTime;
|
---|
61 |
|
---|
62 | double time = 0.0;
|
---|
63 | double waitingTime = 0.0;
|
---|
64 | double serviceTime = 0.0;
|
---|
65 | double tardiness = 0.0;
|
---|
66 | double delivered = 0.0;
|
---|
67 | double overweight = 0.0;
|
---|
68 | double distance = 0.0;
|
---|
69 |
|
---|
70 | //simulate a tour, start and end at depot
|
---|
71 | for (int i = 0; i <= tour.Stops.Count; i++) {
|
---|
72 | int start = 0;
|
---|
73 | if (i > 0)
|
---|
74 | start = tour.Stops[i - 1];
|
---|
75 | int end = 0;
|
---|
76 | if (i < tour.Stops.Count)
|
---|
77 | end = tour.Stops[i];
|
---|
78 |
|
---|
79 | //drive there
|
---|
80 | double currentDistace = vrptw.GetDistance(start, end);
|
---|
81 | time += currentDistace;
|
---|
82 | distance += currentDistace;
|
---|
83 |
|
---|
84 | //check if it was serviced on time
|
---|
85 | if (time > dueTime[end])
|
---|
86 | tardiness += time - dueTime[end];
|
---|
87 |
|
---|
88 | //wait
|
---|
89 | double currentWaitingTime = 0.0;
|
---|
90 | if (time < readyTime[end])
|
---|
91 | currentWaitingTime = readyTime[end] - time;
|
---|
92 | waitingTime += currentWaitingTime;
|
---|
93 | time += currentWaitingTime;
|
---|
94 |
|
---|
95 | //service
|
---|
96 | double currentServiceTime = serviceTimes[end];
|
---|
97 | serviceTime += currentServiceTime;
|
---|
98 | time += currentServiceTime;
|
---|
99 | delivered += demand[end];
|
---|
100 | }
|
---|
101 |
|
---|
102 | eval.Quality += instance.FleetUsageFactor.Value;
|
---|
103 | eval.Quality += instance.DistanceFactor.Value * distance;
|
---|
104 | eval.Distance += distance;
|
---|
105 | eval.VehicleUtilization += 1;
|
---|
106 |
|
---|
107 | double capacity = cvrpInstance.Capacity.Value;
|
---|
108 | if (delivered > capacity) {
|
---|
109 | overweight = delivered - capacity;
|
---|
110 | }
|
---|
111 |
|
---|
112 | (eval as CVRPEvaluation).Overload += overweight;
|
---|
113 | double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
|
---|
114 | eval.Penalty += penalty;
|
---|
115 | eval.Quality += penalty;
|
---|
116 |
|
---|
117 | (eval as CVRPTWEvaluation).Tardiness += tardiness;
|
---|
118 | (eval as CVRPTWEvaluation).TravelTime += time;
|
---|
119 |
|
---|
120 | penalty = tardiness * vrptw.TardinessPenalty.Value;
|
---|
121 | eval.Penalty += penalty;
|
---|
122 | eval.Quality += penalty;
|
---|
123 | eval.Quality += time * vrptw.TimeFactor.Value;
|
---|
124 | }
|
---|
125 |
|
---|
126 | protected override void InitResultParameters() {
|
---|
127 | base.InitResultParameters();
|
---|
128 |
|
---|
129 | TardinessParameter.ActualValue = new DoubleValue(0);
|
---|
130 | TravelTimeParameter.ActualValue = new DoubleValue(0);
|
---|
131 | }
|
---|
132 |
|
---|
133 | protected override void SetResultParameters(VRPEvaluation tourEvaluation) {
|
---|
134 | base.SetResultParameters(tourEvaluation);
|
---|
135 |
|
---|
136 | TardinessParameter.ActualValue.Value = (tourEvaluation as CVRPTWEvaluation).Tardiness;
|
---|
137 | TravelTimeParameter.ActualValue.Value = (tourEvaluation as CVRPTWEvaluation).TravelTime;
|
---|
138 | }
|
---|
139 |
|
---|
140 | [StorableConstructor]
|
---|
141 | protected CVRPTWEvaluator(bool deserializing) : base(deserializing) { }
|
---|
142 |
|
---|
143 | public CVRPTWEvaluator() {
|
---|
144 | Parameters.Add(new LookupParameter<DoubleValue>("Tardiness", "The tardiness."));
|
---|
145 | Parameters.Add(new LookupParameter<DoubleValue>("TravelTime", "The travel time."));
|
---|
146 | }
|
---|
147 |
|
---|
148 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
149 | return new CVRPTWEvaluator(this, cloner);
|
---|
150 | }
|
---|
151 |
|
---|
152 | protected CVRPTWEvaluator(CVRPTWEvaluator original, Cloner cloner)
|
---|
153 | : base(original, cloner) {
|
---|
154 | }
|
---|
155 | }
|
---|
156 | } |
---|