Ejemplo n.º 1
0
def example():
    os.makedirs("./examples", exist_ok=True)
    files = glob.glob('./examples/*')
    for f in files:
        os.remove(f)
    rt = RootedTree.load(0, "example4_1.txt")
    print(copmanager.getCopNumber(rt))
    treedrawer.drawRootedTree(rt,
                              True,
                              show=False,
                              savePath="examples/example4.1.pdf")

    rt = RootedTree.load(0, "example4_2.txt")
    print(copmanager.getCopNumber(rt))
    treedrawer.drawRootedTree(rt,
                              True,
                              show=False,
                              savePath="examples/example4.2.pdf")

    rt = RootedTree.load(0, "example4_3.txt")
    print(copmanager.getCopNumber(rt))
    treedrawer.drawRootedTree(rt,
                              True,
                              show=False,
                              savePath="examples/example4.3.pdf")

    rt = RootedTree.load(5, "example4_3.txt")
    print(copmanager.getCopNumber(rt))
    treedrawer.drawRootedTree(rt,
                              True,
                              show=False,
                              savePath="examples/example4.4.pdf")

    rt = RootedTree.load(0, "example4_5.txt")
    x1 = 11
    x2 = 12
    x3 = 13
    rt.labels = {
        0: None,
        1: Label.make(4, constant.PERPEN_SYM, 0, 0, 1, 0),
        2: Label.make(4, constant.PERPEN_SYM, 0, 0, 1, 0),
        3: Label.make(5, x1, 0, 0, 0, 2).append(2, constant.PERPEN_SYM),
        4: Label.make(8, x2, 0, 0, 0, 0).append(4, 4),
        5: Label.make(6, x3, 0, 0, 0, 0).append(2, 5),
        11: Label.make(5, 11),
        12: Label.make(8, 12),
        13: Label.make(6, 13)
    }
    print(copmanager.getCopNumber(rt))
    treedrawer.drawRootedTree(rt,
                              True,
                              show=False,
                              savePath="examples/example4.5.pdf")
Ejemplo n.º 2
0
 def test_findX(self):
     K = [9, 8, 6]
     L = [
         SV(9, 1),
         SV(8, 3),
         SV(6, 4),
         SV(4, 9),
         SV(4, constant.PERPEN_SYM)
     ]
     self.assertEqual(
         copmanager.findX(L, K),
         Label.make(9, 1).append(8, 3).append(6, constant.PERPEN_SYM))
Ejemplo n.º 3
0
 def test_example4_5(self):
     rt = RootedTree.load(0, "example4_5.txt")
     x1 = 11
     x2 = 12
     x3 = 13
     rt.labels = {
         0: None,
         1: Label.make(4, constant.PERPEN_SYM, 0, 0, 1, 0),
         2: Label.make(4, constant.PERPEN_SYM, 0, 0, 1, 0),
         3: Label.make(5, x1, 0, 0, 0, 2).append(2, constant.PERPEN_SYM),
         4: Label.make(8, x2, 0, 0, 0, 0).append(4, 4),
         5: Label.make(6, x3, 0, 0, 0, 0).append(2, 5),
         11: Label.make(5, 11),
         12: Label.make(8, 12),
         13: Label.make(6, 13)
     }
     self.assertEqual(copmanager.getCopNumber(rt),
                      Label.make(8, x2).append(7, constant.PERPEN_SYM))
Ejemplo n.º 4
0
 def test_example4_4(self):
     rt = RootedTree.load(5, "example4_3.txt")
     self.assertEqual(copmanager.getCopNumber(rt),
                      Label.make(2, constant.PERPEN_SYM, 0, 0, 1, 0))
Ejemplo n.º 5
0
def compute_label(rt, u):
    '''rt = T1
    return T1u[u]'''
    if (len(rt.descendant(u)) == 0):
        rt.labels[u] = Label.noChild()
        return rt.labels[u]

    logger.debug("start")
    k = c1Star(subForest(rt, u))
    # ^k_wb
    numKWb = numKWeakBranChild(rt, u, k)
    # ^k_pb
    numKPb = numKPreBranChild(rt, u, k)
    # ^k_c
    numKC = numKC1Child(rt, u, k)
    # h^k_w
    hkW = maxWeaklyCounter(rt, u, k)
    # h^k
    hk = maxInitialCounter(rt, u, k)

    logger.debug(
        f"u = {u}, k = {k}, numKWb = {numKWb}, numKPb = {numKPb}, numKC ={numKC}, hkW = {hkW}, hk={hk}"
    )

    # 1
    if numKWb > 1:
        rt.labels[u] = Label.make(k + 1, constant.PERPEN_SYM)
        logger.debug("#1 is triggered")
    # 3
    elif numKWb == 1 and numKPb >= 1:
        rt.labels[u] = Label.make(k + 1, constant.PERPEN_SYM, 0, 0, 0, 0)
        logger.debug("#3 is triggered")

    # 5
    elif (numKWb == 1 and numKPb == 0 and numKC >= 2):
        # 6
        if hkW == 2:
            rt.labels[u] = Label.make(k + 1, constant.PERPEN_SYM, 0, 0, 0, 0)
            logger.debug("#6 is triggered")
        # 8
        elif (hkW == 1 and hk >= 1):
            rt.labels[u] = Label.make(k + 1, constant.PERPEN_SYM, 0, 0, 0, 0)
            logger.debug("#8 is triggered")
        # 10
        elif (hkW == 1 and hk == 0):
            rt.labels[u] = Label.make(k, constant.PERPEN_SYM, 1, 2, 0, 0)
            logger.debug("#10 is triggered")
        # 12
        elif (hkW == 0 and hk == 2):
            rt.labels[u] = Label.make(k + 1, constant.PERPEN_SYM, 0, 0, 0, 0)
            logger.debug("#12 is triggered")
        # 14
        elif (hkW == 0 and hk <= 1):
            rt.labels[u] = Label.make(k, constant.PERPEN_SYM, 1, 1, 0, 0)
            logger.debug("#14 is triggered")
    # 16
    elif numKWb == 1 and numKC == 1:
        # 17
        if hkW == 2:
            rt.labels[u] = Label.make(k, u)
            logger.debug("#17 is triggered")
        # 19
        elif hkW == 1:
            rt.labels[u] = Label.make(k, constant.PERPEN_SYM, 1, 2, 0, 0)
            logger.debug("#19 is triggered")
        # 21
        elif hkW == 0:
            rt.labels[u] = Label.make(k, constant.PERPEN_SYM, 1, 1, 0, 0)
            logger.debug("#21 is triggered")
    # 23
    elif numKWb == 0:
        # 24
        if numKPb >= 3:
            rt.labels[u] = Label.make(k + 1, constant.PERPEN_SYM)
            logger.debug("#24 is triggered")
        # 26
        elif numKPb == 2:
            rt.labels[u] = Label.make(k, constant.PERPEN_SYM, 1, 0, 0, 0)
            logger.debug("#26 is triggered")
        # 28
        elif numKPb == 1:
            rt.labels[u] = Label.make(k, constant.PERPEN_SYM, 0, 0, 1, 0)
            logger.debug("#28 is triggered")
        # 30
        elif numKPb == 0:
            # 31
            if hk == 2:
                rt.labels[u] = Label.make(k, constant.PERPEN_SYM, 0, 0, 1, 0)
                logger.debug("#31 is triggered")
            # 33
            elif hk == 1:
                rt.labels[u] = Label.make(k, constant.PERPEN_SYM, 0, 0, 0, 2)
                logger.debug("#33 is triggered")
            # 35
            elif hk == 0:
                rt.labels[u] = Label.make(k, constant.PERPEN_SYM, 0, 0, 0, 1)
                logger.debug("#35 is triggered")
    if rt.labels[u] == None:
        raise Exception("nothing is changed from compute-label")
    return rt.labels[u]