예제 #1
0
def write_splition(simschema, splition, filename="Subgraph"):
    """
    try load_split
    generate subgraphs
    write subgraphs
    """
    splition = load_split(splition)
    if splition == False:
        return None
    order = simschema.ordered
    subgraphs, _ = simschema.gen_subgraph(splition)
    multidot = MultiDot(filename)
    for graph in subgraphs:
        nodes = graph._graph
        dot = multidot.get_dot()
        for index in range(len(nodes)):
            start_node = nodes[index]
            for end_node in start_node:
                dot.add_edge(order[index], order[end_node[0]])
        dot.finish_output()
예제 #2
0
    def write_cyclic_graph(self, bdot, name="C"):
        """
        output dot graph with core cyclic component
        """
        basename = name
        multidot = MultiDot(basename)
        relations = self.get_graph_from_schema()
        graph = Graph(relations)
        ugraph = graph.get_undirected()
        cycles = self.get_cycle_basis(ugraph._graph)
        if len(cycles) == 0:
            return False
        nodes = None
        order = self.ordered
        for cycle in cycles:
#            print "--------------cycle----------"
#            print [order[node] for node in cycle]
            nodes = cycle
            dot = multidot.get_dot()
            for node in nodes:
                start_node = relations[node]
                for end_node in start_node:
                    if end_node in nodes:
                        dot.add_edge(order[node], order[end_node])
            dot.finish_output()

        nodes = set([])
        for cycle in cycles:
            nodes = nodes.union(set(cycle))
        for node in nodes:
            start_node = relations[node]
            for end_node in start_node:
                if end_node in nodes:
                    bdot.add_edge(order[node], order[end_node])
        bdot.finish_output()
        return True