class documentation
class SameFunction:
Count the number of consecutive instances of the same function.
Useful to limit the number of repetitions on the same function.
Example:
>>> import cocoex >>> from cocoex.utilities import SameFunction >>> >>> suite = cocoex.Suite('bbob', '', '') >>> already_seen = SameFunction() >>> processed = 0 >>> for problem in suite: ... if already_seen(problem.id) > 5: ... continue ... # do something here only with the first five instances ... processed += 1 >>> processed, len(suite), already_seen.count (864, 2160, 15)
More arbitrary tests:
>>> for i in range(4): ... if seen('f001_i%d' % i) > 2: ... continue ... # do something here only the first two instances >>> seen.count 4 >>> seen('f_d03_i001') 0 >>> seen('f_d03_i02') 1 >>> for i in range(4): ... if seen('f%d_i%d' % (i, i)): ... break >>> i, seen.count (3, 1)