#region License Information
/* HeuristicLab
* Copyright (C) 2002-2011 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.Encodings.PermutationEncoding;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
[Item("AlbaPermutationCrossover", "An operator which crosses two VRP representations using a standard permutation operator. It is implemented as described in Alba, E. and Dorronsoro, B. (2004). Solving the Vehicle Routing Problem by Using Cellular Genetic Algorithms.")]
[StorableClass]
public sealed class AlbaPermutationCrossover : AlbaCrossover {
public IValueLookupParameter InnerCrossoverParameter {
get { return (IValueLookupParameter)Parameters["InnerCrossover"]; }
}
[StorableConstructor]
private AlbaPermutationCrossover(bool deserializing) : base(deserializing) { }
private AlbaPermutationCrossover(AlbaPermutationCrossover original, Cloner cloner)
: base(original, cloner) {
}
public override IDeepCloneable Clone(Cloner cloner) {
return new AlbaPermutationCrossover(this, cloner);
}
public AlbaPermutationCrossover()
: base() {
Parameters.Add(new ValueLookupParameter("InnerCrossover", "The permutation crossover.", new EdgeRecombinationCrossover()));
}
protected override AlbaEncoding Crossover(IRandom random, AlbaEncoding parent1, AlbaEncoding parent2) {
//note - the inner crossover is called here and the solution is converted to an alba representation
//some refactoring should be done here in the future - the crossover operation should be called directly
if (parent1.Length == parent2.Length) {
InnerCrossoverParameter.ActualValue.ParentsParameter.ActualName = ParentsParameter.ActualName;
IAtomicOperation op = this.ExecutionContext.CreateOperation(
InnerCrossoverParameter.ActualValue, this.ExecutionContext.Scope);
op.Operator.Execute((IExecutionContext)op, CancellationToken);
string childName = InnerCrossoverParameter.ActualValue.ChildParameter.ActualName;
if (ExecutionContext.Scope.Variables.ContainsKey(childName)) {
Permutation permutation = ExecutionContext.Scope.Variables[childName].Value as Permutation;
ExecutionContext.Scope.Variables.Remove(childName);
return new AlbaEncoding(permutation, Cities);
} else
return null;
} else {
return parent1.Clone() as AlbaEncoding;
}
}
}
}