#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.Encodings.PermutationEncoding; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.VehicleRouting.Encodings.Zhu { [Item("ZhuPermutationCrossover", "An operator which crosses two VRP representations using a standard permutation operator. It is implemented as described in Zhu, K.Q. (2000). A New Genetic Algorithm For VRPTW. Proceedings of the International Conference on Artificial Intelligence.")] [StorableClass] public sealed class PrinsPermutationCrossover : ZhuCrossover { public IValueLookupParameter InnerCrossoverParameter { get { return (IValueLookupParameter)Parameters["InnerCrossover"]; } } [StorableConstructor] private PrinsPermutationCrossover(bool deserializing) : base(deserializing) { } private PrinsPermutationCrossover(PrinsPermutationCrossover original, Cloner cloner) : base(original, cloner) { } public override IDeepCloneable Clone(Cloner cloner) { return new PrinsPermutationCrossover(this, cloner); } public PrinsPermutationCrossover() : base() { Parameters.Add(new ValueLookupParameter("InnerCrossover", "The permutation crossover.", new PartiallyMatchedCrossover())); } protected override ZhuEncoding Crossover(IExecutionContext context, IRandom random, ZhuEncoding parent1, ZhuEncoding parent2) { //note - the inner crossover is called here and the result is converted to a prins representation //some refactoring should be done here in the future - the crossover operation should be called directly InnerCrossoverParameter.ActualValue.ParentsParameter.ActualName = ParentsParameter.ActualName; IAtomicOperation op = context.CreateOperation( InnerCrossoverParameter.ActualValue, context.Scope); op.Operator.Execute((IExecutionContext)op); string childName = InnerCrossoverParameter.ActualValue.ChildParameter.ActualName; if (context.Scope.Variables.ContainsKey(childName)) { Permutation permutation = context.Scope.Variables[childName].Value as Permutation; context.Scope.Variables.Remove(childName); return new ZhuEncoding(permutation, Cities, DueTimeParameter.ActualValue, ServiceTimeParameter.ActualValue, ReadyTimeParameter.ActualValue, DemandParameter.ActualValue, CapacityParameter.ActualValue, CoordinatesParameter.ActualValue, UseDistanceMatrixParameter.ActualValue); } else return null; } } }