Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/18/15 11:45:29 (10 years ago)
Author:
mkommend
Message:

#2321: Added option for treatment of solutions with equal quality values in NSGA-II.

Location:
branches/NSGA-II Changes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/NSGA-II Changes/HeuristicLab.Algorithms.NSGA2/3.3/NSGA2.cs

    r12012 r12034  
    8888      get { return (ValueParameter<IntValue>)Parameters["SelectedParents"]; }
    8989    }
     90
     91    private IFixedValueParameter<BoolValue> TreatSolutionsWithEqualQualityAsDominatedParameter {
     92      get { return (IFixedValueParameter<BoolValue>)Parameters["TreatSolutionsWithEqualQualityAsDominated"]; }
     93    }
    9094    #endregion
    9195
     
    135139      set { SelectedParentsParameter.Value = value; }
    136140    }
     141    public bool TreatSolutionsWithEqualQualityAsDominated {
     142      get { return TreatSolutionsWithEqualQualityAsDominatedParameter.Value.Value; }
     143      set { TreatSolutionsWithEqualQualityAsDominatedParameter.Value.Value = value; }
     144    }
     145
    137146    private RandomCreator RandomCreator {
    138147      get { return (RandomCreator)OperatorGraph.InitialOperator; }
     
    171180      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
    172181      Parameters.Add(new ValueParameter<IntValue>("SelectedParents", "Each two parents form a new child, typically this value should be twice the population size, but because the NSGA-II is maximally elitist it can be any multiple of 2 greater than 0.", new IntValue(200)));
     182      Parameters.Add(new FixedValueParameter<BoolValue>("TreatSolutionsWithEqualQualityAsDominated", "Flag which determines wether solutions with equal quality values should be treated as dominated.", new BoolValue(false)));
    173183
    174184      RandomCreator randomCreator = new RandomCreator();
     
    195205      subScopesCounter.Successor = rankAndCrowdingSorter;
    196206
     207      rankAndCrowdingSorter.TreatSolutionsWithEqualQualityAsDominatedParameter.ActualName = TreatSolutionsWithEqualQualityAsDominatedParameter.Name;
    197208      rankAndCrowdingSorter.CrowdingDistanceParameter.ActualName = "CrowdingDistance";
    198209      rankAndCrowdingSorter.RankParameter.ActualName = "Rank";
     
    311322    [StorableHook(HookType.AfterDeserialization)]
    312323    private void AfterDeserialization() {
     324      // BackwardsCompatibility3.3
     325      #region Backwards compatible code, remove with 3.4
     326      if (!Parameters.ContainsKey("TreatSolutionsWithEqualQualityAsDominated"))
     327        Parameters.Add(new FixedValueParameter<BoolValue>("TreatSolutionsWithEqualQualityAsDominated", "Flag which determines wether solutions with equal quality values should be treated as dominated.", new BoolValue(false)));
     328      #endregion
     329
    313330      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
    314331      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
  • branches/NSGA-II Changes/HeuristicLab.Algorithms.NSGA2/3.3/NSGA2MainLoop.cs

    r12012 r12034  
    7979      get { return (LookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
    8080    }
     81    public IValueLookupParameter<BoolValue> TreatSolutionsWithEqualQualityAsDominatedParameter {
     82      get { return (ValueLookupParameter<BoolValue>)Parameters["TreatSolutionsWithEqualQualityAsDominated"]; }
     83    }
    8184    #endregion
    8285
    8386    [StorableConstructor]
    8487    protected NSGA2MainLoop(bool deserializing) : base(deserializing) { }
     88    [StorableHook(HookType.AfterDeserialization)]
     89    private void AfterDeserialization() {
     90      // BackwardsCompatibility3.3
     91      #region Backwards compatible code, remove with 3.4
     92      if (!Parameters.ContainsKey("TreatSolutionsWithEqualQualityAsDominated"))
     93        Parameters.Add(new ValueLookupParameter<BoolValue>("TreatSolutionsWithEqualQualityAsDominated", "Flag which determines wether solutions with equal quality values should be treated as dominated."));
     94      #endregion
     95    }
     96
    8597    protected NSGA2MainLoop(NSGA2MainLoop original, Cloner cloner) : base(original, cloner) { }
    8698    public NSGA2MainLoop()
     
    105117      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze each generation."));
    106118      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
     119      Parameters.Add(new ValueLookupParameter<BoolValue>("TreatSolutionsWithEqualQualityAsDominated", "Flag which determines wether solutions with equal quality values should be treated as dominated."));
    107120      #endregion
    108121
     
    171184      subScopesCounter.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
    172185
     186      rankAndCrowdingSorter.TreatSolutionsWithEqualQualityAsDominatedParameter.ActualName = TreatSolutionsWithEqualQualityAsDominatedParameter.Name;
    173187      rankAndCrowdingSorter.CrowdingDistanceParameter.ActualName = "CrowdingDistance";
    174188      rankAndCrowdingSorter.RankParameter.ActualName = "Rank";
  • branches/NSGA-II Changes/HeuristicLab.Optimization.Operators/3.3/MultiObjective/FastNonDominatedSort.cs

    r12012 r12034  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Drawing;
     25using System.Linq;
    2426using HeuristicLab.Common;
    2527using HeuristicLab.Core;
     
    4042    private enum DominationResult { Dominates, IsDominated, IsNonDominated };
    4143
     44    #region Parameter properties
    4245    public IValueLookupParameter<BoolArray> MaximizationParameter {
    4346      get { return (IValueLookupParameter<BoolArray>)Parameters["Maximization"]; }
    4447    }
    45 
     48    public IValueLookupParameter<BoolValue> TreatSolutionsWithEqualQualityAsDominatedParameter {
     49      get { return (ValueLookupParameter<BoolValue>)Parameters["TreatSolutionsWithEqualQualityAsDominated"]; }
     50    }
    4651    public IScopeTreeLookupParameter<DoubleArray> QualitiesParameter {
    4752      get { return (IScopeTreeLookupParameter<DoubleArray>)Parameters["Qualities"]; }
    4853    }
    49 
    5054    public IScopeTreeLookupParameter<IntValue> RankParameter {
    5155      get { return (IScopeTreeLookupParameter<IntValue>)Parameters["Rank"]; }
    5256    }
     57    #endregion
    5358
    5459    [StorableConstructor]
     
    5762    public FastNonDominatedSort() {
    5863      Parameters.Add(new ValueLookupParameter<BoolArray>("Maximization", "Whether each objective is maximization or minimization."));
     64      Parameters.Add(new ValueLookupParameter<BoolValue>("TreatSolutionsWithEqualQualityAsDominated", "Flag which determines wether solutions with equal quality values should be treated as dominated."));
    5965      Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The qualities of a solution.", 1));
    6066      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Rank", "The rank of a solution.", 1));
     
    6268
    6369    public override IOperation Apply() {
     70      bool treatSolutionsWithEqualQualityAsDominated = TreatSolutionsWithEqualQualityAsDominatedParameter.ActualValue.Value;
    6471      BoolArray maximization = MaximizationParameter.ActualValue;
    6572      ItemArray<DoubleArray> qualities = QualitiesParameter.ActualValue;
     
    7986          dominatedScopes[p] = new List<int>();
    8087        for (int qI = pI + 1; qI < populationSize; qI++) {
    81           DominationResult test = Dominates(qualities[pI], qualities[qI], maximization);
     88          DominationResult test = Dominates(qualities[pI], qualities[qI], maximization, treatSolutionsWithEqualQualityAsDominated);
    8289          if (test == DominationResult.Dominates) {
    8390            dominatedScopes[p].Add(qI);
     
    134141    }
    135142
    136     private DominationResult Dominates(DoubleArray left, DoubleArray right, BoolArray maximizations) {
     143    private static DominationResult Dominates(DoubleArray left, DoubleArray right, BoolArray maximizations, bool treatSolutionsWithEqualQualityAsDominated) {
     144      if (treatSolutionsWithEqualQualityAsDominated && left.SequenceEqual(right)) return DominationResult.Dominates;
     145
    137146      bool leftIsBetter = false, rightIsBetter = false;
    138147      for (int i = 0; i < left.Length; i++) {
     
    141150        if (leftIsBetter && rightIsBetter) break;
    142151      }
     152
    143153      if (leftIsBetter && !rightIsBetter) return DominationResult.Dominates;
    144154      if (!leftIsBetter && rightIsBetter) return DominationResult.IsDominated;
     
    146156    }
    147157
    148     private bool IsDominated(double left, double right, bool maximization) {
     158    private static bool IsDominated(double left, double right, bool maximization) {
    149159      return maximization && left < right
    150160        || !maximization && left > right;
    151161    }
    152162
    153     private void AddToFront(IScope p, List<ScopeList> fronts, int i) {
     163    private static void AddToFront(IScope p, List<ScopeList> fronts, int i) {
    154164      if (i == fronts.Count) fronts.Add(new ScopeList());
    155165      fronts[i].Add(p);
     
    159169      return new FastNonDominatedSort(this, cloner);
    160170    }
     171
     172    [StorableHook(HookType.AfterDeserialization)]
     173    private void AfterDeserialization() {
     174      // BackwardsCompatibility3.3
     175      #region Backwards compatible code, remove with 3.4
     176      if (!Parameters.ContainsKey("TreatSolutionsWithEqualQualityAsDominated"))
     177        Parameters.Add(new ValueLookupParameter<BoolValue>("TreatSolutionsWithEqualQualityAsDominated", "Flag which determines wether solutions with equal quality values should be treated as dominated."));
     178      #endregion
     179    }
    161180  }
    162181}
  • branches/NSGA-II Changes/HeuristicLab.Optimization.Operators/3.3/MultiObjective/RankAndCrowdingSorter.cs

    r12012 r12034  
    3030namespace HeuristicLab.Optimization.Operators {
    3131  public class RankAndCrowdingSorter : AlgorithmOperator, IMultiObjectiveOperator {
     32    #region Parameter properties
    3233    public ValueLookupParameter<BoolArray> MaximizationParameter {
    3334      get { return (ValueLookupParameter<BoolArray>)Parameters["Maximization"]; }
     
    4243      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["CrowdingDistance"]; }
    4344    }
     45    public IValueLookupParameter<BoolValue> TreatSolutionsWithEqualQualityAsDominatedParameter {
     46      get { return (ValueLookupParameter<BoolValue>)Parameters["TreatSolutionsWithEqualQualityAsDominated"]; }
     47    }
     48    #endregion
    4449
    4550    [StorableConstructor]
     
    4954      : base() {
    5055      Parameters.Add(new ValueLookupParameter<BoolArray>("Maximization", "For each objective a value that is true if that objective should be maximized, or false if it should be minimized."));
     56      Parameters.Add(new ValueLookupParameter<BoolValue>("TreatSolutionsWithEqualQualityAsDominated", "Flag which determines wether solutions with equal quality values should be treated as dominated."));
    5157      Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The vector of quality values."));
    5258      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Rank", "The rank of a solution (to which front it belongs)."));
     
    6066
    6167      fastNonDominatedSort.MaximizationParameter.ActualName = MaximizationParameter.Name;
     68      fastNonDominatedSort.TreatSolutionsWithEqualQualityAsDominatedParameter.ActualName = TreatSolutionsWithEqualQualityAsDominatedParameter.Name;
    6269      fastNonDominatedSort.QualitiesParameter.ActualName = QualitiesParameter.Name;
    6370      fastNonDominatedSort.RankParameter.ActualName = RankParameter.Name;
     
    8188      return new RankAndCrowdingSorter(this, cloner);
    8289    }
     90
     91    [StorableHook(HookType.AfterDeserialization)]
     92    private void AfterDeserialization() {
     93      // BackwardsCompatibility3.3
     94      #region Backwards compatible code, remove with 3.4
     95      if (!Parameters.ContainsKey("TreatSolutionsWithEqualQualityAsDominated"))
     96        Parameters.Add(new ValueLookupParameter<BoolValue>("TreatSolutionsWithEqualQualityAsDominated", "Flag which determines wether solutions with equal quality values should be treated as dominated."));
     97      #endregion
     98    }
    8399  }
    84100}
Note: See TracChangeset for help on using the changeset viewer.