implement randomize functionality for bruteforce2

main
josch 12 years ago
parent 2afff50f00
commit f757dca501

@ -1,11 +1,12 @@
import sys
import itertools
from util import xmlfiletodict, get_pallet, get_articles, product_varlength
from util import xmlfiletodict, get_pallet, get_articles, product_varlength, starmap
from arrange_spread2 import arrange_in_layer, spread_articles
import cPickle
from binascii import b2a_base64
import zlib
import os
import random
def rotate(node):
if node is None:
@ -97,10 +98,21 @@ def main():
else:
max_iter = -1
if os.environ.get("randomize"):
try_random = bool(int(os.environ["randomize"]))
else:
try_random = False
if try_rot_article and try_rot_pallet:
product_it = product_varlength(4)
if try_random:
product_it = starmap(random.randint, itertools.repeat((0,3)))
else:
product_it = product_varlength(4)
elif try_rot_article or try_rot_pallet:
product_it = product_varlength(2)
if try_random:
product_it = starmap(random.randint, itertools.repeat((0,1)))
else:
product_it = product_varlength(2)
i = 0
while True:

@ -199,6 +199,20 @@ def product_varlength(branch_factor):
else:
current = current["parent"]
# cannot use itertools.cycle as it doesnt allow to send() to it
def cycle(iterable):
saved = []
for element in iterable:
yield element
saved.append(element)
while saved:
for element in saved:
yield element
# cannot use itertools.starmap as it doesnt allow to send() to it
def starmap(function, iterable):
for args in iterable:
yield function(*args)
if __name__ == "__main__":
it = product_var_repeat(3)

Loading…
Cancel
Save