blob: 0ac8ccea1180283259b48884165f156a350b9433 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
from __future__ import division
class DesignPointGenerator(object):
'''Iterates over all combinations of values specified in options.
Shamelessly stolen (and simplified) from bcw.'''
def __init__(self, options):
self.point_idx = 0 # Current point
self.options = options
self.total = 1
for x in options.itervalues():
self.total *= len(x)
def __iter__(self):
return self
def next(self):
while True:
if self.point_idx == self.total:
raise StopIteration
else:
point = {}
divisor = 1
for key in sorted(self.options.keys()):
size = len(self.options[key])
option_idx = int(self.point_idx / divisor) % size
point[key] = self.options[key][option_idx]
divisor *= size
self.point_idx += 1
return point
|