#region License Information /* HeuristicLab * Copyright (C) 2002-2019 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.Linq; using HEAL.Attic; using HeuristicLab.Analysis; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Optimization; namespace HeuristicLab.Encodings.PermutationEncoding { [StorableType("7bc5215b-c181-40d0-a758-d7c19a356e18")] public abstract class PermutationMultiObjectiveProblem : MultiObjectiveProblem { public int Length { get { return Encoding.Length; } set { Encoding.Length = value; } } public PermutationTypes Type { get { return Encoding.Type; } set { Encoding.Type = value; } } [StorableConstructor] protected PermutationMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { } [StorableHook(HookType.AfterDeserialization)] private void AfterDeserialization() { RegisterEventHandlers(); } protected PermutationMultiObjectiveProblem(PermutationMultiObjectiveProblem original, Cloner cloner) : base(original, cloner) { RegisterEventHandlers(); } protected PermutationMultiObjectiveProblem() : this(new PermutationEncoding() { Length = 10, Type = PermutationTypes.Absolute }) { } protected PermutationMultiObjectiveProblem(PermutationEncoding encoding) : base(encoding) { EncodingParameter.ReadOnly = true; Operators.Add(new HammingSimilarityCalculator()); Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType())); Parameterize(); RegisterEventHandlers(); } public override void Analyze(Permutation[] individuals, double[][] qualities, ResultCollection results, IRandom random) { base.Analyze(individuals, qualities, results, random); // TODO: Calculate Pareto front and add to results } protected override void OnEncodingChanged() { base.OnEncodingChanged(); Parameterize(); } private void Parameterize() { foreach (var similarityCalculator in Operators.OfType()) { similarityCalculator.SolutionVariableName = Encoding.Name; similarityCalculator.QualityVariableName = Evaluator.QualitiesParameter.ActualName; } } private void RegisterEventHandlers() { Encoding.LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged; Encoding.PermutationTypeParameter.Value.ValueChanged += TypeParameter_ValueChanged; } protected virtual void LengthParameter_ValueChanged(object sender, EventArgs e) { } protected virtual void TypeParameter_ValueChanged(object sender, EventArgs e) { } } }