[4154] | 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 |
|
---|
[4722] | 22 | using HeuristicLab.Common;
|
---|
[4154] | 23 | using HeuristicLab.Core;
|
---|
[4722] | 24 | using HeuristicLab.Data;
|
---|
[4154] | 25 | using HeuristicLab.Operators;
|
---|
| 26 | using HeuristicLab.Parameters;
|
---|
[4722] | 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[4174] | 28 | using HeuristicLab.Problems.VehicleRouting.Encodings;
|
---|
[4154] | 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.VehicleRouting {
|
---|
[4179] | 31 | [Item("VRPOperator", "A VRP operator.")]
|
---|
| 32 | [StorableClass]
|
---|
[4154] | 33 | public abstract class VRPOperator : SingleSuccessorOperator, IVRPOperator {
|
---|
| 34 | public int Cities {
|
---|
| 35 | get { return CoordinatesParameter.ActualValue.Rows - 1; }
|
---|
| 36 | }
|
---|
| 37 | public ILookupParameter<DoubleMatrix> CoordinatesParameter {
|
---|
[4179] | 38 | get {
|
---|
| 39 | if (Parameters.ContainsKey("Coordinates"))
|
---|
| 40 | return (ILookupParameter<DoubleMatrix>)Parameters["Coordinates"];
|
---|
| 41 | else
|
---|
| 42 | return null;
|
---|
| 43 | }
|
---|
[4154] | 44 | }
|
---|
| 45 | public ILookupParameter<DoubleMatrix> DistanceMatrixParameter {
|
---|
[4179] | 46 | get {
|
---|
| 47 | if (Parameters.ContainsKey("DistanceMatrix"))
|
---|
| 48 | return (ILookupParameter<DoubleMatrix>)Parameters["DistanceMatrix"];
|
---|
| 49 | else
|
---|
| 50 | return null;
|
---|
| 51 | }
|
---|
[4154] | 52 | }
|
---|
| 53 | public ILookupParameter<BoolValue> UseDistanceMatrixParameter {
|
---|
[4179] | 54 | get {
|
---|
| 55 | if (Parameters.ContainsKey("UseDistanceMatrix"))
|
---|
| 56 | return (ILookupParameter<BoolValue>)Parameters["UseDistanceMatrix"];
|
---|
| 57 | else
|
---|
| 58 | return null;
|
---|
| 59 | }
|
---|
[4154] | 60 | }
|
---|
| 61 | public ILookupParameter<IntValue> VehiclesParameter {
|
---|
[4179] | 62 | get {
|
---|
| 63 | if (Parameters.ContainsKey("Vehicles"))
|
---|
| 64 | return (ILookupParameter<IntValue>)Parameters["Vehicles"];
|
---|
| 65 | else
|
---|
| 66 | return null;
|
---|
| 67 | }
|
---|
[4154] | 68 | }
|
---|
| 69 | public ILookupParameter<DoubleValue> CapacityParameter {
|
---|
[4179] | 70 | get {
|
---|
| 71 | if (Parameters.ContainsKey("Capacity"))
|
---|
| 72 | return (ILookupParameter<DoubleValue>)Parameters["Capacity"];
|
---|
| 73 | else
|
---|
| 74 | return null;
|
---|
| 75 | }
|
---|
[4154] | 76 | }
|
---|
| 77 | public ILookupParameter<DoubleArray> DemandParameter {
|
---|
[4179] | 78 | get {
|
---|
| 79 | if (Parameters.ContainsKey("Demand"))
|
---|
| 80 | return (ILookupParameter<DoubleArray>)Parameters["Demand"];
|
---|
| 81 | else
|
---|
| 82 | return null;
|
---|
| 83 | }
|
---|
[4154] | 84 | }
|
---|
| 85 | public ILookupParameter<DoubleArray> ReadyTimeParameter {
|
---|
[4179] | 86 | get {
|
---|
| 87 | if (Parameters.ContainsKey("ReadyTime"))
|
---|
| 88 | return (ILookupParameter<DoubleArray>)Parameters["ReadyTime"];
|
---|
| 89 | else
|
---|
| 90 | return null;
|
---|
| 91 | }
|
---|
[4154] | 92 | }
|
---|
| 93 | public ILookupParameter<DoubleArray> DueTimeParameter {
|
---|
[4179] | 94 | get {
|
---|
| 95 | if (Parameters.ContainsKey("DueTime"))
|
---|
| 96 | return (ILookupParameter<DoubleArray>)Parameters["DueTime"];
|
---|
| 97 | else
|
---|
| 98 | return null;
|
---|
| 99 | }
|
---|
[4154] | 100 | }
|
---|
| 101 | public ILookupParameter<DoubleArray> ServiceTimeParameter {
|
---|
[4179] | 102 | get {
|
---|
| 103 | if (Parameters.ContainsKey("ServiceTime"))
|
---|
| 104 | return (ILookupParameter<DoubleArray>)Parameters["ServiceTime"];
|
---|
| 105 | else
|
---|
| 106 | return null;
|
---|
| 107 | }
|
---|
[4154] | 108 | }
|
---|
| 109 |
|
---|
[4179] | 110 | [StorableConstructor]
|
---|
| 111 | protected VRPOperator(bool deserializing) : base(deserializing) { }
|
---|
[4722] | 112 | protected VRPOperator(VRPOperator original, Cloner cloner) : base(original, cloner) { }
|
---|
[4154] | 113 | public VRPOperator()
|
---|
| 114 | : base() {
|
---|
| 115 | Parameters.Add(new LookupParameter<DoubleMatrix>("Coordinates", "The coordinates of the cities."));
|
---|
| 116 | Parameters.Add(new LookupParameter<DoubleMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities."));
|
---|
| 117 | Parameters.Add(new LookupParameter<BoolValue>("UseDistanceMatrix", "True if a distance matrix should be calculated and used for evaluation, otherwise false."));
|
---|
| 118 | Parameters.Add(new LookupParameter<IntValue>("Vehicles", "The number of vehicles."));
|
---|
| 119 | Parameters.Add(new LookupParameter<DoubleValue>("Capacity", "The capacity of each vehicle."));
|
---|
| 120 | Parameters.Add(new LookupParameter<DoubleArray>("Demand", "The demand of each customer."));
|
---|
| 121 | Parameters.Add(new LookupParameter<DoubleArray>("ReadyTime", "The ready time of each customer."));
|
---|
| 122 | Parameters.Add(new LookupParameter<DoubleArray>("DueTime", "The due time of each customer."));
|
---|
| 123 | Parameters.Add(new LookupParameter<DoubleArray>("ServiceTime", "The service time of each customer."));
|
---|
| 124 | }
|
---|
[4174] | 125 |
|
---|
| 126 | protected bool Feasible(Tour tour) {
|
---|
| 127 | return tour.Feasible(
|
---|
| 128 | DueTimeParameter.ActualValue,
|
---|
| 129 | ServiceTimeParameter.ActualValue,
|
---|
| 130 | ReadyTimeParameter.ActualValue,
|
---|
| 131 | DemandParameter.ActualValue,
|
---|
| 132 | CapacityParameter.ActualValue,
|
---|
| 133 | CoordinatesParameter.ActualValue,
|
---|
| 134 | DistanceMatrixParameter,
|
---|
| 135 | UseDistanceMatrixParameter.ActualValue);
|
---|
| 136 | }
|
---|
| 137 |
|
---|
[4186] | 138 | protected bool Feasible(IVRPEncoding solution) {
|
---|
| 139 | bool feasible = true;
|
---|
| 140 |
|
---|
[4352] | 141 | foreach (Tour tour in solution.GetTours(DistanceMatrixParameter)) {
|
---|
[4186] | 142 | if (!Feasible(tour)) {
|
---|
| 143 | feasible = false;
|
---|
| 144 | break;
|
---|
| 145 | }
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | return feasible;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
[4174] | 151 | protected double GetLength(Tour tour) {
|
---|
| 152 | return tour.GetLength(
|
---|
| 153 | CoordinatesParameter.ActualValue,
|
---|
| 154 | DistanceMatrixParameter,
|
---|
| 155 | UseDistanceMatrixParameter.ActualValue);
|
---|
| 156 | }
|
---|
[4154] | 157 | }
|
---|
| 158 | }
|
---|