Ejemplo n.º 1
0
    def sorted(self):
        dag = DAG()
        imap = dict()
        vmap = dict()

        for _ in self.interceptors:
            k = self.key(_.interceptor)
            imap[k] = _
            vmap[k] = dag.add(k)

        for k in imap:
            _ = imap[k]
            v = vmap[k]

            if _.before:
                for o in _.before:
                    o = vmap[self.key(o)]
                    dag.add_edge(v, o)

            if _.after:
                for o in _.after:
                    o = vmap[self.key(o)]
                    dag.add_edge(o, v)

        rs = dag.topologicaly()
        s = [imap[k].interceptor for k in rs]
        return s
Ejemplo n.º 2
0
    def sorted(self):
        dag = DAG()
        imap = dict()
        vmap = dict()

        for _ in self.interceptors:
            k = self.key(_.interceptor)
            imap[k] = _
            vmap[k] = dag.add(k)

        for k in imap:
            _ = imap[k]
            v = vmap[k]

            if _.before:
                for o in _.before:
                    o = vmap[self.key(o)]
                    dag.add_edge(v, o)

            if _.after:
                for o in _.after:
                    o = vmap[self.key(o)]
                    dag.add_edge(o, v)

        rs = dag.topologicaly()
        s = [imap[k].interceptor for k in rs]
        return s
Ejemplo n.º 3
0
    def test_cicle_detect_tuples(self):
        '''
        Tests the verticles order in:

        a --> b --> c --> a

        '''

        dag = DAG()
        a = dag.add(1)
        b = dag.add((1, 'b', None))
        c = dag.add(frozenset((2, 'c')))

        dag.add_edge(a, b)
        dag.add_edge(b, c)

        try:
            # add cicle at a --> b --> c --> a
            dag.add_edge(c, a)
            dag.add_edge(a, c)
            raise Exception("Cycle not detected")
        except CycleDetectedException:
            pass
Ejemplo n.º 4
0
    def test_cicle_detect_tuples(self):
        '''
        Tests the verticles order in:

        a --> b --> c --> a

        '''

        dag = DAG()
        a = dag.add(1)
        b = dag.add((1, 'b', None))
        c = dag.add(frozenset((2, 'c')))

        dag.add_edge(a, b)
        dag.add_edge(b, c)

        try:
            # add cicle at a --> b --> c --> a
            dag.add_edge(c, a)
            dag.add_edge(a, c)
            raise Exception("Cycle not detected")
        except CycleDetectedException:
            pass
Ejemplo n.º 5
0
    def test_simple(self):
        '''
        Tests the verticles order in:

        C --> A --> B --> D
        '''

        dag = DAG()
        a = dag.add("A")
        b = dag.add("B")
        c = dag.add("C")
        d = dag.add("D")

        dag.add_edge(c, a)
        dag.add_edge(a, b)
        dag.add_edge(b, d)
        dag.add_edge(c, d)

        rs = dag.topologicaly()

        self.assertTrue(rs.index("C") < rs.index("A"))
        self.assertTrue(rs.index("A") < rs.index("B"))
        self.assertTrue(rs.index("B") < rs.index("D"))
        self.assertTrue(rs.index("C") < rs.index("D"))
Ejemplo n.º 6
0
    def test_simple(self):
        '''
        Tests the verticles order in:

        C --> A --> B --> D
        '''

        dag = DAG()
        a = dag.add("A")
        b = dag.add("B")
        c = dag.add("C")
        d = dag.add("D")

        dag.add_edge(c, a)
        dag.add_edge(a, b)
        dag.add_edge(b, d)
        dag.add_edge(c, d)

        rs = dag.topologicaly()

        self.assertTrue(rs.index("C") < rs.index("A"))
        self.assertTrue(rs.index("A") < rs.index("B"))
        self.assertTrue(rs.index("B") < rs.index("D"))
        self.assertTrue(rs.index("C") < rs.index("D"))
Ejemplo n.º 7
0
 def test_cicle_detect(self):
     '''
     Tests the verticles order in:
     
     C --> A --> B --> D -> C
     '''
     
     dag = DAG()
     a = dag.add("A")
     b = dag.add("B")
     c = dag.add("C")
     d = dag.add("D")
     
     dag.add_edge(c, a)
     dag.add_edge(a, b)
     dag.add_edge(b, d)
     dag.add_edge(c, d)
     
     try:
         # add cicle at A --> C --> A
         dag.add_edge(a, c)
         raise Exception("Cycle not detected")
     except CycleDetectedException: pass
Ejemplo n.º 8
0
    def test_cicle_detect(self):
        '''
        Tests the verticles order in:

        C --> A --> B --> D -> C
        '''

        dag = DAG()
        a = dag.add("A")
        b = dag.add("B")
        c = dag.add("C")
        d = dag.add("D")

        dag.add_edge(c, a)
        dag.add_edge(a, b)
        dag.add_edge(b, d)
        dag.add_edge(c, d)

        try:
            # add cicle at A --> C --> A
            dag.add_edge(a, c)
            raise Exception("Cycle not detected")
        except CycleDetectedException:
            pass
Ejemplo n.º 9
0
'''
Created on Oct 3, 2012

@author: Moises P. Sena
'''
from sdag2 import DAG

dag = DAG()
a = dag.add("A")
b = dag.add("B")
c = dag.add("C")
d = dag.add("D")

dag.add_edge(c, a)
dag.add_edge(a, b)
dag.add_edge(b, d)
dag.add_edge(c, d)

rs = dag.topologicaly()
# Order is: C --> A --> B --> D
print("Order is: %s" % (" --> ".join(rs)))

assert rs.index("C") < rs.index("A")
assert rs.index("A") < rs.index("B")
assert rs.index("B") < rs.index("D")
assert rs.index("C") < rs.index("D")
Ejemplo n.º 10
0
i = 0

while line:
    line = line.strip()
    i += 1
    if not line:
        stderr.write("[WARN]: Line %s is empty.\n" % i)
        continue
    elif line == options.quit_sequence:
        break

    parts = split(options.separator, line)

    try:
        if len(parts) == 2:
            dag.add_edge(parts[0], parts[1])
        elif len(parts) == 1:
            dag.add(parts[0])
        else:
            stderr.write("[ERROR]: Line %s contains more 2 items.\n" % i)
            exit(1)

        line = inf.readline()
    except CycleDetectedException as ex:
        stderr.write("[ERROR]: %s.\n" % ex)
        exit(1)

for l in dag.topologicaly(gen=True):
    outf.write(l)
    outf.write("\n")
Ejemplo n.º 11
0
i = 0

while line:
    line = line.strip()
    i += 1
    if not line:
        stderr.write("[WARN]: Line %s is empty.\n" % i)
        continue
    elif line == options.quit_sequence:
        break

    parts = split(options.separator, line)

    try:
        if len(parts) == 2:
            dag.add_edge(parts[0], parts[1])
        elif len(parts) == 1:
            dag.add(parts[0])
        else:
            stderr.write("[ERROR]: Line %s contains more 2 items.\n" % i)
            exit(1)

        line = inf.readline()
    except CycleDetectedException as ex:
        stderr.write("[ERROR]: %s.\n" % ex)
        exit(1)

for l in dag.topologicaly(gen=True):
    outf.write(l)
    outf.write("\n")
Ejemplo n.º 12
0
"""
Created on Oct 3, 2012

@author: Moises P. Sena
"""
from sdag2 import DAG

dag = DAG()
a = dag.add("A")
b = dag.add("B")
c = dag.add("C")
d = dag.add("D")

dag.add_edge(c, a)
dag.add_edge(a, b)
dag.add_edge(b, d)
dag.add_edge(c, d)

rs = dag.topologicaly()
# Order is: C --> A --> B --> D
print("Order is: %s" % (" --> ".join(rs)))

assert rs.index("C") < rs.index("A")
assert rs.index("A") < rs.index("B")
assert rs.index("B") < rs.index("D")
assert rs.index("C") < rs.index("D")