#region License Information /* HeuristicLab * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Encodings.PermutationEncoding; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using System.Collections.Generic; using HeuristicLab.Problems.VehicleRouting.Encodings.General; using HeuristicLab.Problems.VehicleRouting.Interfaces; namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba { [Item("AlbaEncoding", "Represents an Alba encoding of VRP solutions. It is implemented as described in Alba, E. and Dorronsoro, B. (2004). Solving the Vehicle Routing Problem by Using Cellular Genetic Algorithms.")] [StorableClass] public class AlbaEncoding : PermutationEncoding { #region IVRPEncoding Members public override List GetTours() { List result = new List(); int cities = ProblemInstance.Cities.Value; Tour tour = new Tour(); for (int i = 0; i < this.array.Length; i++) { if (this.array[i] >= cities) { if (tour.Stops.Count > 0) { result.Add(tour); tour = new Tour(); } } else { tour.Stops.Add(this.array[i] + 1); } } if (tour.Stops.Count > 0) { result.Add(tour); } return result; } #endregion public override IDeepCloneable Clone(HeuristicLab.Common.Cloner cloner) { AlbaEncoding clone = new AlbaEncoding( new Permutation(this.PermutationType, this.array), (IVRPProblemInstance)cloner.Clone(ProblemInstance)); cloner.RegisterClonedObject(this, clone); clone.readOnly = readOnly; return clone; } public AlbaEncoding(Permutation permutation, IVRPProblemInstance instance) : base(permutation, instance) { } [StorableConstructor] private AlbaEncoding(bool serializing) : base(serializing) { } public static AlbaEncoding ConvertFrom(List routeParam, IVRPProblemInstance instance) { List route = new List(routeParam); route.RemoveAt(routeParam.Count - 1); int cities = 0; for (int i = 0; i < route.Count; i++) { if (route[i] != 0) { cities++; } } int vehicle = cities; for (int i = 0; i < route.Count; i++) { if (route[i] == 0) { route[i] = vehicle; vehicle++; } else { route[i] = route[i] - 1; } } return new AlbaEncoding( new Permutation(PermutationTypes.RelativeUndirected, route.ToArray()), instance); } } }