Example #1
0
def path_large_unjumble(n):
    d = defaultdict(list)
    for t in listAllFreeTrees(n):
        g, edge_lbls = gen_tree_edge_list_from_list(t)
        d[path_f({}, g).expand()].append(tuple(t))
        # d[path_f({}, g).expand()] += 1
    return d
Example #2
0
def max_path_small_unjumble_with_weighted(n, weights=(1, 2)):
    d = defaultdict(list)
    for t in listAllFreeTrees(n):
        # print t
        g, edge_lbls = gen_tree_edge_list_from_list(t)
        mp = find_maximal_paths(g)
        # print mp
        for lbl in get_labeled_graphs(t, 2, True):
            coloring = []
            # sc = []
            for mpindex in xrange(len(mp)):
                p = mp[mpindex]
                w = 0
                for i in xrange(1, len(p)):
                    x, y = min(p[i], p[i - 1]), max(p[i], p[i - 1])
                    w += weights[lbl[edge_lbls[(x, y)]]]
                # if mpindex > 0 and len(mp[mpindex]) > len(mp[mpindex - 1]):
                #     coloring += sorted(sc)
                #     coloring.append("|")
                #     sc = []
                # sc.append(str(w))
                coloring.append(w)
            # coloring += sorted(sc)
            # print lbl, str(coloring)
            # d[tuple(sorted(coloring))] += 1
            d[tuple(sorted(coloring))].append((tuple(t), lbl))
            # d[tuple(sorted(coloring))] += 1
    return d
Example #3
0
def path_small_unjumble_weights(n):
    monomials = [[x**k * y**(i - k) for k in xrange(i + 1)] for i in xrange(1, n)]
    monomials_weights = [[1 * k + 2 * (i - k) for k in xrange(i + 1)] for i in xrange(1, n)]

    # d = defaultdict(int)
    d = defaultdict(list)
    for t in listAllFreeTrees(n):
        g, edge_lbls = gen_tree_edge_list_from_list(t)
        for lbl in get_labeled_graphs(t, 2, True):
            f = path_labeled_f({}, edge_lbls, lbl, g).expand()

            # wl = [] #[0] * (4 * (n + 1) + 1)
            # for term in str(f).split("+"):
            #     term = term.strip()
            #     if term.find("x") != -1 and term.find("y") != -1:
            #         if term.count("*") > 1:
            #             ii = term.find("*")
            #             term1 = term[: ii]
            #             term2 = term[ii + 1 :].replace("x", "1").replace("y", "2").replace("*", "+").replace("^", "*")
            #             # print term, "t1", eval(term1 + "*(%s)"%term2)
            #             val = eval(term2)
            #             if val >= len(wl):
            #                 wl += [0] * (val - len(wl) + 1)
            #             wl[val] += int(term1)
            #         else:
            #             # print term, "t2", eval(term.replace("x", "1").replace("y", "2").replace("*", "+").replace("^", "*"))
            #             val = eval(term.replace("x", "1").replace("y", "2").replace("*", "+").replace("^", "*"))
            #             if val >= len(wl):
            #                 wl += [0] * (val - len(wl) + 1)
            #             wl[val] += 1
            #     elif not term.isdigit():
            #         # print term, "t3", eval(term.replace("x", "1").replace("y", "2").replace("^", "*"))
            #         ii = term.find("*")
            #         if ii != -1:
            #             term1 = term[: ii]
            #             term2 = term[ii + 1:]
            #             val = eval(term2.replace("x", "1").replace("y", "2").replace("^", "*"))
            #             if val >= len(wl):
            #                 wl += [0] * (val - len(wl) + 1)
            #             wl[val] += int(term1)
            #         else:
            #             val = eval(term.replace("x", "1").replace("y", "2").replace("^", "*"))
            #             if val >= len(wl):
            #                 wl += [0] * (val - len(wl) + 1)
            #             wl[val] += 1

            # print tuple([wl[k] for k in sorted(wl)])
            wl = [0] * (sum(i + 1 for i in lbl) + 1)
            for i in xrange(len(monomials)):
                for j in xrange(i + 2):
                    amonomial = f.coefficient(monomials[i][j])(x=0, y=0)
                    if amonomial != 0:
                        wl[monomials_weights[i][j]] += amonomial

            # print t, lbl, f, wl
            d[tuple(wl)].append((f, t, lbl))
            # d[str(wl)] += 1
    return d
Example #4
0
def path_small_unjumble_labeled(n):
    d = defaultdict(list)
    for t in listAllFreeTrees(n):
        g, edge_lbls = gen_tree_edge_list_from_list(t)
        # d[path_labeled_f({}, g).expand()] += 1
        for lbl in get_labeled_graphs(t, 2, True):
            d[path_labeled_f({}, edge_lbls, lbl, g).expand()].append((tuple(t), lbl))
            # d[path_labeled_f({}, edge_lbls, lbl, g).expand()] += 1
    return d
Example #5
0
def max_path_small_unjumble(n):
    d = defaultdict(list)
    for t in listAllFreeTrees(n):
        # print t
        g, edge_lbls = gen_tree_edge_list_from_list(t)
        mp = find_maximal_paths(g)
        # print mp
        for lbl in get_labeled_graphs(t, 2, True):
            coloring = []
            for mpindex in xrange(len(mp)):
                p = mp[mpindex]
                colorcnt = [0, 0]
                for i in xrange(1, len(p)):
                    x, y = min(p[i], p[i - 1]), max(p[i], p[i - 1])
                    colorcnt[lbl[edge_lbls[(x, y)]]] += 1
                # print "".join(map(str, get_smaller_color(acoloring))), lbl
                coloring.append(tuple(colorcnt))
            d[tuple(sorted(coloring))].append((tuple(t), lbl))
            # d[tuple(sorted(coloring))] += 1
            # print lbl, str(coloring)
    # print d
    return d
Example #6
0
def max_path_large_unjumble(n):
    d = defaultdict(list)
    for t in listAllFreeTrees(n):
        g, edge_lbls = gen_tree_edge_list_from_list(t)
        d[tuple([len(p) for p in find_maximal_paths(g)])].append(tuple(t))
    return d