1# -*- coding: utf-8 -*- 2 3from fpylll.fplll.gso import MatGSO 4from fpylll.fplll.integer_matrix import IntegerMatrix 5from fpylll.fplll.lll import LLLReduction 6from fpylll.fplll.enumeration import Enumeration 7from fpylll import Pruning 8from time import time 9 10 11def bench_enumeration(n): 12 """Return number of nodes visited and wall time for enumeration in dimension `n`. 13 14 :param n: dimension 15 :returns: nodes, wall time 16 17 >>> import fpylll.tools.benchmark 18 >>> _ = fpylll.tools.benchmark.bench_enumeration(30) 19 20 """ 21 22 A = IntegerMatrix.random(n, "qary", bits=30, k=n//2) 23 M = MatGSO(A) 24 L = LLLReduction(M) 25 L(0, 0, n) 26 27 radius = M.get_r(0, 0) * .999 28 pruning = Pruning.run(radius, 2.0**50, M.r(), 0.2) 29 30 enum = Enumeration(M) 31 t = time() 32 enum.enumerate(0, n, radius, 0, pruning=pruning.coefficients) 33 t = time() - t 34 cost = enum.get_nodes() 35 36 return cost, t 37