Exemplo n.º 1
0
def build_uv_rls(m, min_degree=False, no_conseq=False):
    dimension = len(m)
    checked = [False for i in range(dimension)]

    u = (util.get_min_degree_node(m) if min_degree else random.randint(
        0, dimension - 1))

    rls_u = rls.buildRLS(m, u, max_w=0, no_conseq=no_conseq)

    v = util.min_degree_node_from_set(m, rls_u.lastLevel())
    rls_v = rls.buildRLS(m, v, max_w=0, no_conseq=no_conseq)

    return u, v, rls_u, rls_v, dimension
Exemplo n.º 2
0
def grow_set_and_check_peripherals(m, set, min_width=False, initial_p=None):
    ''' ([[]], list or set, bool) -> Peripheral '''

    p = peripherals.Peripherals(0, 0, 0) if not initial_p else initial_p

    width_limit = m.get_dimension()

    set_size = len(set)
    print 'growing set size', len(set)

    iter = 0
    if min_width:
        for x in set:
            rls_x = rls.buildRLS(m, x, max_w=width_limit)
            #print (rls_x.levelsArray if rls_x else "a")
            if rls_x:
                width_limit = rls_x.width()
                p_x = peripherals.Peripherals(x,
                                              rls_x.lastLevel()[0],
                                              rls_x.numLevels() - 1)
                if p_x.diameter >= p.diameter:
                    #print 'min_width:', width_limit
                    p.copy(p_x)

            iter += 1
            percentage = 100 * float(iter) / set_size
            sys.stdout.write("\r{} / {} - {:0.2f}%".format(
                iter, set_size, percentage))
            sys.stdout.flush()
    else:
        for x in set:
            rls_x = rls.buildRLS(m, x)
            p_x = peripherals.Peripherals(x,
                                          rls_x.lastLevel()[0],
                                          rls_x.numLevels() - 1)

            if p_x.diameter > p.diameter:
                p.copy(p_x)

    return p
Exemplo n.º 3
0
def noConsequent_u(m, min_degree=False, min_width=False):

    u = (util.get_min_degree_node(m) if min_degree else random.randint(
        0, dimension - 1))

    rls_u = rls.buildRLS(m, u, max_w=0, no_conseq=True)
    no_conseq_u = rls_u.noConsequents

    p = peripherals.Peripherals(u, rls_u.lastLevel()[0], rls_u.numLevels() - 1)
    return util.grow_set_and_check_peripherals(m,
                                               no_conseq_u,
                                               min_width=min_width,
                                               initial_p=p)
Exemplo n.º 4
0
def iterative_gps_test(m, diameter, min_degree=False):
    plot_count = 0

    dimension = len(m)
    p = peripherals.Peripherals(0, 0, 0)

    root = (util.get_min_degree_node(m) if min_degree else random.randint(
        0, dimension - 1))

    explore = [root]
    checked = [False for i in range(dimension)]
    iter = 0
    while explore:
        #print explore

        v = explore.pop(0)
        rls_v = rls.buildRLS(m, v)
        checked[v] = True

        #print rls_v.levelsArray

        for w in rls_v.lastLevel():
            if checked[w] == False:
                explore.append(w)

        p_v = peripherals.Peripherals(v,
                                      rls_v.lastLevel()[0],
                                      rls_v.numLevels() - 1)

        iter = iter + 1

        if p_v.diameter > p.diameter:
            p.copy(p_v)

        if int(p.diameter) == int(diameter):
            print 'min num iter =', iter
            return p

        #plot.plot_graph(m, str(plot_count), checked)
        #plot_count = plot_count + 1

    #checked[p.b] = True
    #plot.plot_graph(m, str(plot_count), checked)
    return p
Exemplo n.º 5
0
def arany_method(m, min_degree = False, min_width = False):

    u, v, rls_u, rls_v, dimension = build_uv_rls(m, min_degree,
                                                 no_conseq=False)

    reversible_set = util.get_reversible_set(rls_u.levelsArray, 
                                      rls_v.levelsArray)

    m_uv = reversible_set[len(reversible_set) // 2]
    #print m_uv

    a = m_uv.pop()
    rls_a = rls.buildRLS(m, a)

    last_level = rls_a.lastLevel()
    
    p = util.return_most_peripheral(u, rls_u, v, rls_v)
    return util.grow_set_and_check_peripherals(m, last_level,
                                                min_width=min_width,
                                                initial_p=p)
Exemplo n.º 6
0
def exaustive_peripheral_search(m, fromV = None, toV = None, output = None, thread = None):
    dimension = m.get_dimension()

    begin = fromV if fromV else 0
    end = toV if toV else dimension

    if thread:
        print "Thread {} range({},{})".format(thread, begin,end)

    V = range(begin, end)
    V_size = end - begin

    iter = 0
    p = Peripherals(0, 0, 0)

    for v in V:
        rls_v = rls.buildRLS(m, v)
        '''
        print rls_v.levelsArray
        '''
        p_v = Peripherals(v, rls_v.lastLevel()[0], rls_v.numLevels() - 1)
        if p_v.diameter > p.diameter:
            p.copy(p_v)
        
        iter += 1
        percentage = 100 * float(iter)/V_size
        
        if thread:
            if iter % 100 == 0:
                print 'Thread {}: node {} checked - {:0.2f}%'.format(thread,v,percentage)
        #else:
        #    sys.stdout.write("\r{} / {} - {:0.2f}%".format(v,V_size,percentage))
        #    sys.stdout.flush()

    #print p.toStr()
    if output:
        output.put(p)
    return p