Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/24/15 11:17:08 (10 years ago)
Author:
mkommend
Message:

#2276: Merged trunk changes into dataset refactoring branch.

Location:
branches/HeuristicLab.DatasetRefactor/sources
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.DatasetRefactor/sources

  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Optimization.Operators/3.3/ExpressionCalculator.cs

    r12031 r12247  
    7474variables (run parameters or results):
    7575  unquoted or in double quotes if they contain special characters or whitespace
    76 mathematical functions:
     76mathematical functions (resulting in double values):
    7777  +, -, *, /, ^ (power), log
    7878predicates:
    7979  ==, <, >, isnull, not
     80conversions:
     81  toint, todouble
     82array indexing:
     83  []
    8084stack manipulation:
    8185  drop swap dup
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Optimization.Operators/3.3/MultiObjective/FastNonDominatedSort.cs

    r12031 r12247  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
     
    4041    private enum DominationResult { Dominates, IsDominated, IsNonDominated };
    4142
     43    #region Parameter properties
    4244    public IValueLookupParameter<BoolArray> MaximizationParameter {
    4345      get { return (IValueLookupParameter<BoolArray>)Parameters["Maximization"]; }
    4446    }
    45 
     47    public IValueLookupParameter<BoolValue> DominateOnEqualQualitiesParameter {
     48      get { return (ValueLookupParameter<BoolValue>)Parameters["DominateOnEqualQualities"]; }
     49    }
    4650    public IScopeTreeLookupParameter<DoubleArray> QualitiesParameter {
    4751      get { return (IScopeTreeLookupParameter<DoubleArray>)Parameters["Qualities"]; }
    4852    }
    49 
    5053    public IScopeTreeLookupParameter<IntValue> RankParameter {
    5154      get { return (IScopeTreeLookupParameter<IntValue>)Parameters["Rank"]; }
    5255    }
     56    #endregion
    5357
    5458    [StorableConstructor]
     
    5761    public FastNonDominatedSort() {
    5862      Parameters.Add(new ValueLookupParameter<BoolArray>("Maximization", "Whether each objective is maximization or minimization."));
     63      Parameters.Add(new ValueLookupParameter<BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated."));
    5964      Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The qualities of a solution.", 1));
    6065      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Rank", "The rank of a solution.", 1));
     
    6267
    6368    public override IOperation Apply() {
     69      bool dominateOnEqualQualities = DominateOnEqualQualitiesParameter.ActualValue.Value;
    6470      BoolArray maximization = MaximizationParameter.ActualValue;
    6571      ItemArray<DoubleArray> qualities = QualitiesParameter.ActualValue;
     
    7985          dominatedScopes[p] = new List<int>();
    8086        for (int qI = pI + 1; qI < populationSize; qI++) {
    81           DominationResult test = Dominates(qualities[pI], qualities[qI], maximization);
     87          DominationResult test = Dominates(qualities[pI], qualities[qI], maximization, dominateOnEqualQualities);
    8288          if (test == DominationResult.Dominates) {
    8389            dominatedScopes[p].Add(qI);
     
    134140    }
    135141
    136     private DominationResult Dominates(DoubleArray left, DoubleArray right, BoolArray maximizations) {
     142    private static DominationResult Dominates(DoubleArray left, DoubleArray right, BoolArray maximizations, bool dominateOnEqualQualities) {
     143      if (dominateOnEqualQualities && left.SequenceEqual(right)) return DominationResult.Dominates;
     144
    137145      bool leftIsBetter = false, rightIsBetter = false;
    138146      for (int i = 0; i < left.Length; i++) {
     
    141149        if (leftIsBetter && rightIsBetter) break;
    142150      }
     151
    143152      if (leftIsBetter && !rightIsBetter) return DominationResult.Dominates;
    144153      if (!leftIsBetter && rightIsBetter) return DominationResult.IsDominated;
     
    146155    }
    147156
    148     private bool IsDominated(double left, double right, bool maximization) {
     157    private static bool IsDominated(double left, double right, bool maximization) {
    149158      return maximization && left < right
    150159        || !maximization && left > right;
    151160    }
    152161
    153     private void AddToFront(IScope p, List<ScopeList> fronts, int i) {
     162    private static void AddToFront(IScope p, List<ScopeList> fronts, int i) {
    154163      if (i == fronts.Count) fronts.Add(new ScopeList());
    155164      fronts[i].Add(p);
     
    159168      return new FastNonDominatedSort(this, cloner);
    160169    }
     170
     171    [StorableHook(HookType.AfterDeserialization)]
     172    private void AfterDeserialization() {
     173      // BackwardsCompatibility3.3
     174      #region Backwards compatible code, remove with 3.4
     175      if (!Parameters.ContainsKey("DominateOnEqualQualities"))
     176        Parameters.Add(new ValueLookupParameter<BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated."));
     177      #endregion
     178    }
    161179  }
    162180}
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Optimization.Operators/3.3/MultiObjective/RankAndCrowdingSorter.cs

    r12031 r12247  
    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> DominateOnEqualQualitiesParameter {
     46      get { return (ValueLookupParameter<BoolValue>)Parameters["DominateOnEqualQualities"]; }
     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>("DominateOnEqualQualities", "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.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.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("DominateOnEqualQualities"))
     96        Parameters.Add(new ValueLookupParameter<BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated."));
     97      #endregion
     98    }
    8399  }
    84100}
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Optimization.Operators/3.3/SolutionSimilarityCalculator.cs

    r12105 r12247  
    111111      if (x == null || y == null) return false;
    112112
    113       var q1 = x.Variables[QualityVariableName];
    114       var q2 = x.Variables[QualityVariableName];
     113      var q1 = x.Variables[QualityVariableName].Value;
     114      var q2 = y.Variables[QualityVariableName].Value;
    115115
    116116      return CheckQualityEquality(q1, q2) && CalculateSolutionSimilarity(x, y).IsAlmost(1.0);
     
    133133        }
    134134      }
    135       return 0; // throw exception?
     135      return 0;
    136136    }
    137137
     
    146146      var da2 = q2 as DoubleArray;
    147147
    148       if (da1 != null && da2 != null)
    149         return da1.SequenceEqual(da2);
     148      if (da1 != null && da2 != null) {
     149        if (da1.Length != da2.Length)
     150          throw new ArgumentException("The quality arrays must have the same length.");
     151
     152        for (int i = 0; i < da1.Length; ++i) {
     153          if (!da1[i].IsAlmost(da2[i]))
     154            return false;
     155        }
     156
     157        return true;
     158      }
    150159
    151160      throw new ArgumentException("Could not determine quality equality.");
Note: See TracChangeset for help on using the changeset viewer.