Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/21/18 09:18:49 (6 years ago)
Author:
bwerth
Message:

#2943 worked on MOBasicProblem - added Interfaces;reworked MOCalculators; several minor changes

Location:
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Optimization.Operators
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Optimization.Operators/3.3/MultiObjective/CrowdingDistanceAssignment.cs

    r15583 r16171  
    6666
    6767    public static void Apply(DoubleArray[] qualities, DoubleValue[] distances) {
    68       int populationSize = qualities.Length;
    69       int objectiveCount = qualities[0].Length;
    70       for (int m = 0; m < objectiveCount; m++) {
    71         Array.Sort<DoubleArray, DoubleValue>(qualities, distances, new QualitiesComparer(m));
    72 
    73         distances[0].Value = double.MaxValue;
    74         distances[populationSize - 1].Value = double.MaxValue;
    75 
    76         double minQuality = qualities[0][m];
    77         double maxQuality = qualities[populationSize - 1][m];
    78         for (int i = 1; i < populationSize - 1; i++) {
    79           distances[i].Value += (qualities[i + 1][m] - qualities[i - 1][m]) / (maxQuality - minQuality);
    80         }
    81       }
     68      var dist = CrowdingCalculator.CalculateCrowdingDistances(qualities);
     69      for (var i = 0; i < distances.Length; i++) distances[i].Value = dist[i];
    8270    }
    8371
    8472    public override IOperation Apply() {
    85       DoubleArray[] qualities = QualitiesParameter.ActualValue.ToArray();
    86       int populationSize = qualities.Length;
    87       DoubleValue[] distances = new DoubleValue[populationSize];
    88       for (int i = 0; i < populationSize; i++)
    89         distances[i] = new DoubleValue(0);
    90 
    91       CrowdingDistanceParameter.ActualValue = new ItemArray<DoubleValue>(distances);
    92 
    93       Apply(qualities, distances);
    94 
     73      var dist = CrowdingCalculator.CalculateCrowdingDistances(QualitiesParameter.ActualValue.ToArray());
     74      CrowdingDistanceParameter.ActualValue = new ItemArray<DoubleValue>(dist.Select(d => new DoubleValue(d)));
    9575      return base.Apply();
    96     }
    97 
    98     private void Initialize(ItemArray<DoubleValue> distances) {
    99       for (int i = 0; i < distances.Length; i++) {
    100         if (distances[i] == null) distances[i] = new DoubleValue(0);
    101         else distances[i].Value = 0;
    102       }
    103     }
    104 
    105     private class QualitiesComparer : IComparer<DoubleArray> {
    106       private int index;
    107 
    108       public QualitiesComparer(int index) {
    109         this.index = index;
    110       }
    111 
    112       #region IComparer<DoubleArray> Members
    113 
    114       public int Compare(DoubleArray x, DoubleArray y) {
    115         if (x[index] < y[index]) return -1;
    116         else if (x[index] > y[index]) return +1;
    117         else return 0;
    118       }
    119 
    120       #endregion
    12176    }
    12277
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Optimization.Operators/3.3/MultiObjective/FastNonDominatedSort.cs

    r15583 r16171  
    7575
    7676      int[] rank;
    77       var fronts = DominationCalculator<IScope>.CalculateAllParetoFronts(scope.SubScopes.ToArray(), qualities, maximization, out rank, dominateOnEqualQualities);
     77      var fronts = DominationCalculator.CalculateAllParetoFronts(scope.SubScopes.ToArray(), qualities, maximization, out rank, dominateOnEqualQualities);
    7878
    7979      RankParameter.ActualValue = new ItemArray<IntValue>(rank.Select(x => new IntValue(x)));
Note: See TracChangeset for help on using the changeset viewer.