def box_mixer(N, D, b, p): box_list = [] edges_list = [] for i in range(b): box = dl.box_generator(N, D)[0] box_list.append(box) edges_list.append(len(box.edges())) mixing_edges = int(p*sum(edges_list)) # approx number of edges between the boxes, if added fraction p of the total edges in all of the boxes print 'Adding %d edges' %mixing_edges mixed_box = nx.union_all(box_list) #assigns birthdays to the mixed_box DAG for node in mixed_box.nodes(): birthday = sum(node) mixed_box.node[node]['birthday'] = birthday birthday = nx.get_node_attributes(mixed_box, 'birthday') while mixing_edges > 0: box_indices = range(b) rand_index_1 = choice(box_indices) box_indices.remove(rand_index_1) #prevents extra edge being created within a single box rand_index_2 = choice(box_indices) nodes_1 = box_list[rand_index_1].nodes() nodes_2 = box_list[rand_index_2].nodes() node_1 = choice(nodes_1) node_2 = choice(nodes_2) if birthday[node_1] > birthday[node_2]: mixed_box.add_edge(node_1,node_2) mixing_edges -= 1 return [mixed_box,box_list]
def test(N, D): box = dl.box_generator(N, D) DAG = box[0] ext = box[1] start = ext[1] end = ext[0] print DAG.node[start]["birthday"] print "!!!!!" start_time = time.clock() the_greedy_path = greedy_path(DAG, start, max_depth=50) greedy_time = time.clock() - start_time start_time = time.clock() lp = dl.lpd(DAG, start, end) lp_time = time.clock() - start_time print "Greedy" greedy_path_length = len(the_greedy_path) # print the_greedy_path print "Longest" lp_length = lp[2] # print lp[1] print "Greedy Time = %s" % str(greedy_time) print "LP Time = %s" % str(lp_time) return (greedy_path_length, greedy_time, lp_length, lp_time)
def test(N, D): box = dl.box_generator(N, D) DAG = box[0] ext = box[1] start = ext[1] end = ext[0] the_indec_path = indecisive_path(DAG, start, -1, end) print len(the_indec_path)
def test(N, D): box = dl.box_generator(N, D, 'minkowski') #box = mod2.COd(D,N) dag = box[0] ext = box[1] tr_dag = tr.trans_red(dag) good_dag = tr_dag lp = dl.lpd(tr_dag, ext[1], ext[0]) length = lp[2] print length return length
def lpd_test(N, D): box = dl.box_generator(N, D, 'minkowski') dag = box[0] ext = box[1] tr_dag = tr.trans_red(dag) print ext[0] print ext[1] lp = dl.lpd(tr_dag, ext[1], ext[0]) print lp[1] return lp
def tr_test(N): box = dl.box_generator(N, 3) dag = box[0] ext = box[1] '''for node in dag.nodes(): print '####################' print node print dag.successors(node) print '####################''' start_time = time.clock() tr_dag = tr.trans_red(dag) tr_time = time.clock() - start_time #print tr_dag.successors(ext[1]) print 'N = %s and time for tr was %s' % (N, tr_time)
def test(N, D): box = dl.box_generator(N, D) dag = box[0] ext = box[1] tr_dag = tr.trans_red(dag) good_dag = tr_dag lp = dl.lpd(tr_dag, ext[1], ext[0]) path = lp[1] tr_dag = good_dag dim = mps.mpsd(tr_dag, path) mm_dim = mmd.MM_dimension(dag) print dim print mm_dim return [dim[0], mm_dim]
k_max = k i_max = [i] print 'Change kmax at %s to %d' %(thing,k) elif k == k_max: if k_max > 0: i_max.append(i) print 'Add %s to list' %thing i += 1 if len(i_max) == 1: #there is a single node that has the maximum degree value i_path = i_max[0] elif len(i_max) > 1: #there is more than one node with the same (non-zero) degree value i_path = choice(i_max) print 'multiple choice, choose from %s' %str(i_max) else: #i.e. i_max is an empty list...all node have k=0 i.e. the end of the path will be reached on the next step to a random one of 'things' i_path = choice(range(len(things))) next_step = things[i_path] #This is the next step that the path with take path = indecisive_path(DAG,next_step,type,path) return path full_box = dl.box_generator(100, 2) ext = full_box[1] path = indecisive_path(full_box[0],ext[1],'start') print len(path) print path