#region License Information /* HeuristicLab * Copyright (C) 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 System; using System.Collections.Generic; using System.Linq; using HEAL.Attic; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Optimization; using HeuristicLab.PluginInfrastructure; using HeuristicLab.Problems.VehicleRouting.Interfaces; namespace HeuristicLab.Problems.VehicleRouting.Encodings.GVR { [Item("GVR Encoding", "Represents the genetic vehicle representation encoding for GVR encoded solutions.")] [StorableType("9ff9f959-31d2-44e5-8a5e-b122220535c2")] public class GVREncoding : Encoding, IVRPEncoding { [StorableConstructor] private GVREncoding(StorableConstructorFlag _) : base(_) { } [StorableHook(HookType.AfterDeserialization)] private void AfterDeserialization() { DiscoverOperators(); } public override IDeepCloneable Clone(Cloner cloner) { return new GVREncoding(this, cloner); } private GVREncoding(GVREncoding original, Cloner cloner) : base(original, cloner) { } public GVREncoding() : this("VRPTours") { } public GVREncoding(string name) : base(name) { DiscoverOperators(); } #region Operator Discovery private static readonly IEnumerable encodingSpecificOperatorTypes; static GVREncoding() { encodingSpecificOperatorTypes = new List() { typeof (IGVROperator), typeof (IVRPCreator), typeof (IMultiVRPOperator) }; } private void DiscoverOperators() { var assembly = typeof(IGVROperator).Assembly; var discoveredTypes = ApplicationManager.Manager.GetTypes(encodingSpecificOperatorTypes, assembly, true, false, false); var operators = discoveredTypes.Select(t => (IOperator)Activator.CreateInstance(t)); var newOperators = operators.Except(Operators, new TypeEqualityComparer()).ToList(); foreach (var op in newOperators.OfType().ToList()) { op.SetOperators(Operators.Concat(newOperators)); if (!op.Operators.Any()) newOperators.Remove(op); } foreach (var op in Operators.OfType()) { op.SetOperators(newOperators); } ConfigureOperators(newOperators); foreach (var @operator in newOperators) AddOperator(@operator); } #endregion public override void ConfigureOperators(IEnumerable operators) { base.ConfigureOperators(operators); } #region specific operator wiring #endregion } }