[4363] | 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 |
|
---|
| 36 | namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
|
---|
| 37 | [Item("CVRPTWEvaluator", "Represents a single depot CVRPTW evaluator.")]
|
---|
| 38 | [StorableClass]
|
---|
| 39 | public class CVRPTWEvaluator: CVRPEvaluator {
|
---|
| 40 | public ILookupParameter<DoubleValue> TardinessParameter {
|
---|
| 41 | get { return (ILookupParameter<DoubleValue>)Parameters["Tardiness"]; }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[4374] | 44 | public ILookupParameter<DoubleValue> TravelTimeParameter {
|
---|
| 45 | get { return (ILookupParameter<DoubleValue>)Parameters["TravelTime"]; }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[4363] | 48 | protected override VRPEvaluation CreateTourEvaluation() {
|
---|
| 49 | return new CVRPTWEvaluation();
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour) {
|
---|
| 53 | base.EvaluateTour(eval, instance, tour);
|
---|
| 54 |
|
---|
| 55 | ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
|
---|
| 56 |
|
---|
| 57 | double time = 0.0;
|
---|
| 58 | double waitingTime = 0.0;
|
---|
| 59 | double serviceTime = 0.0;
|
---|
| 60 | double tardiness = 0.0;
|
---|
| 61 |
|
---|
| 62 | //simulate a tour, start and end at depot
|
---|
| 63 | for (int i = 0; i <= tour.Stops.Count; i++) {
|
---|
| 64 | int start = 0;
|
---|
| 65 | if (i > 0)
|
---|
| 66 | start = tour.Stops[i - 1];
|
---|
| 67 | int end = 0;
|
---|
| 68 | if (i < tour.Stops.Count)
|
---|
| 69 | end = tour.Stops[i];
|
---|
| 70 |
|
---|
| 71 | //drive there
|
---|
| 72 | double currentDistace = vrptw.GetDistance(start, end);
|
---|
| 73 | time += currentDistace;
|
---|
| 74 |
|
---|
| 75 | //check if it was serviced on time
|
---|
| 76 | if (time > vrptw.DueTime[end])
|
---|
| 77 | tardiness += time - vrptw.DueTime[end];
|
---|
| 78 |
|
---|
| 79 | //wait
|
---|
| 80 | double currentWaitingTime = 0.0;
|
---|
| 81 | if (time < vrptw.ReadyTime[end])
|
---|
| 82 | currentWaitingTime = vrptw.ReadyTime[end] - time;
|
---|
| 83 | waitingTime += currentWaitingTime;
|
---|
| 84 | time += currentWaitingTime;
|
---|
| 85 |
|
---|
| 86 | //service
|
---|
| 87 | double currentServiceTime = vrptw.ServiceTime[end];
|
---|
| 88 | serviceTime += currentServiceTime;
|
---|
| 89 | time += currentServiceTime;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | (eval as CVRPTWEvaluation).Tardiness = tardiness;
|
---|
[4374] | 93 | (eval as CVRPTWEvaluation).TravelTime = time;
|
---|
| 94 |
|
---|
[4363] | 95 | double penalty = tardiness * vrptw.TardinessPenalty.Value;
|
---|
| 96 | eval.Penalty += penalty;
|
---|
| 97 | eval.Quality += penalty;
|
---|
| 98 | eval.Quality += time * vrptw.TimeFactor.Value;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | protected override void InitResultParameters() {
|
---|
| 102 | base.InitResultParameters();
|
---|
| 103 |
|
---|
| 104 | TardinessParameter.ActualValue = new DoubleValue(0);
|
---|
[4374] | 105 | TravelTimeParameter.ActualValue = new DoubleValue(0);
|
---|
[4363] | 106 | }
|
---|
| 107 |
|
---|
| 108 | protected override void UpdateResultParameters(VRPEvaluation tourEvaluation) {
|
---|
| 109 | base.UpdateResultParameters(tourEvaluation);
|
---|
| 110 |
|
---|
| 111 | TardinessParameter.ActualValue.Value += (tourEvaluation as CVRPTWEvaluation).Tardiness;
|
---|
[4374] | 112 | TravelTimeParameter.ActualValue.Value += (tourEvaluation as CVRPTWEvaluation).TravelTime;
|
---|
[4363] | 113 | }
|
---|
| 114 |
|
---|
| 115 | [StorableConstructor]
|
---|
| 116 | protected CVRPTWEvaluator(bool deserializing) : base(deserializing) { }
|
---|
| 117 |
|
---|
| 118 | public CVRPTWEvaluator() {
|
---|
| 119 | Parameters.Add(new LookupParameter<DoubleValue>("Tardiness", "The tardiness."));
|
---|
[4374] | 120 | Parameters.Add(new LookupParameter<DoubleValue>("TravelTime", "The travel time."));
|
---|
[4363] | 121 | }
|
---|
| 122 | }
|
---|
| 123 | } |
---|