Ejemplo n.º 1
0
def _generate_upper_bounds():
    """
    This function can be used to produce new upper bounds,
    but shouldn't be used in productive code. Simply run this
    command once and then hardcode the list.
    """

    left_max = 40
    right_max = 30

    UPPER_BOUNDS = set()
    UPPER_BOUNDS.add((1.0, 1.0))

    def add_to_bounds(a, b):
        size = float(len(b)) / len(a)
        upper_bound = relative_distance(a, b)
        UPPER_BOUNDS.add((size, upper_bound))

    for k in range(1, left_max):
        for i in range(1, right_max):
            if k == i == 1:
                continue
            atest = 'm' * k
            btest = 'm' * k + 'm' * (i - 1)
            add_to_bounds(atest, btest)

    # Remove duplicates
    UPPER_BOUNDS = list(UPPER_BOUNDS)

    # Sort
    UPPER_BOUNDS.sort(lambda x, y: cmp(x[0], y[0]))

    fp = file("upper_bounds.py", "w")
    fp.write("UPPER_BOUNDS = ")
    pprint.pprint(UPPER_BOUNDS, fp)
    fp.close()
Ejemplo n.º 2
0
def _generate_upper_bounds():
    '''
    This function can be used to produce new upper bounds,
    but shouldn't be used in productive code. Simply run this
    command once and then hardcode the list.
    '''

    left_max = 40
    right_max = 30

    UPPER_BOUNDS = set()
    UPPER_BOUNDS.add((1.0, 1.0))

    def addToBounds(a, b):
        size = float(len(b)) / len(a)
        upper_bound = relative_distance(a, b)
        UPPER_BOUNDS.add((size, upper_bound))

    for k in range(1, left_max):
        for i in range(1, right_max):
            if k == i == 1:
                continue
            atest = 'm' * k
            btest = 'm' * k + 'm' * (i - 1)
            addToBounds(atest, btest)

    # Remove duplicates
    UPPER_BOUNDS = list(UPPER_BOUNDS)

    # Sort
    UPPER_BOUNDS.sort(lambda x, y: cmp(x[0], y[0]))

    fp = file("upper_bounds.py", "w")
    fp.write("UPPER_BOUNDS = ")
    pprint.pprint(UPPER_BOUNDS, fp)
    fp.close()
Ejemplo n.º 3
0
 def add_to_bounds(a, b):
     size = float(len(b)) / len(a)
     upper_bound = relative_distance(a, b)
     UPPER_BOUNDS.add((size, upper_bound))
Ejemplo n.º 4
0
 def addToBounds(a, b):
     size = float(len(b)) / len(a)
     upper_bound = relative_distance(a, b)
     UPPER_BOUNDS.add((size, upper_bound))