def test_repetition_ktimes(k):
    start = timer()
    find_stable_set_nktimes = 10**(k)
    without_dup_collection_of_n_stable_sets = set()
    with_dup = 0  # count how many stable sets found with duplication
    for i in range(find_stable_set_nktimes):
        find_ss = find_stable_set(
            G, total_stable_set_surplus_bound)  # less than 2
        if find_ss != None:
            with_dup = with_dup + 1
            candidate_dom, total_surplus = find_ss
            without_dup_collection_of_n_stable_sets.add(
                frozenset(candidate_dom))

    without_dup = len(without_dup_collection_of_n_stable_sets)

    ## WRITING TO RECORD ###################################################
    # for recording the trial
    trialname = 'test_duplication_7_' + domfilename.split('.')[0] + '_' + str(
        k) + '.md'
    trialfile = open(trialname, 'w')
    trialfile.write('NOTE: only consider combs with 7 teeth! \n')
    trialfile.write(domfilename.split('.')[0] + '\n\n')

    # write duplication
    trialfile.write('With duplicaition, %d stable sets were considered \n' %
                    with_dup)
    trialfile.write('Without duplication, %d stable sets were considered \n' %
                    without_dup)
    trialfile.write('Running find_stable_set: %d times \n\n' %
                    find_stable_set_nktimes)

    trialfile.write('Number of nodes in G: %d \n' % G.number_of_nodes())
    trialfile.write('Number of edges in G: %d \n' % G.number_of_edges())
    trialfile.write('Surplus bound on each domino: %.4f \n' % surplus_bound)
    trialfile.write('Bound on total surplus of stable sets: %.4f \n' %
                    total_stable_set_surplus_bound)

    end = timer()
    trialfile.write('Total running time: %.5f seconds' % (end - start))

    trialfile.close()
    print('With duplicaition, %d stable sets were considered \n' % with_dup)
    print('Without duplicaition, %d stable sets were considered \n' %
          without_dup)
    print('Total time: %.5f seconds \n \n' % (end - start))
def comb_surplus_interval_ktimes(k):
    global counter, viol_comb_surplus_lst
    start = timer()

    # for the loop
    find_handle_nktimes = 10**k  # number of times you want to run find_handle

    for i in range(find_handle_nktimes):
        find_ss = find_stable_set(
            G, total_stable_set_surplus_bound)  # less than 2
        if find_ss != None:
            counter = counter + 1
            candidate_dom, total_surplus = find_ss

            interval = comb_surplus_interval(F, G, candidate_dom,
                                             total_surplus,
                                             pattern_upper_bound)
            '''
				fh=find_handle(F,G,candidate_dom,total_surplus, comb_upper_bound,pattern_upper_bound)
				if fh !=None:
					combs_found = combs_found+1
				'''

    ## WRITING TO RECORD ###################################################
    # for recording the trial

    # PLEASE CHECK THEM!!!!!!!!!!!!!!!!!!!!!!!!!
    trialname = 'interval_7_' + domfilename.split('.')[0] + '_' + str(
        k) + '.md'
    trialfile = open(trialname, 'w')
    trialfile.write('Trying patterns for %d candidate doms of size 7. \n' %
                    counter)
    #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    trialfile.write(domfilename.split('.')[0] + '\n')
    trialfile.write('Surplus bound on each domino: %.4f \n' % surplus_bound)
    trialfile.write('Number of nodes in G: %d \n' % G.number_of_nodes())
    trialfile.write('Number of edges in G: %d \n' % G.number_of_edges())
    trialfile.write('Bound on total surplus of stable sets: %.4f \n' %
                    total_stable_set_surplus_bound)

    #THIS WARNING NOTE MAY NEED SOME CHANGE AS WELL
    trialfile.write(
        'Pattern upper bound: %d. \n Note: now consider all possible patterns, since number of teeth<=9\n'
        % pattern_upper_bound)
    #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    trialfile.write('Running comb_surplus_interval: %d times \n' %
                    find_handle_nktimes)
    trialfile.write('Number of candidate_dom considered %d \n \n' % counter)

    # interval recording
    trialfile.write('Comb surpluses: \n')
    trialfile.write('0.0 <= comb_surplus < 1:{0:8} \n\n'.format(zero_to_one))

    trialfile.write('1.0 <= comb_surplus < 1.2:{0:8} \n'.format(one_to_two_1))
    trialfile.write('1.2 <= comb_surplus < 1.4:{0:8} \n'.format(one_to_two_2))
    trialfile.write('1.4 <= comb_surplus < 1.6:{0:8} \n'.format(one_to_two_3))
    trialfile.write('1.6 <= comb_surplus < 1.8:{0:8} \n'.format(one_to_two_4))
    trialfile.write('1.8 <= comb_surplus < 2.0:{0:8} \n'.format(one_to_two_5))
    trialfile.write('1.0 <= comb_surplus < 2.0:{0:8} \n\n'.format(one_to_two))

    trialfile.write(
        '2.0 <= comb_surplus < 2.2:{0:8} \n'.format(two_to_three_1))
    trialfile.write(
        '2.2 <= comb_surplus < 2.4:{0:8} \n'.format(two_to_three_2))
    trialfile.write(
        '2.4 <= comb_surplus < 2.6:{0:8} \n'.format(two_to_three_3))
    trialfile.write(
        '2.6 <= comb_surplus < 2.8:{0:8} \n'.format(two_to_three_4))
    trialfile.write(
        '2.8 <= comb_surplus < 3.0:{0:8} \n'.format(two_to_three_5))
    trialfile.write(
        '2.0 <= comb_surplus < 3.0:{0:8} \n\n'.format(two_to_three))

    trialfile.write(
        '3.0 <= comb_surplus < 3.2:{0:8} \n'.format(three_to_four_1))
    trialfile.write(
        '3.2 <= comb_surplus < 3.4:{0:8} \n'.format(three_to_four_2))
    trialfile.write(
        '3.4 <= comb_surplus < 3.6:{0:8} \n'.format(three_to_four_3))
    trialfile.write(
        '3.6 <= comb_surplus < 3.8:{0:8} \n'.format(three_to_four_4))
    trialfile.write(
        '3.8 <= comb_surplus < 4.0:{0:8} \n'.format(three_to_four_5))
    trialfile.write(
        '3.0 <= comb_surplus < 4.0:{0:8} \n\n'.format(three_to_four))

    trialfile.write(
        '4.0 <= comb_surplus < 4.2:{0:8} \n'.format(four_to_five_1))
    trialfile.write(
        '4.2 <= comb_surplus < 4.4:{0:8} \n'.format(four_to_five_2))
    trialfile.write(
        '4.4 <= comb_surplus < 4.6:{0:8} \n'.format(four_to_five_3))
    trialfile.write(
        '4.6 <= comb_surplus < 4.8:{0:8} \n'.format(four_to_five_4))
    trialfile.write(
        '4.8 <= comb_surplus < 5.0:{0:8} \n'.format(four_to_five_5))
    trialfile.write(
        '4.0 <= comb_surplus < 5.0:{0:8} \n\n'.format(four_to_five))

    trialfile.write('5.0 <= comb_surplus < 5.2:{0:8} \n'.format(five_to_six_1))
    trialfile.write('5.2 <= comb_surplus < 5.4:{0:8} \n'.format(five_to_six_2))
    trialfile.write('5.4 <= comb_surplus < 5.6:{0:8} \n'.format(five_to_six_3))
    trialfile.write('5.6 <= comb_surplus < 5.8:{0:8} \n'.format(five_to_six_4))
    trialfile.write('5.8 <= comb_surplus < 6.0:{0:8} \n'.format(five_to_six_5))
    trialfile.write('5.0 <= comb_surplus < 6.0:{0:8} \n\n'.format(five_to_six))

    trialfile.write('6.0 <= comb_surplus < 7.0:{0:8} \n'.format(six_to_seven))
    trialfile.write(
        '7.0 <= comb_surplus < 8.0:{0:8} \n'.format(seven_to_eight))
    trialfile.write('>= 8.0:{0:27} \n\n'.format(more_than_eight))

    trialfile.write('Violated comb surpluses:\n')
    for item in viol_comb_surplus_lst:
        trialfile.write('%.5f\n' % item)

    ## WRITE COMB ######################################################################

    end = timer()
    trialfile.write('Total running time: %.5f seconds' % (end - start))
    trialfile.close()
    print('Total number of sets of candidate_dom considered: %d' % counter)
    print('Surpluses of violated combs: \n')
    print(viol_comb_surplus_lst)

    #print('Combs found: %d \n' % combs_found)

    print('Total time: %.5f seconds' % (end - start))
Ejemplo n.º 3
0
def find_many_combs(F, G, comb_upper_bd, surplus_bound, ncombs):
    for i in range(ncombs):
        stable = find_stable_set(G, surplus_bound)
        candidate_dom = stable[0]
        total_surplus = stable[1]
        find_handle(F, G, candidate_dom, total_surplus, comb_upper_bd)
Ejemplo n.º 4
0
    comb_upper_bound = 1.0  # less than 1

    #for the loop
    find_handle_ntimes = 100000  # number of times you want to run findhandle
    ####################################################################

    F = build_support_graph(supp_graph_name)
    G = create_dom_graph(domfilename, surplus_bound, node_num_upper_bound)

    for k in range(1, 4):  # k=1,2,3,4
        counter = 0  # number of candidate_dom (i.e. number of stable sets) considered
        combs_found = 0
        find_handle_nktimes = 10**k

        for i in range(find_handle_nktimes):
            find_ss = find_stable_set(
                G, total_stable_set_surplus_bound)  # less than 2
            if find_ss != None:
                counter = counter + 1
                candidate_dom, total_surplus = find_ss
                fh = find_handle(F, G, candidate_dom, total_surplus,
                                 comb_upper_bound, pattern_upper_bound)
                if fh != None:
                    combs_found = combs_found + 1

        ## WRITING TO RECORD ###################################################
        # for recording the trial
        trialname = 'test_find_handle_3teeth' + domfilename.split(
            '.')[0] + '_' + str(k) + '.md'
        trialfile = open(trialname, 'w')
        #trialfile.write('NOTE: only consider combs with more than 5 teeth! \n')
        trialfile.write(
Ejemplo n.º 5
0
                    if Fshrink.has_edge(p1_node,p2_node):
                        edge_cut_list.append((p1_node,p2_node))
            '''
            '''
            print('cut weight = %.5f' % cutweight)
            print('total surplus = %.5f' % total_surplus)
            print('cut weight + total surplus = %.5f' % cutweight+total_surplus)
            
            print('running time = %.5f seconds \n'% (end-start))
            '''
    print('Fails :(')
    return None  #[cutweight, cutweight+total_surplus, edge_cut_list]


if __name__ == '__main__':
    from domgraph import create_dom_graph

    F = build_support_graph('bowtie.x')
    G = create_dom_graph('bowtie.dom', 0.5, 5000)
    for i in range(1):
        candidate_dom, total_surplus = find_stable_set(G, 0.75)
        find_handle(F, G, candidate_dom, total_surplus, 0.9)


def find_many_combs(F, G, vio_upper_bd, surplus_bound, ncombs):
    for i in range(ncombs):
        stable = find_stable_set(G, surplus_bound)
        candidate_dom = stable[0]
        total_surplus = stable[1]
        find_handle(F, G, candidate_dom, total_surplus, vio_upper_bd)