How to use the altgraph.Graph function in altgraph

To help you get started, we’ve selected a few altgraph examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyinstaller / pyinstaller / tests / unit / test_modulegraph / test_modulegraph.py View on Github external
def test_constructor(self):
        o = modulegraph.ModuleGraph()
        self.assertTrue(o.path is sys.path)
        self.assertEqual(o.lazynodes, {})
        self.assertEqual(o.replace_paths, ())
        self.assertEqual(o.debug, 0)

        # Stricter tests would be nice, but that requires
        # better control over what's on sys.path
        self.assertIsInstance(o.nspackages, dict)

        g = Graph.Graph()
        o = modulegraph.ModuleGraph(['a', 'b', 'c'], ['modA'], [
                ('fromA', 'toB'), ('fromC', 'toD')],
                {
                    'modA': ['modB', 'modC'],
                    'modC': ['modE', 'modF'],
                }, g, 1)
        self.assertEqual(o.path, ['a', 'b', 'c'])
        self.assertEqual(o.lazynodes, {
            'modA': None,
            'modC': ['modE', 'modF'],
        })
        self.assertEqual(o.replace_paths, [('fromA', 'toB'), ('fromC', 'toD')])
        self.assertEqual(o.nspackages, {})
        self.assertTrue(o.graph is g)
        self.assertEqual(o.debug, 1)
github salilab / imp / modules / kernel / pyext / src / _graph_show.py View on Github external
def show_altgraph(g):
    def clean(name):
        try:
            n0 = name.get_name()
        except:
            n0 = str(name)
        n1 = str(n0).replace('"', '')
        n2 = n1.replace("\n", '')
        return n2
    import altgraph
    from altgraph import Graph, Dot
    graph = Graph.Graph()
    for i, v in enumerate(g.get_vertices()):
        graph.add_node(i)  # , node_data=g.get_vertex_name(v)
    for i, v in enumerate(g.get_vertices()):
        for n in g.get_out_neighbors(v):
            graph.add_edge(v, n)
    dot = Dot.Dot(graph)  # , graph_type="digraph"
    for i, v in enumerate(g.get_vertices()):
        dot.node_style(i, label=clean(g.get_vertex_name(v)))
    dot.display()
github hakuna-m / wubiuefi / src / pypack / altgraph / GraphUtil.py View on Github external
def generate_scale_free_graph(steps, growth_num, self_loops=False, multi_edges=False):
    '''
    Generates and returns a L{Graph.Graph} instance that will have C{steps*growth_num} nodes
    and a scale free (powerlaw) connectivity. Starting with a fully connected graph with C{growth_num} nodes
    at every step C{growth_num} nodes are added to the graph and are connected to existing nodes with
    a probability proportional to the degree of these existing nodes.
    '''
    graph = Graph.Graph()

    # initialize the graph
    store = []
    for i in range(growth_num):
        store   += [ i ] * (growth_num - 1)
        for j in range(i + 1, growth_num):
            graph.add_edge(i,j)

    # generate
    for node in range(growth_num, (steps-1) * growth_num):
        graph.add_node(node)
        while ( graph.out_degree(node) < growth_num ):
            nbr = random.choice(store)

            # loop defense
            if node == nbr and not self_loops:
github HenriWahl / Nagstamon / build / helpers / pyinstaller-2.1 / PyInstaller / lib / altgraph / GraphUtil.py View on Github external
def generate_scale_free_graph(steps, growth_num, self_loops=False, multi_edges=False):
    '''
    Generates and returns a :py:class:`~altgraph.Graph.Graph` instance that will have *steps* \* *growth_num* nodes
    and a scale free (powerlaw) connectivity. Starting with a fully connected graph with *growth_num* nodes
    at every step *growth_num* nodes are added to the graph and are connected to existing nodes with
    a probability proportional to the degree of these existing nodes.
    '''
    # FIXME: The code doesn't seem to do what the documentation claims.
    graph = Graph.Graph()

    # initialize the graph
    store = []
    for i in range(growth_num):
        #store   += [ i ] * (growth_num - 1)
        for j in range(i + 1, growth_num):
            store.append(i)
            store.append(j)
            graph.add_edge(i,j)

    # generate
    for node in range(growth_num, steps * growth_num):
        graph.add_node(node)
        while ( graph.out_degree(node) < growth_num ):
            nbr = random.choice(store)
github HenriWahl / Nagstamon / build / helpers / pyinstaller-2.1 / PyInstaller / lib / altgraph / GraphUtil.py View on Github external
def generate_random_graph(node_num, edge_num, self_loops=False, multi_edges=False):
    '''
    Generates and returns a :py:class:`~altgraph.Graph.Graph` instance with *node_num* nodes
    randomly connected by *edge_num* edges.
    '''
    g = Graph.Graph()

    if not multi_edges:
        if self_loops:
            max_edges = node_num * node_num
        else:
            max_edges = node_num * (node_num-1)

        if edge_num > max_edges:
            raise GraphError("inconsistent arguments to 'generate_random_graph'")

    nodes = range(node_num)

    for node in nodes:
        g.add_node(node)

    while 1:
github Synss / macports_deptree / port_deptree.py View on Github external
def make_stats(graph):
    """Return the stats for `graph`."""
    stats = dict(missing=0,
                 installed=0,
                 outdated=0,
                 total=graph.number_of_nodes())
    for node in graph:
        node_data = graph.node_data(node)
        stats[node_data.status] += 1
    return stats


if __name__ == '__main__':
    graph = Graph.Graph()
    reduce = False
    commandline = {}
    try:
        if not sys.argv[1:]:
            raise RuntimeError
        for arg in sys.argv[1:]:
            if arg.startswith("@"):
                continue
            elif arg.startswith("--min"):
                reduce = True
            elif not (arg.startswith("+") or arg.startswith("-")):
                portname = arg
                commandline[portname] = []
            else:
                commandline[portname].append(arg)
    except:

altgraph

Python graph (network) package

MIT
Latest version published 7 months ago

Package Health Score

73 / 100
Full package analysis

Similar packages