Free cookie consent management tool by TermsFeed Policy Generator

# Changeset 17309

Ignore:
Timestamp:
10/03/19 17:43:11 (4 years ago)
Message:

#2521: Refactored maximization property for multi-objective problems

Location:
branches/2521_ProblemRefactoring
Files:
16 edited

Unmodified
Removed
• ## branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/Indicators/HypervolumeIndicator.cs

 r17226 using HeuristicLab.Core; using HeuristicLab.Optimization; using HeuristicLab.Problems.TestFunctions.MultiObjective; namespace HeuristicLab.Algorithms.MOCMAEvolutionStrategy { #region Helpers private static double Contribution(IList front, int idx, bool[] maximization, double[] refPoint) { private static double Contribution(IList front, int idx, IReadOnlyList maximization, double[] refPoint) { var point = front[idx]; front.RemoveAt(idx);
• ## branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/MOCMAEvolutionStrategy.cs

 r17261 var bkf = problem.BestKnownFront == null ? null : problem.BestKnownFront.ToArray(); if (bkf != null && problem.ReferencePoint != null) { ResultsBestKnownHypervolume = HypervolumeCalculator.CalculateHypervolume(bkf, problem.ReferencePoint, Problem.Maximization); ResultsBestKnownHypervolume = HypervolumeCalculator.CalculateHypervolume(bkf, problem.ReferencePoint, Problem.Maximization.CloneAsArray()); ResultsDifferenceBestKnownHypervolume = ResultsBestKnownHypervolume; } //perform a non-dominated sort to assign the rank to every element int[] ranks; var fronts = DominationCalculator.CalculateAllParetoFronts(parents.ToArray(), parents.Select(i => i.PenalizedFitness).ToArray(), Problem.Maximization, out ranks); var fronts = DominationCalculator.CalculateAllParetoFronts(parents.ToArray(), parents.Select(i => i.PenalizedFitness).ToArray(), Problem.Maximization.CloneAsArray(), out ranks); //deselect the highest rank fronts until we would end up with less or equal mu elements
• ## branches/2521_ProblemRefactoring/HeuristicLab.Data/3.3/BoolArray.cs

 r17253 #endregion using System.Collections.Generic; using System.Text; using HEAL.Attic; public BoolArray(int length) : base(length) { } public BoolArray(bool[] elements, bool @readonly = false) : base(elements, @readonly) { } public BoolArray(IReadOnlyList elements) : base(elements) { } public override IDeepCloneable Clone(Cloner cloner) {
• ## branches/2521_ProblemRefactoring/HeuristicLab.Data/3.3/StringConvertibleArray.cs

 r17253 #endregion using System.Collections.Generic; using HEAL.Attic; using HeuristicLab.Common; protected StringConvertibleArray(int length) : base(length) { } protected StringConvertibleArray(T[] elements, bool @readonly = false) : base(elements, @readonly) { } protected StringConvertibleArray(IReadOnlyList elements) : base(elements) { } protected abstract bool Validate(string value, out string errorMessage);
• ## branches/2521_ProblemRefactoring/HeuristicLab.Data/3.3/ValueTypeArray.cs

 r17253 } protected ValueTypeArray(T[] elements, bool @readonly = false) { if (elements == null) throw new ArgumentNullException(); if (elements == null) throw new ArgumentNullException(nameof(elements)); array = (T[])elements.Clone(); readOnly = @readonly; resizable = true; elementNames = new List(); } protected ValueTypeArray(IReadOnlyList elements) { if (elements == null) throw new ArgumentNullException(nameof(elements)); array = elements.ToArray(); // TODO: array should be an IList readOnly = true; resizable = true; // TODO: really? elementNames = new List(); // TODO: wasteful }
• ## branches/2521_ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeMultiObjectiveProblem.cs

 r17230 base.Analyze(trees, qualities, results, random); var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(trees, qualities, Maximization); var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(trees, qualities, Maximization.CloneAsArray()); var plot = new ParetoFrontScatterPlot(fronts, trees, qualities, Objectives, BestKnownFront); results.AddOrUpdateResult("Pareto Front Scatter Plot", plot);
• ## branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IMultiObjectiveProblemDefinition.cs

 r17257 public interface IMultiObjectiveProblemDefinition { int Objectives { get; } bool[] Maximization { get; } IReadOnlyList Maximization { get; } IReadOnlyList BestKnownFront { get; } double[] ReferencePoint { get; }

• ## branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/MultiObjective/DominationCalculator.cs

 r17230 /// Whether solutions of exactly equal quality should dominate one another. /// The pareto front containing the best solutions and their associated quality resp. fitness. public static List> CalculateBestParetoFront(T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities = true) { public static List> CalculateBestParetoFront(T[] solutions, double[][] qualities, IReadOnlyList maximization, bool dominateOnEqualQualities = true) { var populationSize = solutions.Length; Dictionary> dominatedIndividuals; /// Whether solutions of exactly equal quality should dominate one another. /// A sorted list of the pareto fronts from best to worst. public static List>> CalculateAllParetoFronts(T[] solutions, double[][] qualities, bool[] maximization, out int[] rank, bool dominateOnEqualQualities = true) { public static List>> CalculateAllParetoFronts(T[] solutions, double[][] qualities, IReadOnlyList maximization, out int[] rank, bool dominateOnEqualQualities = true) { var populationSize = solutions.Length; } private static List> CalculateBestFront(T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities, int populationSize, out Dictionary> dominatedIndividuals, out int[] dominationCounter, out int[] rank) { private static List> CalculateBestFront(T[] solutions, double[][] qualities, IReadOnlyList maximization, bool dominateOnEqualQualities, int populationSize, out Dictionary> dominatedIndividuals, out int[] dominationCounter, out int[] rank) { var front = new List>(); dominatedIndividuals = new Dictionary>(); /// Whether solutions of exactly equal quality should dominate one another. /// A sorted list of the pareto fronts where each front contains the indices of the and . public static List> CalculateAllParetoFrontsIndices(T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities = true) { public static List> CalculateAllParetoFrontsIndices(T[] solutions, double[][] qualities, IReadOnlyList maximization, bool dominateOnEqualQualities = true) { return CalculateAllParetoFrontsIndices(solutions, qualities, maximization, out var rank, dominateOnEqualQualities); } /// Whether solutions of exactly equal quality should dominate one another. /// A sorted list of the pareto fronts where each front contains the indices of the and . public static List> CalculateAllParetoFrontsIndices(T[] solutions, double[][] qualities, bool[] maximization, out int[] rank, bool dominateOnEqualQualities = true) { public static List> CalculateAllParetoFrontsIndices(T[] solutions, double[][] qualities, IReadOnlyList maximization, out int[] rank, bool dominateOnEqualQualities = true) { var populationSize = solutions.Length; } private static List CalculateBestFrontIndices(T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities, int populationSize, List[] dominatedIndividuals, int[] dominationCounter, int[] rank) { private static List CalculateBestFrontIndices(T[] solutions, double[][] qualities, IReadOnlyList maximization, bool dominateOnEqualQualities, int populationSize, List[] dominatedIndividuals, int[] dominationCounter, int[] rank) { var front = new List(); for (var pI = 0; pI < populationSize - 1; pI++) { /// Whether the result should be Dominates in case both fitness vectors are exactly equal /// Dominates if left dominates right, IsDominated if right dominates left and IsNonDominated otherwise. public static DominationResult Dominates(double[] left, double[] right, bool[] maximizations, bool dominateOnEqualQualities) { public static DominationResult Dominates(double[] left, double[] right, IReadOnlyList maximizations, bool dominateOnEqualQualities) { //mkommend Caution: do not use LINQ.SequenceEqual for comparing the two quality arrays (left and right) due to performance reasons if (dominateOnEqualQualities) {
• ## branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/MultiObjective/HypervolumeCalculator.cs

 r17225 namespace HeuristicLab.Optimization { public static class HypervolumeCalculator { public static double[] CalculateNadirPoint(IEnumerable qualities, bool[] maximization) { public static double[] CalculateNadirPoint(IEnumerable qualities, IReadOnlyList maximization) { var res = maximization.Select(m => m ? double.MaxValue : double.MinValue).ToArray(); foreach (var quality in qualities) /// /// public static double CalculateHypervolume(IList qualities, double[] referencePoint, bool[] maximization) { public static double CalculateHypervolume(IList qualities, double[] referencePoint, IReadOnlyList maximization) { qualities = qualities.Where(vec => DominationCalculator.Dominates(vec, referencePoint, maximization, false) == DominationResult.Dominates).ToArray(); if (qualities.Count== 0) return 0; //TODO computation for negative hypervolume? if (maximization.Length == 2) if (maximization.Count == 2) return Calculate2D(qualities, referencePoint, maximization); if (Array.TrueForAll(maximization, x => !x)) if (maximization.All(x => !x)) return CalculateMultiDimensional(qualities, referencePoint); throw new NotImplementedException("HypervolumeCalculator calculation for more than two dimensions is supported only with minimization problems."); /// /// public static double Calculate2D(IList front, double[] referencePoint, bool[] maximization) { public static double Calculate2D(IList front, double[] referencePoint, IReadOnlyList maximization) { if (front == null) throw new ArgumentNullException("front"); if (referencePoint == null) throw new ArgumentNullException("referencePoint");
• ## branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/MultiObjectiveExternalEvaluationProblem.cs

 r17226 public MultiObjectiveExternalEvaluationProblem(TEncoding encoding) : base(encoding) { Parameters.Remove("Maximization"); // readonly in base class Parameters.Add(new FixedValueParameter("Maximization", "Set to false if the problem should be minimized.", new BoolArray())); MaximizationParameter.ReadOnly = false; MaximizationParameter.Value = new BoolArray(new [] { false, false }); Parameters.Add(new OptionalValueParameter("Cache", "Cache of previously evaluated solutions.")); Parameters.Add(new ValueParameter>("Clients", "The clients that are used to communicate with the external application.", new CheckedItemCollection() { new EvaluationServiceClient() })); #region Multi Objective Problem Overrides public override bool[] Maximization { get { return Parameters.ContainsKey("Maximization") ? ((IValueParameter)Parameters["Maximization"]).Value.ToArray() : new bool[0]; } } public virtual void SetMaximization(bool[] maximization) { ((IStringConvertibleArray)MaximizationParameter.Value).Length = maximization.Length;
• ## branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/CompiledProblemDefinition.cs

 r17226 using System.Collections.Generic; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Optimization; #region ISingleObjectiveProblemDefinition Members public int Objectives => Maximization.Length; public abstract bool[] Maximization { get; } public int Objectives => Maximization.Count; public abstract IReadOnlyList Maximization { get; } public abstract IReadOnlyList BestKnownFront { get; } public abstract double[] ReferencePoint { get; }
• ## branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProblemDefinitionScript.cs

 r17226 using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Optimization; public IReadOnlyList BestKnownFront => CompiledProblemDefinition.BestKnownFront; public double[] ReferencePoint => CompiledProblemDefinition.ReferencePoint; public bool[] Maximization => CompiledProblemDefinition.Maximization; public IReadOnlyList Maximization => CompiledProblemDefinition.Maximization;
• ## branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProgrammableProblem.cs

 r17226 private void OnProblemDefinitionChanged() { Parameters.Remove("Maximization"); Parameters.Add(new ValueParameter("Maximization", "Set to false if the problem should be minimized.", (BoolArray)new BoolArray(Maximization).AsReadOnly()) {Hidden = true}); Maximization = new BoolArray(ProblemDefinition.Maximization); Encoding = (TEncoding)ProblemScript.Encoding.Clone(); private void OnProblemScriptNameChanged() { Name = ProblemScript.Name; } public override bool[] Maximization { get { return Parameters.ContainsKey("ProblemScript") ? ProblemDefinition.Maximization : new[] {false}; } }
• ## branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/MultiObjectiveCombinedEncodingProblem_Template.cs

 r17225 namespace HeuristicLab.Problems.Programmable { public class CompiledMultiObjectiveProblemDefinition : CompiledMultiObjectiveProblemDefinition { public override bool[] Maximization { get { return new[] { true, false }; } } public override IReadOnlyList Maximization { get { return new[] { true, false }; } } public override double[] ReferencePoint { get { return null; } } public override IReadOnlyList BestKnownFront { get { return null; } }
• ## branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/MultiObjectiveTestFunctionProblem.cs

 r17261 #endregion using System; using System.Linq; using HEAL.Attic; using HeuristicLab.Analysis; #region Properties public override bool[] Maximization { get { //necessary because of virtual member call in base ctor if (!Parameters.ContainsKey("TestFunction")) return new bool[0]; return TestFunction.Maximization(Objectives).ToArray(); } } public int ProblemSize { get { return ProblemSizeParameter.Value.Value; } #region Events private void UpdateParameterValues() { Parameters.Remove(MaximizationParameterName); Parameters.Add(new FixedValueParameter(MaximizationParameterName, "Set to false if the problem should be minimized.", (BoolArray)new BoolArray(TestFunction.Maximization(Objectives)).AsReadOnly())); Maximization = new BoolArray(TestFunction.Maximization(Objectives)); Parameters.Remove(BestKnownFrontParameterName);
Note: See TracChangeset for help on using the changeset viewer.