Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/18/19 16:11:21 (5 years ago)
Author:
mkommend
Message:

#2521: Refactored single-objective problems to use EvaluationResult instead of double as return type from Evaluate.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GraphColoring/3.3/GraphColoringProblem.cs

    r17320 r17382  
    129129    }
    130130
    131     public override double Evaluate(LinearLinkage lle, IRandom random, CancellationToken cancellationToken) {
     131    public override ISingleObjectiveEvaluationResult Evaluate(LinearLinkage lle, IRandom random, CancellationToken cancellationToken) {
    132132      var adjList = adjacencyListParameter.Value;
    133133      var llee = lle.ToEndLinks(); // LLE-e encoding uses the highest indexed member as group number
     134
     135      double quality = double.NaN;
    134136
    135137      switch (FitnessFunction) {
     
    142144            var mag = Math.Pow(10, -(int)Math.Ceiling(Math.Log10(llee.Length)));
    143145            // the value is e.g. 4.03 for 4 conflicts with 3 colors (and less than 100 nodes)
    144             return conflicts + colors * mag;
     146            quality = conflicts + colors * mag;
     147            break;
    145148          }
    146149        case FitnessFunction.Penalized: {
     
    157160              if (color1 == color2) colors[color1].ConflictCount++;
    158161            }
    159             return 2 * colors.Sum(x => x.Value.ColorCount * x.Value.ConflictCount) - colors.Sum(x => x.Value.ColorCount * x.Value.ColorCount);
     162            quality = 2 * colors.Sum(x => x.Value.ColorCount * x.Value.ConflictCount) - colors.Sum(x => x.Value.ColorCount * x.Value.ColorCount);
     163            break;
    160164          }
    161165        default: throw new InvalidOperationException(string.Format("Unknown fitness function {0}.", FitnessFunction));
    162166      }
     167
     168      return new SingleObjectiveEvaluationResult(quality);
    163169    }
    164170
Note: See TracChangeset for help on using the changeset viewer.