Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4067


Ignore:
Timestamp:
07/22/10 00:11:15 (14 years ago)
Author:
abeham
Message:

#1040

  • Fixed some bugs in NSGA-II
Location:
trunk/sources/HeuristicLab.Algorithms.NSGA2/3.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.NSGA2/3.3/CrowdedComparisonSorter.cs

    r4040 r4067  
    5858      int[] indices = Enumerable.Range(0, size).ToArray();
    5959
    60       Array.Sort(indices, new CustomComparer(ranks, distances));
    6160      IScope[] scopes = ExecutionContext.Scope.SubScopes.ToArray();
    62       Array.Sort(indices, scopes);
     61      Array.Sort(indices, scopes, new CustomComparer(ranks, distances));
    6362      ExecutionContext.Scope.SubScopes.Clear();
    6463      ExecutionContext.Scope.SubScopes.AddRange(scopes);
  • trunk/sources/HeuristicLab.Algorithms.NSGA2/3.3/CrowdingDistanceAssignment.cs

    r4017 r4067  
    7070        double minQuality = qualities[0][m];
    7171        double maxQuality = qualities[populationSize - 1][m];
    72         for (int i = 2; i < populationSize - 1; i++) {
     72        for (int i = 1; i < populationSize - 1; i++) {
    7373          distances[i].Value += (qualities[i + 1][m] - qualities[i - 1][m]) / (maxQuality - minQuality);
    7474        }
     
    8282      for (int i = 0; i < populationSize; i++)
    8383        distances[i] = new DoubleValue(0);
     84
     85      CrowdingDistanceParameter.ActualValue = new ItemArray<DoubleValue>(distances);
    8486     
    8587      Apply(qualities, distances);
    8688
    87       CrowdingDistanceParameter.ActualValue = new ItemArray<DoubleValue>(distances);
    8889      return base.Apply();
    8990    }
  • trunk/sources/HeuristicLab.Algorithms.NSGA2/3.3/FastNonDominatedSort.cs

    r4045 r4067  
    7272      for (int pI = 0; pI < populationSize - 1; pI++) {
    7373        IScope p = scope.SubScopes[pI];
    74         dominatedScopes[p] = new List<int>();
     74        if (!dominatedScopes.ContainsKey(p))
     75          dominatedScopes[p] = new List<int>();
    7576        for (int qI = pI + 1; qI < populationSize; qI++) {
    7677          DominationResult test = Dominates(qualities[pI], qualities[qI], maximization);
     
    8081          } else if (test == DominationResult.IsDominated) {
    8182            dominationCounter[pI] += 1;
     83            if (!dominatedScopes.ContainsKey(scope.SubScopes[qI]))
     84              dominatedScopes.Add(scope.SubScopes[qI], new List<int>());
    8285            dominatedScopes[scope.SubScopes[qI]].Add(pI);
    8386          }
     
    98101        ScopeList nextFront = new ScopeList();
    99102        foreach (IScope p in fronts[i]) {
    100           for (int k = 0; k < dominatedScopes[p].Count; k++) {
    101             int dominatedScope = dominatedScopes[p][k];
    102             dominationCounter[k] -= 1;
    103             if (dominationCounter[k] == 0) {
    104               rank[k] = new IntValue(i + 1);
    105               nextFront.Add(scope.SubScopes[k]);
     103          if (dominatedScopes.ContainsKey(p)) {
     104            for (int k = 0; k < dominatedScopes[p].Count; k++) {
     105              int dominatedScope = dominatedScopes[p][k];
     106              dominationCounter[dominatedScope] -= 1;
     107              if (dominationCounter[dominatedScope] == 0) {
     108                rank[dominatedScope] = new IntValue(i + 1);
     109                nextFront.Add(scope.SubScopes[dominatedScope]);
     110              }
    106111            }
    107112          }
  • trunk/sources/HeuristicLab.Algorithms.NSGA2/3.3/NSGA2.cs

    r4045 r4067  
    208208      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
    209209      ParameterizeSolutionsCreator();
     210      ParameterizeRankAndCrowdingSorter();
    210211      ParameterizeMainLoop();
    211212      ParameterizeSelectors();
     
    226227      ParameterizeStochasticOperator(Problem.Evaluator);
    227228      ParameterizeSolutionsCreator();
     229      ParameterizeRankAndCrowdingSorter();
    228230      ParameterizeMainLoop();
    229231      ParameterizeSelectors();
     
    251253    }
    252254    private void Evaluator_QualitiesParameter_ActualNameChanged(object sender, EventArgs e) {
     255      ParameterizeRankAndCrowdingSorter();
    253256      ParameterizeMainLoop();
    254257      ParameterizeSelectors();
     
    269272      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
    270273      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
     274    }
     275    private void ParameterizeRankAndCrowdingSorter() {
     276      RankAndCrowdingSorter.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
     277      RankAndCrowdingSorter.QualitiesParameter.ActualName = Problem.Evaluator.QualitiesParameter.ActualName;
    271278    }
    272279    private void ParameterizeMainLoop() {
Note: See TracChangeset for help on using the changeset viewer.