Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/21/12 18:02:33 (13 years ago)
Author:
gkronber
Message:

#1847: merged trunk changes r7800:HEAD into gp move operators branch

Location:
branches/GP-MoveOperators
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/GP-MoveOperators

  • branches/GP-MoveOperators/HeuristicLab.Selection/3.3/BestSelector.cs

    r7259 r8085  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    5455
    5556      // create a list for each scope that contains the scope's index in the original scope list
    56       var temp = qualities.Select((x, index) => new { index, x.Value });
     57      var temp = qualities.Where(x => IsValidQuality(x.Value)).Select((x, index) => new { index, x.Value });
    5758      if (maximization)
    5859        temp = temp.OrderByDescending(x => x.Value);
     
    6061        temp = temp.OrderBy(x => x.Value);
    6162      var list = temp.ToList();
     63
     64      //check if list with indexes is as long as the original scope list
     65      //otherwise invalid quality values were filtered
     66      if (list.Count != scopes.Count) {
     67        throw new ArgumentException("The scopes contain invalid quality values (either infinity or double.NaN) on which the selector cannot operate.");
     68      }
    6269
    6370      if (copy) {
  • branches/GP-MoveOperators/HeuristicLab.Selection/3.3/GeneralizedRankSelector.cs

    r7259 r8085  
    6363      double pressure = PressureParameter.ActualValue.Value;
    6464
    65       var ordered = qualities.Select((x, index) => new KeyValuePair<int, double>(index, x.Value)).OrderBy(x => x.Value).ToList();
     65      var ordered = qualities.Where(x => IsValidQuality(x.Value)).Select((x, index) => new KeyValuePair<int, double>(index, x.Value)).OrderBy(x => x.Value).ToList();
    6666      if (maximization) ordered.Reverse();
     67
     68      //check if list with indexes is as long as the original scope list
     69      //otherwise invalid quality values were filtered
     70      if (ordered.Count != scopes.Count) {
     71        throw new ArgumentException("The scopes contain invalid quality values (either infinity or double.NaN) on which the selector cannot operate.");
     72      }
    6773
    6874      int m = scopes.Count;
  • branches/GP-MoveOperators/HeuristicLab.Selection/3.3/LinearRankSelector.cs

    r7259 r8085  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    5455
    5556      // create a list for each scope that contains the scope's index in the original scope list and its lots
    56       var temp = qualities.Select((x, index) => new { index, x.Value });
     57      var temp = qualities.Where(x => IsValidQuality(x.Value)).Select((x, index) => new { index, x.Value });
    5758      if (maximization)
    5859        temp = temp.OrderBy(x => x.Value);
     
    6061        temp = temp.OrderByDescending(x => x.Value);
    6162      var list = temp.Select((x, index) => new { x.index, lots = index + 1 }).ToList();
     63
     64      //check if list with indexes is as long as the original scope list
     65      //otherwise invalid quality values were filtered
     66      if (list.Count != scopes.Count) {
     67        throw new ArgumentException("The scopes contain invalid quality values (either infinity or double.NaN) on which the selector cannot operate.");
     68      }
    6269
    6370      int lotSum = list.Count * (list.Count + 1) / 2;
  • branches/GP-MoveOperators/HeuristicLab.Selection/3.3/ProportionalSelector.cs

    r7259 r8085  
    6969      // prepare qualities for proportional selection
    7070      var qualities = QualityParameter.ActualValue.Select(x => x.Value);
    71       double minQuality = qualities.Min();
    72       double maxQuality = qualities.Max();
     71      double minQuality = double.MaxValue;
     72      double maxQuality = double.MinValue;
     73      foreach (var quality in qualities) {
     74        if (!IsValidQuality(quality)) throw new ArgumentException("The scopes contain invalid quality values (either infinity or double.NaN) on which the selector cannot operate.");
     75        if (quality < minQuality) minQuality = quality;
     76        if (quality > maxQuality) maxQuality = quality;
     77      }
     78
    7379      if (minQuality == maxQuality) {  // all quality values are equal
    7480        qualities = qualities.Select(x => 1.0);
     
    8995
    9096      List<double> list = qualities.ToList();
    91       double qualitySum = qualities.Sum();
     97      double qualitySum = list.Sum();
    9298      for (int i = 0; i < count; i++) {
    9399        double selectedQuality = random.NextDouble() * qualitySum;
  • branches/GP-MoveOperators/HeuristicLab.Selection/3.3/SingleObjectiveSelector.cs

    r7259 r8085  
    6363      CopySelectedParameter.Hidden = true;
    6464    }
     65
     66    protected bool IsValidQuality(double quality) {
     67      return !double.IsNaN(quality) && !double.IsInfinity(quality);
     68    }
    6569  }
    6670}
  • branches/GP-MoveOperators/HeuristicLab.Selection/3.3/TournamentSelector.cs

    r7259 r8085  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    5758      IRandom random = RandomParameter.ActualValue;
    5859      bool maximization = MaximizationParameter.ActualValue.Value;
    59       List<double> qualities = QualityParameter.ActualValue.Select(x => x.Value).ToList();
     60      List<double> qualities = QualityParameter.ActualValue.Where(x => IsValidQuality(x.Value)).Select(x => x.Value).ToList();
    6061      int groupSize = GroupSizeParameter.ActualValue.Value;
    6162      IScope[] selected = new IScope[count];
     63
     64      //check if list with indexes is as long as the original scope list
     65      //otherwise invalid quality values were filtered
     66      if (qualities.Count != scopes.Count) {
     67        throw new ArgumentException("The scopes contain invalid quality values (either infinity or double.NaN) on which the selector cannot operate.");
     68      }
    6269
    6370      for (int i = 0; i < count; i++) {
  • branches/GP-MoveOperators/HeuristicLab.Selection/3.3/WorstSelector.cs

    r7259 r8085  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    5152
    5253      // create a list for each scope that contains the scope's index in the original scope list
    53       var temp = qualities.Select((x, index) => new { index, x.Value });
     54      var temp = qualities.Where(x => IsValidQuality(x.Value)).Select((x, index) => new { index, x.Value });
    5455      if (maximization)
    5556        temp = temp.OrderBy(x => x.Value);
     
    5758        temp = temp.OrderByDescending(x => x.Value);
    5859      var list = temp.ToList();
     60
     61      //check if list with indexes is as long as the original scope list
     62      //otherwise invalid quality values were filtered
     63      if (list.Count != scopes.Count) {
     64        throw new ArgumentException("The scopes contain invalid quality values (either infinity or double.NaN) on which the selector cannot operate.");
     65      }
    5966
    6067      if (copy) {
Note: See TracChangeset for help on using the changeset viewer.