Exemplo n.º 1
0
def checkDescendingOrder(id_list):

    for id in id_list:
        data = flippable.data_from_id(id)

        p_list = flippable.get_lex_primitive_pairs(data)
        f_list = flippable.get_flippable_pairs(data, dim)

        p_list2 = []
        for p in p_list:
            if p[0] < p[1]:
                p_list2.append(p)

        f_list2 = []
        for f in f_list:
            if f[0] < f[1]:
                f_list2.append(f)

        if len(f_list2) == 1:
            print('only one', flippable.data_to_id(data))
            print('t', f_list2)

    print('all done')
Exemplo n.º 2
0
    for id in id_list:
        data = flippable.data_from_id(id)

        flippable_pairs = flippable.get_flippable_pairs(data, dim)

        flipped_data = [
            flippable.flip(data, flip_pair, dim)
            for flip_pair in flippable_pairs
        ]

        edges = []

        for pair, f in zip(flippable_pairs, flipped_data):

            f_id = flippable.data_to_id(f)
            new_pref_list.add(f_id)
            new_flip_list.append(format_flip(id, f_id, pair[0], pair[1]))

        #        update_pref_table(f_str)
        #        update_flip_table([id, f_str], pair)
        # update_flip_table([id, f_id], pair)

        processed_id_list.add(id)

    # print("updating for prefs ", len(new_pref_list))
    update_pref_table(new_pref_list)
    update_flip_table(new_flip_list)
    mark_processed(processed_id_list)

cur.close()
Exemplo n.º 3
0
data4part2 = [
    [15, 14, 13, 12, 11, 10, 7, 6, 9, 8, 5, 4, 3, 2, 1, 0],
    [15, 14, 13, 12, 11, 10, 9, 7, 8, 6, 5, 4, 3, 2, 1, 0],
    [15, 14, 13, 11, 12, 10, 7, 6, 9, 8, 5, 3, 4, 2, 1, 0],
    [15, 14, 13, 11, 12, 10, 9, 7, 8, 6, 5, 3, 4, 2, 1, 0],
]

data4 = data4part1 + data4part2

dim = 4
start_data = data4

parent_dic = {}
#parent_dic[flippable.data_to_id(data2[0])] = data3
parent_dic[flippable.data_to_id(data3[0])] = data4part1
parent_dic[flippable.data_to_id(data3[1])] = data4part2

print(parent_dic)

new_prefs = []

for mydata in start_data:
    print('handling ', mydata)
    new_prefs = new_prefs + generate(mydata, dim)

#new_prefs = new_prefs + generate(data4[13], dim)

print('done')

print(len(new_prefs))
Exemplo n.º 4
0
def generate(mydata, dim):
    #### mydata is the data to extend
    new_prefs = []

    #print('mydata', mydata)
    mydata_half = [mydata[i] for i in range(0, len(mydata) // 2)]

    my_cutoff = 2**(dim - 1)
    #print('my_cutoff=', my_cutoff)
    first = [get_as_big(x, my_cutoff) for x in mydata]

    prefix = [x for x in mydata if x < my_cutoff]

    #print('first', first)
    #print('prefix', prefix)

    mydata_half2 = [2 * x for x in mydata_half]

    print(mydata_half, mydata_half2)

    children = parent_dic[flippable.data_to_id(prefix)]
    #print('children', children)

    for child in children:
        print('handling child', child)
        mychild_bin = [x % 2 for x in child]

        #print('mychild_bin', mychild_bin)

        indices1 = [i for i, e in enumerate(mychild_bin) if e == 1]
        # indices0 = set(range(0,len(mychild_bin))) - set(indices1)

        #print('indices1', indices1)
        # print(indices0)

        new_data_top_half = [x for x in mydata_half2]

        #print('new data half', new_data_top_half)

        for i, idx in enumerate(indices1):
            #print('\t\t', i , idx)
            new_data_top_half.insert(idx, 1 + mydata_half2[i])

        #print('new half data is', new_data_top_half)

        new_top_half_as_bin = [
            decimal_to_bin_array(x, dim + 1) for x in new_data_top_half
        ]

        # reversed and complement
        new_data_bottom_half = [
            2**(dim + 1) - 1 - x for x in reversed(new_data_top_half)
        ]

        # check straight appending
        new_data = new_data_top_half + new_data_bottom_half

        if check_middle_cols(new_data, dim):
            new_prefs.append(new_data)

        # how many ways can we stitch? at least one
        # new_data_bottom_half = [7,6,5,4,3,2,1,0]
        stitch_data = [
            x ^ (new_data_bottom_half[0]) < 2**dim
            for x in new_data_bottom_half
        ]
        try:
            stitch_end = stitch_data.index(False)
        except ValueError:
            stitch_end = len(stitch_data)

        #print("stitchable:", stitch_data, stitch_end)

        # xxxab need to consider all possible subsets, i think
        # for stitch_idx in range(0, stitch_end):
        #     print('>>>>>>>>>>>>>> stitching', stitch_idx, new_data_top_half[0: len(new_data_top_half) - stitch_idx])
        #     stitch_pref = new_data_top_half[0: len(new_data_top_half) - stitch_idx] \
        #                + new_data_bottom_half[0: stitch_idx] \
        #                + new_data_top_half[len(new_data_top_half) - stitch_idx: len(new_data_top_half)] \
        #                + new_data_bottom_half[stitch_idx: len(new_data_bottom_half)]
        #
        #     if check_middle_cols(stitch_pref, dim):
        #         print('>>>>>>>>', stitch_pref)
        #         new_prefs.append(stitch_pref)

        # for stitch_idx in range(0, stitch_end):
        #     stitch_sets = all_subsets(range(0, stitch_end))
        #
        #     for stitch_set in stitch_sets:
        #          if len(stitch_set) > 0:
        #             stitch_pref = interweave(new_data_top_half, new_data_bottom_half, stitch_set)
        #             if check_middle_cols(stitch_pref, dim):
        #                 print('>>>>>>>>', stitch_pref)
        #                 new_prefs.append(stitch_pref)

        print('\tstitch end=', stitch_end)

        my_len = len(new_data_top_half)

        for stitch_size in range(0, stitch_end):
            stitch_sets = get_subsets(range(my_len - stitch_end, my_len),
                                      stitch_size)

            for stitch_set in stitch_sets:
                if len(
                        stitch_set
                ) > 0:  #and stitch_set != (2**dim-1,) and stitch_set !=(2**dim-2, 2**dim-1):
                    stitch_pref = interweave(new_data_top_half,
                                             new_data_bottom_half, stitch_size,
                                             stitch_set)
                    if check_middle_cols(stitch_pref, dim):
                        #print('>>>>>>>>', stitch_pref)
                        new_prefs.append(stitch_pref)

    return new_prefs
Exemplo n.º 5
0
            ma2 = np.ma.masked_array(c_array1, m2)
            ca2 = np.ma.compress_cols(ma2)

            #print(ca2)

            parent_data = [checkflip.bin_array_to_decimal(x) for x in ca2]

            #print('\t\t', parent_data)

            parent_list.append((parent_data))

        #print(parent_list)

        name_array = [
            name_for_id(flippable.data_to_id(p)) for p in parent_list
        ]
        #        name = '-'.join(name_array) + "+" +  str(data[2**(dim-1) -1])
        if data[2**(dim - 1) - 1] < 2**(dim - 1):
            end = '-'
        else:
            end = '+'

        name = '(' + ''.join(name_array) + ')' + end
        name_list.append(name)

        print(name)

    #for id, name in zip(id_list, name_list):
    #    print(id, name)