Index: unk/sources/HeuristicLab.Algorithms.NSGA2/3.3/BasicMultiObjectiveQualityAnalyzer.cs
===================================================================
--- /trunk/sources/HeuristicLab.Algorithms.NSGA2/3.3/BasicMultiObjectiveQualityAnalyzer.cs (revision 13166)
+++ (revision )
@@ -1,98 +1,0 @@
-#region License Information
-/* HeuristicLab
- * Copyright (C) 2002-2015 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 System.Text;
-using HeuristicLab.Operators;
-using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
-using HeuristicLab.Core;
-using HeuristicLab.Data;
-using HeuristicLab.Optimization;
-using HeuristicLab.Parameters;
-using HeuristicLab.Common;
-
-namespace HeuristicLab.Algorithms.NSGA2 {
- [Item("BasicMultiObjectiveSolutionAnalyzer", "Basic analyzer for multiobjective problems that collects and presents the current pareto front as double matrix.")]
- [StorableClass]
- public class BasicMultiObjectiveQualityAnalyzer : SingleSuccessorOperator, IAnalyzer {
- public IScopeTreeLookupParameter RankParameter {
- get { return (IScopeTreeLookupParameter)Parameters["Rank"]; }
- }
- public IScopeTreeLookupParameter QualitiesParameter {
- get { return (IScopeTreeLookupParameter)Parameters["Qualities"]; }
- }
- public ILookupParameter ResultsParameter {
- get { return (ILookupParameter)Parameters["Results"]; }
- }
-
- [StorableConstructor]
- protected BasicMultiObjectiveQualityAnalyzer(bool deserializing) : base(deserializing) { }
- protected BasicMultiObjectiveQualityAnalyzer(BasicMultiObjectiveQualityAnalyzer original, Cloner cloner) : base(original, cloner) { }
- public BasicMultiObjectiveQualityAnalyzer() {
- Parameters.Add(new ScopeTreeLookupParameter("Rank", "The rank of solution describes to which front it belongs."));
- Parameters.Add(new ScopeTreeLookupParameter("Qualities", "The vector of qualities of each solution."));
- Parameters.Add(new LookupParameter("Results", "The result collection to store the front to."));
- }
-
- public override IOperation Apply() {
- ItemArray ranks = RankParameter.ActualValue;
- ItemArray qualities = QualitiesParameter.ActualValue;
- ResultCollection results = ResultsParameter.ActualValue;
-
- bool populationLevel = RankParameter.Depth == 1;
-
- int objectives = qualities[0].Length;
- int frontSize = ranks.Count(x => x.Value == 0);
- ItemArray paretoArchive = null;
- if (populationLevel) paretoArchive = new ItemArray(frontSize);
-
- DoubleMatrix front = new DoubleMatrix(frontSize, objectives);
- int counter = 0;
- for (int i = 0; i < ranks.Length; i++) {
- if (ranks[i].Value == 0) {
- for (int k = 0; k < objectives; k++)
- front[counter, k] = qualities[i][k];
- if (populationLevel) {
- paretoArchive[counter] = (IScope)ExecutionContext.Scope.SubScopes[i].Clone();
- }
- counter++;
- }
- }
-
- if (results.ContainsKey("Pareto Front"))
- results["Pareto Front"].Value = front;
- else results.Add(new Result("Pareto Front", front));
-
- if (populationLevel) {
- if (results.ContainsKey("Pareto Archive"))
- results["Pareto Archive"].Value = paretoArchive;
- else results.Add(new Result("Pareto Archive", paretoArchive));
- }
- return base.Apply();
- }
-
- public override IDeepCloneable Clone(Cloner cloner) {
- return new BasicMultiObjectiveQualityAnalyzer(this, cloner);
- }
- }
-}
Index: unk/sources/HeuristicLab.Algorithms.NSGA2/3.3/CrowdedComparisonSorter.cs
===================================================================
--- /trunk/sources/HeuristicLab.Algorithms.NSGA2/3.3/CrowdedComparisonSorter.cs (revision 13166)
+++ (revision )
@@ -1,99 +1,0 @@
-#region License Information
-/* HeuristicLab
- * Copyright (C) 2002-2015 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 HeuristicLab.Core;
-using HeuristicLab.Data;
-using HeuristicLab.Operators;
-using HeuristicLab.Parameters;
-using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
-using HeuristicLab.Common;
-
-namespace HeuristicLab.Algorithms.NSGA2 {
- ///
- /// CrowdedComparisonSorter as described in: Deb, Pratap, Agrawal and Meyarivan, "A Fast and Elitist Multiobjective
- /// Genetic Algorithm: NSGA-II", IEEE Transactions On Evolutionary Computation, Vol. 6, No. 2, April 2002
- ///
- [Item("CrowdedComparisonSorter", @"CrowdedComparisonSorter as described in: Deb, Pratap, Agrawal and Meyarivan, ""A Fast and Elitist Multiobjective
-Genetic Algorithm: NSGA-II"", IEEE Transactions On Evolutionary Computation, Vol. 6, No. 2, April 2002.")]
- [StorableClass]
- public class CrowdedComparisonSorter : SingleSuccessorOperator {
-
- public IScopeTreeLookupParameter RankParameter {
- get { return (IScopeTreeLookupParameter)Parameters["Rank"]; }
- }
-
- public IScopeTreeLookupParameter CrowdingDistanceParameter {
- get { return (IScopeTreeLookupParameter)Parameters["CrowdingDistance"]; }
- }
-
- [StorableConstructor]
- protected CrowdedComparisonSorter(bool deserializing) : base(deserializing) { }
- protected CrowdedComparisonSorter(CrowdedComparisonSorter original, Cloner cloner) : base(original, cloner) { }
- public CrowdedComparisonSorter() {
- Parameters.Add(new ScopeTreeLookupParameter("Rank", "The rank of the solution."));
- Parameters.Add(new ScopeTreeLookupParameter("CrowdingDistance", "The crowding distance of the solution."));
- }
-
- public override IOperation Apply() {
- ItemArray ranks = RankParameter.ActualValue;
- ItemArray distances = CrowdingDistanceParameter.ActualValue;
- int size = ranks.Length;
- int[] indices = Enumerable.Range(0, size).ToArray();
-
- IScope[] scopes = ExecutionContext.Scope.SubScopes.ToArray();
- Array.Sort(indices, scopes, new CustomComparer(ranks, distances));
- ExecutionContext.Scope.SubScopes.Clear();
- ExecutionContext.Scope.SubScopes.AddRange(scopes);
- return base.Apply();
- }
-
- private class CustomComparer : IComparer {
- ItemArray ranks;
- ItemArray distances;
-
- public CustomComparer(ItemArray ranks, ItemArray distances) {
- this.ranks = ranks;
- this.distances = distances;
- }
-
- #region IComparer Members
-
- public int Compare(int x, int y) {
- if (ranks[x].Value < ranks[y].Value) return -1;
- else if (ranks[x].Value > ranks[y].Value) return 1;
- else { // ranks are the same -> compare by distance
- if (distances[x].Value > distances[y].Value) return -1;
- else if (distances[x].Value < distances[y].Value) return 1;
- else return 0; // same distance
- }
- }
-
- #endregion
- }
-
- public override IDeepCloneable Clone(Cloner cloner) {
- return new CrowdedComparisonSorter(this, cloner);
- }
- }
-}
Index: unk/sources/HeuristicLab.Algorithms.NSGA2/3.3/CrowdedTournamentSelector.cs
===================================================================
--- /trunk/sources/HeuristicLab.Algorithms.NSGA2/3.3/CrowdedTournamentSelector.cs (revision 13166)
+++ (revision )
@@ -1,119 +1,0 @@
-#region License Information
-/* HeuristicLab
- * Copyright (C) 2002-2015 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.Collections.Generic;
-using System.Linq;
-using HeuristicLab.Core;
-using HeuristicLab.Data;
-using HeuristicLab.Optimization;
-using HeuristicLab.Parameters;
-using HeuristicLab.Selection;
-using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
-using HeuristicLab.Common;
-
-namespace HeuristicLab.Algorithms.NSGA2 {
- [Item("CrowdedTournamentSelector", "Selects solutions using tournament selection by using the partial order defined in Deb et al. 2002. A Fast and Elitist Multiobjective Genetic Algorithm: NSGA-II. IEEE Transactions on Evolutionary Computation, 6(2), pp. 182-197.")]
- [StorableClass]
- public class CrowdedTournamentSelector : Selector, IMultiObjectiveSelector, IStochasticOperator {
- public ILookupParameter MaximizationParameter {
- get { return (ILookupParameter)Parameters["Maximization"]; }
- }
- public IValueLookupParameter NumberOfSelectedSubScopesParameter {
- get { return (IValueLookupParameter)Parameters["NumberOfSelectedSubScopes"]; }
- }
- public IValueParameter CopySelectedParameter {
- get { return (IValueParameter)Parameters["CopySelected"]; }
- }
- public ILookupParameter RandomParameter {
- get { return (ILookupParameter)Parameters["Random"]; }
- }
- public ILookupParameter> QualitiesParameter {
- get { return (ILookupParameter>)Parameters["Qualities"]; }
- }
- public IScopeTreeLookupParameter RankParameter {
- get { return (IScopeTreeLookupParameter)Parameters["Rank"]; }
- }
- public IScopeTreeLookupParameter CrowdingDistanceParameter {
- get { return (IScopeTreeLookupParameter)Parameters["CrowdingDistance"]; }
- }
- public IValueLookupParameter GroupSizeParameter {
- get { return (IValueLookupParameter)Parameters["GroupSize"]; }
- }
-
- public BoolValue CopySelected {
- get { return CopySelectedParameter.Value; }
- set { CopySelectedParameter.Value = value; }
- }
-
- [StorableConstructor]
- protected CrowdedTournamentSelector(bool deserializing) : base(deserializing) { }
- protected CrowdedTournamentSelector(CrowdedTournamentSelector original, Cloner cloner) : base(original, cloner) { }
- public CrowdedTournamentSelector()
- : base() {
- Parameters.Add(new LookupParameter("Maximization", "For each objective determines whether it should be maximized or minimized."));
- Parameters.Add(new ValueLookupParameter("NumberOfSelectedSubScopes", "The number of sub-scopes that should be selected."));
- Parameters.Add(new ValueParameter("CopySelected", "True if the selected scopes are to be copied (cloned) otherwise they're moved."));
- Parameters.Add(new LookupParameter("Random", "The random number generator."));
- Parameters.Add(new ScopeTreeLookupParameter("Qualities", "The solutions' qualities vector."));
- Parameters.Add(new ScopeTreeLookupParameter("Rank", "The solutions' domination rank."));
- Parameters.Add(new ScopeTreeLookupParameter("CrowdingDistance", "The solutions' crowding distance values."));
- Parameters.Add(new ValueLookupParameter("GroupSize", "The size of the group from which the best will be chosen.", new IntValue(2)));
- }
-
- protected override IScope[] Select(List scopes) {
- IRandom random = RandomParameter.ActualValue;
- List ranks = RankParameter.ActualValue.Select(x => x.Value).ToList();
- List crowdingDistance = CrowdingDistanceParameter.ActualValue.Select(x => x.Value).ToList();
- int count = NumberOfSelectedSubScopesParameter.ActualValue.Value;
- int groupSize = GroupSizeParameter.ActualValue.Value;
- bool copy = CopySelected.Value;
- IScope[] selected = new IScope[count];
-
- for (int i = 0; i < count; i++) {
- int best = random.Next(scopes.Count);
- int index;
- for (int j = 1; j < groupSize; j++) {
- index = random.Next(scopes.Count);
- if (ranks[best] > ranks[index]
- || ranks[best] == ranks[index]
- && crowdingDistance[best] < crowdingDistance[index]) {
- best = index;
- }
- }
-
- if (copy)
- selected[i] = (IScope)scopes[best].Clone();
- else {
- selected[i] = scopes[best];
- scopes.RemoveAt(best);
- ranks.RemoveAt(best);
- crowdingDistance.RemoveAt(best);
- }
- }
-
- return selected;
- }
-
- public override IDeepCloneable Clone(Cloner cloner) {
- return new CrowdedTournamentSelector(this, cloner);
- }
- }
-}
Index: unk/sources/HeuristicLab.Algorithms.NSGA2/3.3/CrowdingDistanceAssignment.cs
===================================================================
--- /trunk/sources/HeuristicLab.Algorithms.NSGA2/3.3/CrowdingDistanceAssignment.cs (revision 13166)
+++ (revision )
@@ -1,123 +1,0 @@
-#region License Information
-/* HeuristicLab
- * Copyright (C) 2002-2015 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 HeuristicLab.Core;
-using HeuristicLab.Data;
-using HeuristicLab.Operators;
-using HeuristicLab.Parameters;
-using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
-using HeuristicLab.Common;
-
-namespace HeuristicLab.Algorithms.NSGA2 {
- [Item("CrowdingDistanceAssignment", "Calculates the crowding distances for each sub-scope as described in Deb et al. 2002. A Fast and Elitist Multiobjective Genetic Algorithm: NSGA-II. IEEE Transactions on Evolutionary Computation, 6(2), pp. 182-197.")]
- [StorableClass]
- public class CrowdingDistanceAssignment : SingleSuccessorOperator {
-
- public ScopeTreeLookupParameter QualitiesParameter {
- get { return (ScopeTreeLookupParameter)Parameters["Qualities"]; }
- }
-
- public ScopeTreeLookupParameter CrowdingDistanceParameter {
- get { return (ScopeTreeLookupParameter)Parameters["CrowdingDistance"]; }
- }
-
- private void QualitiesParameter_DepthChanged(object sender, EventArgs e) {
- CrowdingDistanceParameter.Depth = QualitiesParameter.Depth;
- }
-
- [StorableConstructor]
- protected CrowdingDistanceAssignment(bool deserializing) : base(deserializing) { }
- protected CrowdingDistanceAssignment(CrowdingDistanceAssignment original, Cloner cloner) : base(original, cloner) { }
- public CrowdingDistanceAssignment() {
- Parameters.Add(new ScopeTreeLookupParameter("Qualities", "The vector of quality values."));
- Parameters.Add(new ScopeTreeLookupParameter("CrowdingDistance", "Sets the crowding distance in each sub-scope."));
- AttachEventHandlers();
- }
-
- [StorableHook(HookType.AfterDeserialization)]
- private void AttachEventHandlers() {
- QualitiesParameter.DepthChanged += new EventHandler(QualitiesParameter_DepthChanged);
- }
-
- public static void Apply(DoubleArray[] qualities, DoubleValue[] distances) {
- int populationSize = qualities.Length;
- int objectiveCount = qualities[0].Length;
- for (int m = 0; m < objectiveCount; m++) {
- Array.Sort(qualities, distances, new QualitiesComparer(m));
-
- distances[0].Value = double.MaxValue;
- distances[populationSize - 1].Value = double.MaxValue;
-
- double minQuality = qualities[0][m];
- double maxQuality = qualities[populationSize - 1][m];
- for (int i = 1; i < populationSize - 1; i++) {
- distances[i].Value += (qualities[i + 1][m] - qualities[i - 1][m]) / (maxQuality - minQuality);
- }
- }
- }
-
- public override IOperation Apply() {
- DoubleArray[] qualities = QualitiesParameter.ActualValue.ToArray();
- int populationSize = qualities.Length;
- DoubleValue[] distances = new DoubleValue[populationSize];
- for (int i = 0; i < populationSize; i++)
- distances[i] = new DoubleValue(0);
-
- CrowdingDistanceParameter.ActualValue = new ItemArray(distances);
-
- Apply(qualities, distances);
-
- return base.Apply();
- }
-
- private void Initialize(ItemArray distances) {
- for (int i = 0; i < distances.Length; i++) {
- if (distances[i] == null) distances[i] = new DoubleValue(0);
- else distances[i].Value = 0;
- }
- }
-
- private class QualitiesComparer : IComparer {
- private int index;
-
- public QualitiesComparer(int index) {
- this.index = index;
- }
-
- #region IComparer Members
-
- public int Compare(DoubleArray x, DoubleArray y) {
- if (x[index] < y[index]) return -1;
- else if (x[index] > y[index]) return +1;
- else return 0;
- }
-
- #endregion
- }
-
- public override IDeepCloneable Clone(Cloner cloner) {
- return new CrowdingDistanceAssignment(this, cloner);
- }
- }
-}
Index: unk/sources/HeuristicLab.Algorithms.NSGA2/3.3/DefaultCrossover.cs
===================================================================
--- /trunk/sources/HeuristicLab.Algorithms.NSGA2/3.3/DefaultCrossover.cs (revision 13166)
+++ (revision )
@@ -1,61 +1,0 @@
-#region License Information
-/* HeuristicLab
- * Copyright (C) 2002-2015 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.Core;
-using HeuristicLab.Operators;
-using HeuristicLab.Optimization;
-using HeuristicLab.Parameters;
-using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
-using HeuristicLab.Common;
-
-namespace HeuristicLab.Algorithms.NSGA2 {
- [Item("DefaultCrossover", "This operator creates a parent by copying a single individual.")]
- [StorableClass]
- public class DefaultCrossover : SingleSuccessorOperator, ICrossover, IStochasticOperator {
- public ILookupParameter RandomParameter {
- get { return (ILookupParameter)Parameters["Random"]; }
- }
-
-
- [StorableConstructor]
- protected DefaultCrossover(bool deserializing) : base(deserializing) { }
- protected DefaultCrossover(DefaultCrossover original, Cloner cloner) : base(original, cloner) { }
- public DefaultCrossover()
- : base() {
- Parameters.Add(new LookupParameter("Random", "The random number generator."));
- }
-
- public override IOperation Apply() {
- IScope scope = ExecutionContext.Scope;
- int index = RandomParameter.ActualValue.Next(scope.SubScopes.Count);
- IScope child = scope.SubScopes[index];
-
- foreach (IVariable var in child.Variables)
- scope.Variables.Add((IVariable)var.Clone());
-
- return base.Apply();
- }
-
- public override IDeepCloneable Clone(Cloner cloner) {
- return new DefaultCrossover(this, cloner);
- }
- }
-}
Index: unk/sources/HeuristicLab.Algorithms.NSGA2/3.3/FastNonDominatedSort.cs
===================================================================
--- /trunk/sources/HeuristicLab.Algorithms.NSGA2/3.3/FastNonDominatedSort.cs (revision 13166)
+++ (revision )
@@ -1,162 +1,0 @@
-#region License Information
-/* HeuristicLab
- * Copyright (C) 2002-2015 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 HeuristicLab.Core;
-using HeuristicLab.Data;
-using HeuristicLab.Operators;
-using HeuristicLab.Parameters;
-using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
-using HeuristicLab.Common;
-
-namespace HeuristicLab.Algorithms.NSGA2 {
- ///
- /// FastNonDominatedSort as described in: Deb, Pratap, Agrawal and Meyarivan, "A Fast and Elitist Multiobjective
- /// Genetic Algorithm: NSGA-II", IEEE Transactions On Evolutionary Computation, Vol. 6, No. 2, April 2002
- ///
- [Item("FastNonDominatedSort", @"FastNonDominatedSort as described in: Deb, Pratap, Agrawal and Meyarivan, ""A Fast and Elitist Multiobjective
-Genetic Algorithm: NSGA-II"", IEEE Transactions On Evolutionary Computation, Vol. 6, No. 2, April 2002")]
- [StorableClass]
- public class FastNonDominatedSort : SingleSuccessorOperator {
- private enum DominationResult { Dominates, IsDominated, IsNonDominated };
-
- public IValueLookupParameter MaximizationParameter {
- get { return (IValueLookupParameter)Parameters["Maximization"]; }
- }
-
- public IScopeTreeLookupParameter QualitiesParameter {
- get { return (IScopeTreeLookupParameter)Parameters["Qualities"]; }
- }
-
- public IScopeTreeLookupParameter RankParameter {
- get { return (IScopeTreeLookupParameter)Parameters["Rank"]; }
- }
-
- [StorableConstructor]
- protected FastNonDominatedSort(bool deserializing) : base(deserializing) { }
- protected FastNonDominatedSort(FastNonDominatedSort original, Cloner cloner) : base(original, cloner) { }
- public FastNonDominatedSort() {
- Parameters.Add(new ValueLookupParameter("Maximization", "Whether each objective is maximization or minimization."));
- Parameters.Add(new ScopeTreeLookupParameter("Qualities", "The qualities of a solution.", 1));
- Parameters.Add(new ScopeTreeLookupParameter("Rank", "The rank of a solution.", 1));
- }
-
- public override IOperation Apply() {
- BoolArray maximization = MaximizationParameter.ActualValue;
- ItemArray qualities = QualitiesParameter.ActualValue;
- if (qualities == null) throw new InvalidOperationException(Name + ": No qualities found.");
-
- IScope scope = ExecutionContext.Scope;
- int populationSize = scope.SubScopes.Count;
-
- List fronts = new List();
- Dictionary> dominatedScopes = new Dictionary>();
- int[] dominationCounter = new int[populationSize];
- ItemArray rank = new ItemArray(populationSize);
-
- for (int pI = 0; pI < populationSize - 1; pI++) {
- IScope p = scope.SubScopes[pI];
- if (!dominatedScopes.ContainsKey(p))
- dominatedScopes[p] = new List();
- for (int qI = pI + 1; qI < populationSize; qI++) {
- DominationResult test = Dominates(qualities[pI], qualities[qI], maximization);
- if (test == DominationResult.Dominates) {
- dominatedScopes[p].Add(qI);
- dominationCounter[qI] += 1;
- } else if (test == DominationResult.IsDominated) {
- dominationCounter[pI] += 1;
- if (!dominatedScopes.ContainsKey(scope.SubScopes[qI]))
- dominatedScopes.Add(scope.SubScopes[qI], new List());
- dominatedScopes[scope.SubScopes[qI]].Add(pI);
- }
- if (pI == populationSize - 2
- && qI == populationSize - 1
- && dominationCounter[qI] == 0) {
- rank[qI] = new IntValue(0);
- AddToFront(scope.SubScopes[qI], fronts, 0);
- }
- }
- if (dominationCounter[pI] == 0) {
- rank[pI] = new IntValue(0);
- AddToFront(p, fronts, 0);
- }
- }
- int i = 0;
- while (i < fronts.Count && fronts[i].Count > 0) {
- ScopeList nextFront = new ScopeList();
- foreach (IScope p in fronts[i]) {
- if (dominatedScopes.ContainsKey(p)) {
- for (int k = 0; k < dominatedScopes[p].Count; k++) {
- int dominatedScope = dominatedScopes[p][k];
- dominationCounter[dominatedScope] -= 1;
- if (dominationCounter[dominatedScope] == 0) {
- rank[dominatedScope] = new IntValue(i + 1);
- nextFront.Add(scope.SubScopes[dominatedScope]);
- }
- }
- }
- }
- i += 1;
- fronts.Add(nextFront);
- }
-
- RankParameter.ActualValue = rank;
-
- scope.SubScopes.Clear();
-
- for (i = 0; i < fronts.Count; i++) {
- Scope frontScope = new Scope("Front " + i);
- foreach (var p in fronts[i])
- frontScope.SubScopes.Add(p);
- if (frontScope.SubScopes.Count > 0)
- scope.SubScopes.Add(frontScope);
- }
- return base.Apply();
- }
-
- private DominationResult Dominates(DoubleArray left, DoubleArray right, BoolArray maximizations) {
- bool leftIsBetter = false, rightIsBetter = false;
- for (int i = 0; i < left.Length; i++) {
- if (IsDominated(left[i], right[i], maximizations[i])) rightIsBetter = true;
- else if (IsDominated(right[i], left[i], maximizations[i])) leftIsBetter = true;
- if (leftIsBetter && rightIsBetter) break;
- }
- if (leftIsBetter && !rightIsBetter) return DominationResult.Dominates;
- if (!leftIsBetter && rightIsBetter) return DominationResult.IsDominated;
- return DominationResult.IsNonDominated;
- }
-
- private bool IsDominated(double left, double right, bool maximization) {
- return maximization && left < right
- || !maximization && left > right;
- }
-
- private void AddToFront(IScope p, List fronts, int i) {
- if (i == fronts.Count) fronts.Add(new ScopeList());
- fronts[i].Add(p);
- }
-
- public override IDeepCloneable Clone(Cloner cloner) {
- return new FastNonDominatedSort(this, cloner);
- }
- }
-}
Index: unk/sources/HeuristicLab.Algorithms.NSGA2/3.3/RankAndCrowdingSorter.cs
===================================================================
--- /trunk/sources/HeuristicLab.Algorithms.NSGA2/3.3/RankAndCrowdingSorter.cs (revision 13166)
+++ (revision )
@@ -1,84 +1,0 @@
-#region License Information
-/* HeuristicLab
- * Copyright (C) 2002-2015 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.Core;
-using HeuristicLab.Data;
-using HeuristicLab.Operators;
-using HeuristicLab.Parameters;
-using HeuristicLab.Selection;
-using HeuristicLab.Common;
-using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
-
-namespace HeuristicLab.Algorithms.NSGA2 {
- public class RankAndCrowdingSorter : AlgorithmOperator {
- public ValueLookupParameter MaximizationParameter {
- get { return (ValueLookupParameter)Parameters["Maximization"]; }
- }
- public ScopeTreeLookupParameter QualitiesParameter {
- get { return (ScopeTreeLookupParameter)Parameters["Qualities"]; }
- }
- public ScopeTreeLookupParameter RankParameter {
- get { return (ScopeTreeLookupParameter)Parameters["Rank"]; }
- }
- public ScopeTreeLookupParameter CrowdingDistanceParameter {
- get { return (ScopeTreeLookupParameter)Parameters["CrowdingDistance"]; }
- }
-
- [StorableConstructor]
- protected RankAndCrowdingSorter(bool deserializing) : base(deserializing) { }
- protected RankAndCrowdingSorter(RankAndCrowdingSorter original, Cloner cloner) : base(original, cloner) { }
- public RankAndCrowdingSorter()
- : base() {
- Parameters.Add(new ValueLookupParameter("Maximization", "For each objective a value that is true if that objective should be maximized, or false if it should be minimized."));
- Parameters.Add(new ScopeTreeLookupParameter("Qualities", "The vector of quality values."));
- Parameters.Add(new ScopeTreeLookupParameter("Rank", "The rank of a solution (to which front it belongs)."));
- Parameters.Add(new ScopeTreeLookupParameter("CrowdingDistance", "The crowding distance of a solution in a population."));
-
- FastNonDominatedSort fastNonDominatedSort = new FastNonDominatedSort();
- UniformSubScopesProcessor subScopesProcessor = new UniformSubScopesProcessor();
- CrowdingDistanceAssignment crowdingDistanceAssignment = new CrowdingDistanceAssignment();
- CrowdedComparisonSorter crowdedComparisonSorter = new CrowdedComparisonSorter();
- MergingReducer mergingReducer = new MergingReducer();
-
- fastNonDominatedSort.MaximizationParameter.ActualName = MaximizationParameter.Name;
- fastNonDominatedSort.QualitiesParameter.ActualName = QualitiesParameter.Name;
- fastNonDominatedSort.RankParameter.ActualName = RankParameter.Name;
-
- crowdingDistanceAssignment.CrowdingDistanceParameter.ActualName = CrowdingDistanceParameter.Name;
- crowdingDistanceAssignment.QualitiesParameter.ActualName = QualitiesParameter.Name;
-
- crowdedComparisonSorter.CrowdingDistanceParameter.ActualName = CrowdingDistanceParameter.Name;
- crowdedComparisonSorter.RankParameter.ActualName = RankParameter.Name;
-
- OperatorGraph.InitialOperator = fastNonDominatedSort;
- fastNonDominatedSort.Successor = subScopesProcessor;
- subScopesProcessor.Operator = crowdingDistanceAssignment;
- crowdingDistanceAssignment.Successor = crowdedComparisonSorter;
- crowdedComparisonSorter.Successor = null;
- subScopesProcessor.Successor = mergingReducer;
- mergingReducer.Successor = null;
- }
-
- public override IDeepCloneable Clone(Cloner cloner) {
- return new RankAndCrowdingSorter(this, cloner);
- }
- }
-}