def return_most_peripheral(u, rls_u, v, rls_v): p_u = peripherals.Peripherals(u, rls_u.lastLevel()[0], rls_u.numLevels() - 1) p_v = peripherals.Peripherals(u, rls_v.lastLevel()[0], rls_v.numLevels() - 1) if p_u.diameter > p_v: return p_u return p_v
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
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
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)