Example #1
0
def stn_check(st):
    #S has the minimum value
    assert st.s['stn'] == 1
    #T has the maximum value
    for n in st.nodes.values():
        if n != st.t:
            assert n['stn'] < st.t['stn']
    #TODO: complete st-numbering check
    info('The ST-numbering has been properly computed')
Example #2
0
 def plugin_start(self, name):
     """Starts a plugin.
     @param name The name of the plugin. See plugin_base.PluginBase.name.
     """
     if not name in self._plugins:
         return False
     info('starting plugin "%s"' % name)
     self._plugins[name].start()
     return True
Example #3
0
 def __init__(self, start, end):
     if type(start) is Point:
         self.start = start
     else:
         self.start = Point(*start)
     if type(end) is Point:
         self.end = end
     else:
         self.end = Point(*end)
     if self.is_point():
         info('%s:This line is a point!' % str(self))
Example #4
0
    def draw(self):
        g = self.graph
        allocated_col = [] #int TODO: do we really need it?
        pending_edges = {} #node_from.id():[col1, col2]
        avail_sides = {}
        nodes = g.nodes.values()

        # Initialize avail_sides
        for n in nodes:
            #-1 is left, 0 is down, 1 is right, 2 is up
            avail_sides[n.id()] = [-1, 0, 1, 2]

        #### Routine definitions
        def get_position(node):
            return self.positions[node.id()]
        def set_position(node, column, line):
            '''Put a node somewhere'''
            self.positions[node.id()] = Point(column, line)
            return self.positions[node.id()]
        def allocate_column(node, column=None):
            #If none, uses himself column
            if column is None:
                column = get_position(node).x
            allocated_col.append(column)
            if node.id() in pending_edges:
                pending_edges[node.id()].append(column)
            else:
                pending_edges[node.id()] = [column]
        allocate_column.leftish_col = 0
        allocate_column.rightish_col = 3
        def allocate_column_left(node):
            allocate_column.leftish_col -= 1
            allocate_column(node, allocate_column.leftish_col)
        def allocate_column_right(node):
            allocate_column.rightish_col += 1
            allocate_column(node, allocate_column.rightish_col)

        def stn(node):
            return node['stn']
        def connect_points(a, b, col):
            if avail_sides[b.id()] == [2]: #Last, 4-degree node
                pl = Polyline.hvh(get_position(a), get_position(b)+(0,1), col)
                pl.add_line(Line(get_position(b)+(0,1), get_position(b)))
            else:
                pl = Polyline.hvh(get_position(a), get_position(b), col)
                if get_position(b).x < col:
                    avail_sides[b.id()].remove(1)
                elif get_position(b).x == col:
                    avail_sides[b.id()].remove(0)
                else:
                    avail_sides[b.id()].remove(-1)

            self.lines.append(pl)
            if get_position(a).x < col:
                avail_sides[a.id()].remove(1)
            elif get_position(a).x == col:
                avail_sides[a.id()].remove(2)
            else:
                avail_sides[a.id()].remove(-1)

            pending_edges[a.id()].remove(col)

            return pl

        ### End routine definition

        #Sorting by ST-Numbering is the way!
        nodes.sort(key=stn)
        debug(str([(n.id(), n['stn']) for n in  nodes]))

        #Draw 1, 2 and the edge between them
        v1 = nodes.pop(0)
        v2 = nodes.pop(0)
        set_position(v1, 0, 0) #The center of drawing is v1
        set_position(v2, 3, 0)
        v1_v2_line = Polyline()
        v1_v2_line.add_line(Line((0,0), (0, -1)))
        v1_v2_line.add_line(Line((0,-1), (3, -1)))
        v1_v2_line.add_line(Line((3,-1), (3, 0)))
        self.lines.append(v1_v2_line)
        #So ugly
        pending_edges[v1.id()] = []
        pending_edges[v2.id()] = []
        allocate_column(v1)
        if len(g.get_adiacents(v1)) > 2:
            allocate_column(v1, 1)
        if len(g.get_adiacents(v1)) > 3:
            allocate_column_left(v1)
        allocate_column(v2)
        if len(g.get_adiacents(v2)) > 2:
            allocate_column(v2, 2)
        if len(g.get_adiacents(v2)) > 3:
            allocate_column_right(v2)

        line = 1
        v = nodes.pop(0)
        while len(nodes) >= 0:
            debug('now on %s' % v.name)
            debug(str(pending_edges))
            #Choose column
            available_cols = []
            for x in g.get_adiacents(v):
                if x.id() in pending_edges:
                    for edge in pending_edges[x.id()]:
                        available_cols.append((edge, x.id()))
            if not available_cols:
                raise Exception('sth went wrong: no available columns!')
            #col is the chosen column
            degree = len([x for x in g.get_adiacents(v) if x['stn'] < v['stn']])
            debug('Choosing col for %s from %s' % (v.id(), str(available_cols)))
            col = available_cols[len(available_cols)/2]
            chosen_col = col_choose.column_choose(available_cols)
            col = chosen_col[(len(chosen_col)-1)/2][0]
            set_position(v, col, line)
            debug('Chosen: %d' % col)
            for column in chosen_col:
                debug('Connect %s to %s through %d' % (column[1], v.id(), column[0]))
                connect_points(g.nodes[column[1]], v, column[0])

            out_degree = len(g.get_adiacents(v)) - 4 + len(avail_sides[v.id()])
            debug(str(avail_sides[v.id()]))
            debug('%s has %d out_degree' % (v.id(), out_degree))
            allocate_column(v)
            if out_degree > 1:
                if -1 in avail_sides[v.id()]:
                    allocate_column_left(v)
                    if out_degree > 2:
                        assert 1 in avail_sides[v.id()]
                        allocate_column_right(v)
                else:
                    assert out_degree == 2
                    allocate_column_right(v)

            line += 1
            try:
                v = nodes.pop(0)
            except:
                break
        info(str(self.positions))