Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/13/12 09:01:31 (12 years ago)
Author:
mkommend
Message:

#1871: Added quality checks in all SingleObjectiveSelectors.

Location:
trunk/sources/HeuristicLab.Selection/3.3
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Selection/3.3/BestSelector.cs

    r7259 r7995  
    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) {
  • trunk/sources/HeuristicLab.Selection/3.3/GeneralizedRankSelector.cs

    r7259 r7995  
    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;
  • trunk/sources/HeuristicLab.Selection/3.3/LinearRankSelector.cs

    r7259 r7995  
    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;
  • trunk/sources/HeuristicLab.Selection/3.3/ProportionalSelector.cs

    r7259 r7995  
    6969      // prepare qualities for proportional selection
    7070      var qualities = QualityParameter.ActualValue.Select(x => x.Value);
     71      //check if list with indexes is as long as the original scope list
     72      //otherwise invalid quality values were filtered
     73      if (!qualities.All(IsValidQuality)) {
     74        throw new ArgumentException("The scopes contain invalid quality values (either infinity or double.NaN) on which the selector cannot operate.");
     75      }
     76
    7177      double minQuality = qualities.Min();
    7278      double maxQuality = qualities.Max();
  • trunk/sources/HeuristicLab.Selection/3.3/SingleObjectiveSelector.cs

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

    r7259 r7995  
    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++) {
  • trunk/sources/HeuristicLab.Selection/3.3/WorstSelector.cs

    r7259 r7995  
    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.