Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/01/10 16:43:56 (14 years ago)
Author:
gkronber
Message:

Made PTC2 operator more robust. #859 (PTC2 initialization operator fails if it is used with restrictive function libraries)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP/3.3/TreeGardener.cs

    r2675 r2730  
    483483
    484484    public static IFunction RandomSelect(IRandom random, IList<IFunction> functionSet) {
     485      if (random == null || functionSet == null) throw new ArgumentNullException();
     486      if (functionSet.Count == 0) throw new ArgumentException("Empty function set");
     487      if (functionSet.Select(x => x.Tickets).Sum() <= 0) throw new ArgumentException("All functions in set have 0 tickets");
    485488      double[] accumulatedTickets = new double[functionSet.Count];
    486489      double ticketAccumulator = 0;
     
    498501        if (r < accumulatedTickets[i]) return functionSet[i];
    499502      }
    500       // sanity check
    501       throw new InvalidProgramException(); // should never happen
     503      throw new ArgumentException();
    502504    }
    503505
Note: See TracChangeset for help on using the changeset viewer.