[3938] | 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 |
|
---|
[4068] | 22 | using HeuristicLab.Core;
|
---|
[3938] | 23 | using HeuristicLab.Data;
|
---|
[4174] | 24 | using System.Collections.Generic;
|
---|
| 25 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 26 | using HeuristicLab.Common;
|
---|
[3938] | 27 |
|
---|
| 28 | namespace HeuristicLab.Problems.VehicleRouting.Encodings {
|
---|
[4174] | 29 | [StorableClass]
|
---|
| 30 | public class Tour : Item {
|
---|
| 31 | [Storable]
|
---|
| 32 | public List<int> Cities { get; private set; }
|
---|
| 33 |
|
---|
| 34 | public Tour() {
|
---|
| 35 | Cities = new List<int>();
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 39 | Tour clone = base.Clone(cloner) as Tour;
|
---|
| 40 | clone.Cities = new List<int>(Cities);
|
---|
| 41 |
|
---|
| 42 | return clone;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | public bool Feasible(DoubleArray dueTimeArray,
|
---|
| 46 | DoubleArray serviceTimeArray, DoubleArray readyTimeArray, DoubleArray demandArray, DoubleValue capacity,
|
---|
| 47 | DoubleMatrix coordinates, ILookupParameter<DoubleMatrix> distanceMatrix, BoolValue useDistanceMatrix) {
|
---|
| 48 | TourEvaluation eval = VRPEvaluator.EvaluateTour(this,
|
---|
| 49 | dueTimeArray,
|
---|
| 50 | serviceTimeArray,
|
---|
| 51 | readyTimeArray,
|
---|
| 52 | demandArray,
|
---|
| 53 | capacity,
|
---|
| 54 | new DoubleValue(0),
|
---|
| 55 | new DoubleValue(0),
|
---|
| 56 | new DoubleValue(0),
|
---|
| 57 | new DoubleValue(1),
|
---|
| 58 | new DoubleValue(1),
|
---|
| 59 | coordinates,
|
---|
| 60 | distanceMatrix,
|
---|
| 61 | useDistanceMatrix);
|
---|
| 62 |
|
---|
| 63 | return eval.Overload < double.Epsilon && eval.Tardiness < double.Epsilon;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | public double GetLength(DoubleMatrix coordinates,
|
---|
| 67 | ILookupParameter<DoubleMatrix> distanceMatrix,
|
---|
| 68 | BoolValue useDistanceMatrix) {
|
---|
| 69 | double length = 0;
|
---|
| 70 |
|
---|
| 71 | if (Cities.Count > 0) {
|
---|
| 72 | List<int> cities = new List<int>();
|
---|
| 73 | cities.Add(0);
|
---|
| 74 | foreach (int city in Cities) {
|
---|
| 75 | cities.Add(city);
|
---|
| 76 | }
|
---|
| 77 | cities.Add(0);
|
---|
| 78 |
|
---|
| 79 | for (int i = 1; i < cities.Count; i++) {
|
---|
| 80 | length += VRPUtilities.GetDistance(
|
---|
| 81 | cities[i - 1], cities[i], coordinates, distanceMatrix, useDistanceMatrix);
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | return length;
|
---|
| 86 | }
|
---|
[3938] | 87 | }
|
---|
| 88 | }
|
---|