1  #region License Information


2  /* HeuristicLab


3  * Copyright (C) 20022010 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.Collections.Generic;


28  using HeuristicLab.Problems.VehicleRouting.Encodings.General;


29  using HeuristicLab.Problems.VehicleRouting.Interfaces;


30 


31  namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {


32  [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.")]


33  [StorableClass]


34  public class AlbaEncoding : PermutationEncoding {


35  #region IVRPEncoding Members


36  public override List<Tour> GetTours() {


37  List<Tour> result = new List<Tour>();


38 


39  int cities = ProblemInstance.Cities.Value;


40 


41  Tour tour = new Tour();


42  for (int i = 0; i < this.array.Length; i++) {


43  if (this.array[i] >= cities) {


44  if (tour.Stops.Count > 0) {


45  result.Add(tour);


46 


47  tour = new Tour();


48  }


49  } else {


50  tour.Stops.Add(this.array[i] + 1);


51  }


52  }


53 


54  if (tour.Stops.Count > 0) {


55  result.Add(tour);


56  }


57 


58  return result;


59  }


60  #endregion


61 


62  public override IDeepCloneable Clone(HeuristicLab.Common.Cloner cloner) {


63  AlbaEncoding clone = new AlbaEncoding(


64  new Permutation(this.PermutationType, this.array),


65  (IVRPProblemInstance)cloner.Clone(ProblemInstance));


66  cloner.RegisterClonedObject(this, clone);


67  clone.readOnly = readOnly;


68  return clone;


69  }


70 


71  public AlbaEncoding(Permutation permutation, IVRPProblemInstance instance)


72  : base(permutation, instance) {


73  }


74 


75  [StorableConstructor]


76  private AlbaEncoding(bool serializing)


77  : base(serializing) {


78  }


79 


80  public static AlbaEncoding ConvertFrom(List<int> routeParam, IVRPProblemInstance instance) {


81  List<int> route = new List<int>(routeParam);


82  route.RemoveAt(routeParam.Count  1);


83 


84  int cities = 0;


85  for (int i = 0; i < route.Count; i++) {


86  if (route[i] != 0) {


87  cities++;


88  }


89  }


90 


91  int vehicle = cities;


92  for (int i = 0; i < route.Count; i++) {


93  if (route[i] == 0) {


94  route[i] = vehicle;


95  vehicle++;


96  } else {


97  route[i] = route[i]  1;


98  }


99  }


100 


101  return new AlbaEncoding(


102  new Permutation(PermutationTypes.RelativeUndirected, route.ToArray()),


103  instance);


104  }


105  }


106  }

