[4150] | 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 HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
| 26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 27 | using System.Drawing;
|
---|
| 28 | using System.Collections.Generic;
|
---|
[4352] | 29 | using HeuristicLab.Problems.VehicleRouting.Encodings.General;
|
---|
[4150] | 30 |
|
---|
| 31 | namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
|
---|
[4177] | 32 | [Item("PotvinEncoding", "Represents a potvin encoding of VRP solutions. It is implemented as described in Potvin, J.-Y. and Bengio, S. (1996). The Vehicle Routing Problem with Time Windows - Part II: Genetic Search. INFORMS Journal of Computing, 8:165–172.")]
|
---|
[4150] | 33 | [StorableClass]
|
---|
[4352] | 34 | public class PotvinEncoding : TourEncoding {
|
---|
[4150] | 35 | [Storable]
|
---|
[4174] | 36 | public List<int> Unrouted { get; set; }
|
---|
[4150] | 37 |
|
---|
| 38 | public override IDeepCloneable Clone(HeuristicLab.Common.Cloner cloner) {
|
---|
| 39 | PotvinEncoding clone = new PotvinEncoding();
|
---|
| 40 | cloner.RegisterClonedObject(this, clone);
|
---|
| 41 | clone.Tours = (ItemList<Tour>)cloner.Clone(this.Tours);
|
---|
[4174] | 42 | clone.Unrouted = new List<int>(Unrouted);
|
---|
[4150] | 43 | return clone;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[4352] | 46 | public PotvinEncoding(): base() {
|
---|
[4174] | 47 | Unrouted = new List<int>();
|
---|
[4150] | 48 | }
|
---|
[4352] | 49 |
|
---|
| 50 | [StorableConstructor]
|
---|
| 51 | private PotvinEncoding(bool serializing)
|
---|
| 52 | : base() {
|
---|
| 53 | }
|
---|
[4150] | 54 |
|
---|
[4352] | 55 | public static PotvinEncoding ConvertFrom(IVRPEncoding encoding, ILookupParameter<DoubleMatrix> distanceMatrix) {
|
---|
[4150] | 56 | PotvinEncoding solution = new PotvinEncoding();
|
---|
| 57 |
|
---|
[4352] | 58 | TourEncoding.ConvertFrom(encoding, solution, distanceMatrix);
|
---|
[4150] | 59 |
|
---|
| 60 | return solution;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | public static PotvinEncoding ConvertFrom(List<int> route) {
|
---|
| 64 | PotvinEncoding solution = new PotvinEncoding();
|
---|
| 65 |
|
---|
[4352] | 66 | TourEncoding.ConvertFrom(route, solution);
|
---|
[4150] | 67 |
|
---|
| 68 | return solution;
|
---|
| 69 | }
|
---|
[4174] | 70 |
|
---|
| 71 | public bool FindInsertionPlace(
|
---|
| 72 | DoubleArray dueTimeArray,
|
---|
| 73 | DoubleArray serviceTimeArray, DoubleArray readyTimeArray, DoubleArray demandArray, DoubleValue capacity,
|
---|
| 74 | DoubleMatrix coordinates, ILookupParameter<DoubleMatrix> distanceMatrix, BoolValue useDistanceMatrix,
|
---|
| 75 | int city, int routeToAvoid, out int route, out int place) {
|
---|
| 76 | route = -1;
|
---|
| 77 | place = -1;
|
---|
| 78 | double minDetour = 0;
|
---|
| 79 |
|
---|
| 80 | for (int tour = 0; tour < Tours.Count; tour++) {
|
---|
| 81 | if (tour != routeToAvoid) {
|
---|
| 82 | for (int i = 0; i <= Tours[tour].Cities.Count; i++) {
|
---|
| 83 | double length = Tours[tour].GetLength(coordinates, distanceMatrix, useDistanceMatrix);
|
---|
| 84 |
|
---|
| 85 | Tours[tour].Cities.Insert(i, city);
|
---|
| 86 |
|
---|
| 87 | if (Tours[tour].Feasible(dueTimeArray, serviceTimeArray, readyTimeArray, demandArray,
|
---|
| 88 | capacity, coordinates, distanceMatrix, useDistanceMatrix)) {
|
---|
[4352] | 89 | double newLength = Tours[tour].GetLength(coordinates, distanceMatrix, useDistanceMatrix);
|
---|
[4174] | 90 |
|
---|
| 91 | double detour = newLength - length;
|
---|
| 92 |
|
---|
| 93 | if (route <= 0 || detour < minDetour) {
|
---|
| 94 | route = tour;
|
---|
| 95 | place = i;
|
---|
| 96 | minDetour = detour;
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | Tours[tour].Cities.RemoveAt(i);
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | return route >= 0 && place >= 0;
|
---|
| 106 | }
|
---|
[4150] | 107 | }
|
---|
| 108 | }
|
---|