using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Encodings.PermutationEncoding; using HeuristicLab.Optimization; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.PluginInfrastructure; using HeuristicLab.Problems.BinPacking; namespace HeuristicLab.Encodings.PackingEncoding.PackingSequence { [StorableClass] public class Encoding : HeuristicLab.Optimization.Encoding { [StorableConstructor] private Encoding(bool deserializing) : base(deserializing) { } public Encoding() : base("PackingSequence") { SolutionCreator = new PackingSequenceRandomCreator(); RegisterParameterEvents(); DiscoverOperators(); } private Encoding(Encoding original, Cloner cloner) : base(original, cloner) { RegisterParameterEvents(); } public override IDeepCloneable Clone(Cloner cloner) { return new Encoding(this, cloner); } public override void ConfigureOperators(IEnumerable operators) { // TODO } #region Operator discovery private static readonly IEnumerable encodingSpecificOperatorTypes; static Encoding() { encodingSpecificOperatorTypes = new List { typeof(IPackingSequenceOperator), // TODO move (also namespace) }; } private void DiscoverOperators() { var assembly = typeof(IPackingSequenceCreator).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(); ConfigureOperators(newOperators); foreach (var @operator in newOperators) AddOperator(@operator); } #endregion private void RegisterParameterEvents() { // nothing to do } } public static class IndividualExtensionMethods { public static Permutation PackingSequence(this Individual individual) { var encoding = individual.GetEncoding(); return individual.PackingSequence(encoding.Name); } public static Permutation PackingSequence(this Individual individual, string name) { return (Permutation)individual[name]; } } }