• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python networkx.topological_sort函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中networkx.topological_sort函数的典型用法代码示例。如果您正苦于以下问题:Python topological_sort函数的具体用法?Python topological_sort怎么用?Python topological_sort使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了topological_sort函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: add_edges_from

    def add_edges_from(self, ebunch, attr_dict=None, **attr):
        """Add all the edges in ebunch.
        Parameters
        ----------
        ebunch : container of edges
            Each edge given in the container will be added to the
            graph. The edges must be given as as 2-tuples (u,v) or
            3-tuples (u,v,d) where d is a dictionary containing edge
            data.
        attr_dict : dictionary, optional (default= no attributes)
            Dictionary of edge attributes.  Key/value pairs will
            update existing data associated with each edge.
        attr : keyword arguments, optional
            Edge data (or labels or objects) can be assigned using
            keyword arguments.

        Enusres No cycles are in this directed graph (DAG)
      
        """
        # set up attribute dict
        if attr_dict is None:
            attr_dict = attr
        else:
            try:
                attr_dict.update(attr)
            except AttributeError:
                raise NetworkXError("The attr_dict argument must be a dict.")
        # process ebunch
        for e in ebunch:
            ne = len(e)
            if ne == 3:
                u, v, dd = e
                assert hasattr(dd, "update")
            elif ne == 2:
                u, v = e
                dd = {}
            else:
                raise NetworkXError("Edge tuple %s must be a 2-tuple or 3-tuple." % (e,))
            if u not in self.succ:
                self.succ[u] = {}
                self.pred[u] = {}
                self.node[u] = {}
            if v not in self.succ:
                self.succ[v] = {}
                self.pred[v] = {}
                self.node[v] = {}
            datadict = self.adj[u].get(v, {})
            datadict.update(attr_dict)
            datadict.update(dd)
            self.succ[u][v] = datadict
            self.pred[v][u] = datadict

            # make sure it's a DAG
            try:
                networkx.topological_sort(self)
            except networkx.NetworkXUnfeasible:
                self.remove_edge(u, v)
                raise networkx.NetworkXUnfeasible(
                    "Graph contains a cycle! DAG is acyclic! Edge " + u + "-" + v + " cannot be added."
                )
开发者ID:saherahwal,项目名称:Mining-Goal-Networks,代码行数:60,代码来源:EntityNW.py


示例2: evaluate

 def evaluate(self, x):
     # XXX: this is a massive hack
     x = x[::-1]
     assert self.circuit
     g = self.circuit.copy()
     for node in nx.topological_sort(g):
         if 'gate' not in g.node[node]:
             if g.node[node]['label'][0].startswith('x'):
                 g.add_node(node, value=int(x[node]))
             else:
                 g.add_node(node, value=int(g.node[node]['value']))
         elif g.node[node]['gate'] in ('ADD', 'MUL', 'SUB'):
             keys = g.pred[node].keys()
             if len(keys) == 1:
                 idx1 = idx2 = keys[0]
             else:
                 assert(len(keys) == 2)
                 idx1 = g.pred[node].keys()[0]
                 idx2 = g.pred[node].keys()[1]
             if g.node[node]['gate'] == 'ADD':
                 value = g.node[idx1]['value'] + g.node[idx2]['value']
             elif g.node[node]['gate'] == 'SUB':
                 value = g.node[idx1]['value'] - g.node[idx2]['value']
             elif g.node[node]['gate'] == 'MUL':
                 value = g.node[idx1]['value'] * g.node[idx2]['value']
             g.add_node(node, value=value)
         else:
             raise Exception('Unable to evaluate')
     idx = nx.topological_sort(g)[-1]
     return g.node[idx]['value'] != 0
开发者ID:dmwit,项目名称:obfuscation,代码行数:30,代码来源:z_obfuscator.py


示例3: evaluate

 def evaluate(self, x):
     # XXX: this is a massive hack
     x = x[::-1]
     assert self.circuit
     g = self.circuit.copy()
     for node in nx.topological_sort(g):
         if "gate" not in g.node[node]:
             if g.node[node]["label"][0].startswith("x"):
                 g.add_node(node, value=int(x[node]))
             else:
                 g.add_node(node, value=int(g.node[node]["value"]))
         elif g.node[node]["gate"] in ("ADD", "MUL"):
             keys = g.pred[node].keys()
             if len(keys) == 1:
                 idx1 = idx2 = keys[0]
             else:
                 assert len(keys) == 2
                 idx1 = g.pred[node].keys()[0]
                 idx2 = g.pred[node].keys()[1]
             if g.node[node]["gate"] == "ADD":
                 value = g.node[idx1]["value"] + g.node[idx2]["value"]
             elif g.node[node]["gate"] == "MUL":
                 value = g.node[idx1]["value"] * g.node[idx2]["value"]
             g.add_node(node, value=value)
         else:
             raise Exception("Unable to evaluate")
     idx = nx.topological_sort(g)[-1]
     return g.node[idx]["value"] != 0
开发者ID:CyberPoint,项目名称:Obfuscation,代码行数:28,代码来源:z_obfuscator.py


示例4: ensure_dependencies

    def ensure_dependencies(request):
        r"""
        CommandLine:
            python -m dtool.base --exec-BaseRequest.ensure_dependencies

        Example:
            >>> # ENABLE_DOCTEST
            >>> from dtool.base import *  # NOQA
            >>> from dtool.example_depcache import testdata_depc
            >>> depc = testdata_depc()
            >>> request = depc.new_request('vsmany', [1, 2], [2, 3, 4])
            >>> request.ensure_dependencies()
        """
        import networkx as nx
        depc = request.depc
        if False:
            dependencies = nx.ancestors(depc.graph, request.tablename)
            subgraph = depc.graph.subgraph(set.union(dependencies, {request.tablename}))
            dependency_order = nx.topological_sort(subgraph)
            root = dependency_order[0]
            [nx.algorithms.dijkstra_path(subgraph, root, start)[:-1] +
             nx.algorithms.dijkstra_path(subgraph, start, request.tablename)
             for start in dependency_order]
        graph = depc.graph
        root = list(nx.topological_sort(graph))[0]
        edges = graph.edges()
        #parent_to_children = ut.edges_to_adjacency_list(edges)
        child_to_parents = ut.edges_to_adjacency_list([t[::-1] for t in edges])
        to_root = {request.tablename:
                   ut.paths_to_root(request.tablename, root, child_to_parents)}
        from_root = ut.reverse_path(to_root, root, child_to_parents)
        dependency_levels_ = ut.get_levels(from_root)
        dependency_levels = ut.longest_levels(dependency_levels_)

        true_order = ut.flatten(dependency_levels)[1:-1]
        #print('[req] Ensuring %s request dependencies: %r' % (request, true_order,))
        ut.colorprint(
            '[req] Ensuring request %s dependencies: %r' % (request, true_order,), 'yellow')
        for tablename in true_order:
            table = depc[tablename]
            if table.ismulti:
                pass
            else:
                # HACK FOR IBEIS
                all_aids = ut.flat_unique(request.qaids, request.daids)
                depc.get_rowids(tablename, all_aids)
                pass
            pass

        #zip(depc.get_implicit_edges())
        #zip(depc.get_implicit_edges())

        #raise NotImplementedError('todo')
        #depc = request.depc
        #parent_rowids = request.parent_rowids
        #config = request.config
        #rowid_dict = depc.get_all_descendant_rowids(
        #    request.tablename, root_rowids, config=config)
        pass
开发者ID:Erotemic,项目名称:dtool,代码行数:59,代码来源:base.py


示例5: test_nbunch_argument

 def test_nbunch_argument(self):
     G=nx.DiGraph()
     G.add_edges_from([(1,2), (2,3), (1,4), (1,5), (2,6)])
     assert_equal(nx.topological_sort(G), [1, 2, 3, 6, 4, 5])
     assert_equal(nx.topological_sort_recursive(G), [1, 5, 4, 2, 6, 3])
     assert_equal(nx.topological_sort(G,[1]), [1, 2, 3, 6, 4, 5])
     assert_equal(nx.topological_sort_recursive(G,[1]), [1, 5, 4, 2, 6, 3])
     assert_equal(nx.topological_sort(G,[5]), [5])
     assert_equal(nx.topological_sort_recursive(G,[5]), [5])
开发者ID:datachomper,项目名称:googleants,代码行数:9,代码来源:test_dag.py


示例6: _compute_lattice_monotonicity

    def _compute_lattice_monotonicity(self, reds, pis):
        """
        Infer the redundancy and partial information of lattice elements via lattice monotonicity.

        Parameters
        ----------
        reds : dict
            Currently known redundancy values.
        pis : dict
            Currently known partial information values.

        Returns
        -------
        reds : dict
            Updated redundancy values.
        pis : dict
            Updated partial information values.
        """
        # everything below a redundancy of 0 is a redundancy of 0
        nodes = list(nx.topological_sort(self._lattice))
        while nodes:
            node = nodes.pop(0)
            if node in reds and np.isclose(0, reds[node]):
                for n in descendants(self._lattice, node):
                    if n not in reds:
                        reds[n] = 0
                        nodes.remove(n)

        # everything above a redundancy of I(inputs, output) is I(inputs, output)
        nodes = list(reversed(list(nx.topological_sort(self._lattice))))
        while nodes:
            node = nodes.pop(0)
            if node in reds and np.isclose(reds[node], self._total):
                for n in ascendants(self._lattice, node):
                    if n not in reds:
                        reds[n] = self._total
                        nodes.remove(n)

        # if redundancy of A == redundancy of B, then for all A -> C -> B, redundancy of C = redundancy of A, B
        tops = [node for node in self._lattice if node in reds and any((n not in reds) for n in self._lattice[node])]
        bottoms = [node for node in self._lattice if
                   node in reds and any((n not in reds) for n in self._lattice.reverse()[node])]
        for top, bottom in product(tops, bottoms):
            if np.isclose(reds[top], reds[bottom], atol=1e-5, rtol=1e-5):
                for path in nx.all_simple_paths(self._lattice, top, bottom):
                    for node in path[1:-1]:
                        if node not in reds:
                            reds[node] = reds[top]

        # if redundancy of A is equal to the redundancy any of A's children, then pi(A) = 0
        for node in self._lattice:
            if node not in pis:
                if node in reds and all(n in reds for n in self._lattice[node]) and self._lattice[node]:
                    if any(np.isclose(reds[n], reds[node], atol=1e-5, rtol=1e-5) for n in self._lattice[node]):
                        pis[node] = 0

        return reds, pis
开发者ID:Autoplectic,项目名称:dit,代码行数:57,代码来源:pid.py


示例7: attempt_edge

 def attempt_edge(graph, a, b):
     a_gate, a_port = a
     b_gate, b_port = b
     graph.add_edge(a_gate, b_gate)
     try:
         nx.topological_sort(graph)
     except nx.NetworkXUnfeasible:
         graph.remove_edge(a_gate, b_gate)
         broken_up_links.append((a, b))
开发者ID:breuleux,项目名称:colonel,代码行数:9,代码来源:circuit.py


示例8: main

def main():
  log = logging.getLogger(__name__)
  logging.basicConfig(level = logging.INFO)

  backend = foradage.RECAST_Backend(2)

  g = adage.mk_dag()

  global_context = {
    'workdir':'/Users/lukas/Code/code-snippets/cap-schema-drafts/steer',
    'dataset':'user15.lheinric.p123/'
  }

  steps_graph = nx.DiGraph()
  workflow = json.load(open('capdata/workflow.json'))

  for step in workflow:
    steps_graph.add_node(step['name'],step)
    for x in step['dependencies']:
      steps_graph.add_edge(x,step['name'])

  rules = {}
  for stepname in nx.topological_sort(steps_graph):
      stepinfo = steps_graph.node[stepname]
      rule = foradage.RECAST_Rule(stepinfo,workflow,rules,global_context)
      rules[stepname] = rule

  adage.rundag(g,rules.values(), track = True, backend = backend)

  provgraph = nx.DiGraph()
  for x in nx.topological_sort(g):
    attr = g.node[x].copy()
    attr.update(color = 'red',label = g.getNode(x).name)
    provgraph.add_node(x,attr)
    nodeinfo =  g.getNode(x).task.node

    if 'used_inputs' in nodeinfo:
      for k,inputs_from_node in nodeinfo['used_inputs'].iteritems():
        for one in inputs_from_node:
          depname = 'output_{}_{}_{}'.format(k,one[0],one[1])
          provgraph.add_edge(depname,x)
    else:
      for pre in g.predecessors(x):
        provgraph.add_edge(pre,x)


    for k,v in g.getNode(x).result_of()['RECAST_metadata']['outputs'].iteritems():
      for i,y in enumerate(v):
        name = 'output_{}_{}_{}'.format(g.getNode(x).task.node['name'],k,i)
        provgraph.add_node(name,{'shape':'box','label':'{}_{}'.format(k,i),'color':'blue'})
        provgraph.add_edge(x,name)
        
  nx.write_dot(provgraph,'workflow_instance.dot')
  subprocess.call(['dot','-Tpdf','workflow_instance.dot'], stdout = open('workflow_instance.pdf','w'))
  nx.write_dot(steps_graph,'steps.dot')
  subprocess.call(['dot','-Tpdf','steps.dot'], stdout = open('steps.pdf','w'))
开发者ID:lukasheinrich,项目名称:code-snippets,代码行数:56,代码来源:steering.py


示例9: test_topological_sort2

    def test_topological_sort2(self):
        DG = nx.DiGraph({1: [2], 2: [3], 3: [4],
                         4: [5], 5: [1], 11: [12],
                         12: [13], 13: [14], 14: [15]})
        assert_raises(nx.NetworkXUnfeasible, consume, nx.topological_sort(DG))

        assert_false(nx.is_directed_acyclic_graph(DG))

        DG.remove_edge(1, 2)
        consume(nx.topological_sort(DG))
        assert_true(nx.is_directed_acyclic_graph(DG))
开发者ID:aparamon,项目名称:networkx,代码行数:11,代码来源:test_dag.py


示例10: __init__

    def __init__(self, equations):
        # Everythings must be an equation
        self.equations = equations
        self.equations_by_name = {}

        for eq in equations:
            if not isinstance(eq, Equation):
                raise RuntimeError("Non Equation found.")

            if eq.name in equations:
                raise RuntimeError("Equations names must be unique within a graph")
            self.equations_by_name[eq.name] = eq

        # Make a network from this. The first is the full network of both
        # equations and variables (a bipartite graph). The second is just the
        # network of causal variables (the project of the bipartite graph).
        full_network = nx.DiGraph()
        causal_network = nx.DiGraph()
        for p in equations:
            for i in p.inputs:
                full_network.add_edge(i, p)
            for o in p.outputs:
                full_network.add_edge(p, o)
            for i in p.inputs:
                for o in p.outputs:
                    causal_network.add_edge(i, o)

        self.full_network = full_network
        self.causal_network = causal_network

        # Nodes are either inputs, outputs, or inner
        self.inputs = set()
        self.outputs = set()
        self.inner = set()

        for n in self.causal_network.nodes():
            preds = self.full_network.predecessors(n)
            sucs = self.full_network.successors(n)
            if not preds:
                self.inputs.add(n)
            if not sucs:
                self.outputs.add(n)
            if preds and sucs:
                self.inner.add(n)

        # Sort all nodes into topological order. This allows us to calculate
        # the probabilities across the nodes in the right order, so that the
        # inputs for each player are always calculated in time (by previous
        # equations).
        self.ordered_variables = nx.topological_sort(self.causal_network)
        self.ordered_nodes = nx.topological_sort(self.full_network)

        self.graphviz_prettify(self.full_network)
        self.graphviz_prettify(self.causal_network)
开发者ID:brettc,项目名称:causalinfo,代码行数:54,代码来源:graph.py


示例11: add_edge

    def add_edge(self, u, v, attr_dict=None, **attr):
        """Add an edge between u and v.

        The nodes u and v will be automatically added if they are
        not already in the graph.

        Edge attributes can be specified with keywords or by providing
        a dictionary with key/value pairs.  See examples below.

        Ensures no cycle are introduced in the graph.
        
        Parameters
        ----------
        u,v : nodes
            Nodes can be, for example, strings or numbers.
            Nodes must be hashable (and not None) Python objects.
        attr_dict : dictionary, optional (default= no attributes)
            Dictionary of edge attributes.  Key/value pairs will
            update existing data associated with the edge.
        attr : keyword arguments, optional
            Edge data (or labels or objects) can be assigned using
            keyword arguments.

        """
        # set up attribute dict
        if attr_dict is None:
            attr_dict = attr
        else:
            try:
                attr_dict.update(attr)
            except AttributeError:
                raise NetworkXError("The attr_dict argument must be a dictionary.")
        # add nodes
        if u not in self.succ:
            self.succ[u] = {}
            self.pred[u] = {}
            self.node[u] = {}
        if v not in self.succ:
            self.succ[v] = {}
            self.pred[v] = {}
            self.node[v] = {}
        # add the edge
        datadict = self.adj[u].get(v, {})
        datadict.update(attr_dict)
        self.succ[u][v] = datadict
        self.pred[v][u] = datadict

        # make sure it's a DAG
        try:
            networkx.topological_sort(self)
        except networkx.NetworkXUnfeasible:
            self.remove_edge(u, v)
            raise networkx.NetworkXUnfeasible("Graph contains a cycle! DAG is acyclic!")
开发者ID:saherahwal,项目名称:Mining-Goal-Networks,代码行数:53,代码来源:EntityNW.py


示例12: test_topological_sort1

    def test_topological_sort1(self):
        DG=nx.DiGraph()
        DG.add_edges_from([(1,2),(1,3),(2,3)])
        assert_equal(nx.topological_sort(DG),[1, 2, 3])
        assert_equal(nx.topological_sort_recursive(DG),[1, 2, 3])

        DG.add_edge(3,2)
        assert_raises(nx.NetworkXUnfeasible, nx.topological_sort, DG)
        assert_raises(nx.NetworkXUnfeasible, nx.topological_sort_recursive, DG)
        
        DG.remove_edge(2,3)
        assert_equal(nx.topological_sort(DG),[1, 3, 2])
        assert_equal(nx.topological_sort_recursive(DG),[1, 3, 2])
开发者ID:datachomper,项目名称:googleants,代码行数:13,代码来源:test_dag.py


示例13: __delitem__

    def __delitem__(self, key):

        #print "__delitem__(" + str(key) + ")__"

        #a special case: self
        if key in ["self", "key", "value", "col", "row"]:
            raise KeyError
        
        # if we do not have the key, then we leave
        if key not in self.state:
            raise KeyError
        
        # we remove the key
        #self.G.remove_node(key)
        del self.formulas[key]
        del self.values[key]
        #del self.mode[key]
        #del self.state[key]

        # we call the callbacks
        for i in self.callbacks:
            try:
                i("delete", key)
            except Exception as e:
                print "callback delete " + key
                print "callback :=" + str(i)
                print "error: " + str(e)
                pass

        for i in self.named_callbacks:
            try:
                self.__getitem__(i)(self, "delete", key)
            except Exception as e:
                print "callback delete " + key
                print "callback :=" + str(i)
                print "error: " + str(e)
                pass

        # we mark all successor as dirty
        for i in nx.topological_sort(self.G, [key]):
            if i <> key:
                #print str(key) + " -> " + str(i)
                self.state[i] = 0
                self.update(i)

        # if there is not successor, we remove the node, and mode and state
        if nx.topological_sort(self.G, [key]) == [key]:
            self.G.remove_node(key)
            del self.mode[key]
            del self.state[key]
开发者ID:nicolasmarti,项目名称:pythonlibs,代码行数:50,代码来源:storegraph.py


示例14: _nodes

 def _nodes(self, order=None):
     """
     returns all nodes in the graph
     """
     if order is None:
         node_names = self.name_to_node.keys()
     elif order == "architecture":
         node_names = nx.topological_sort(self.architectural_tree)
     elif order == "computation":
         node_names = nx.topological_sort(self.computation_graph)
     else:
         raise ValueError("Unknown order: %s" % order)
     # make sure that all of the original nodes are returned
     assert set(self.name_to_node.keys()) == set(node_names)
     return [self.name_to_node[name] for name in node_names]
开发者ID:sashatarg,项目名称:treeano,代码行数:15,代码来源:graph.py


示例15: binarize_dag

def binarize_dag(g,
                 vertex_weight_key,
                 edge_weight_key,
                 dummy_node_name_prefix='d_'):
    g = g.copy()  # be functional
    dummy_node_counter = 1
    for u in nx.topological_sort(g):
        nbs = g.neighbors(u)
        while len(nbs) > 2:
            for p_1, p_2 in chunks(nbs, 2):
                v = "{}{}".format(
                    dummy_node_name_prefix,
                    dummy_node_counter
                )
                g.add_node(v)
                g.node[v]['dummy'] = True
                
                g.add_edge(u, v)
                g.add_edges_from([(v, p_1),
                                  (v, p_2)])

                g.node[v][vertex_weight_key] = 0
                g[v][p_1][edge_weight_key] = g[u][p_1][edge_weight_key]
                g[v][p_2][edge_weight_key] = g[u][p_2][edge_weight_key]
                g[u][v][edge_weight_key] = 0
                
                g.remove_edges_from([(u, p_1), (u, p_2)])
                dummy_node_counter += 1
            nbs = g.neighbors(u)
    return g
开发者ID:xiaohan2012,项目名称:lst,代码行数:30,代码来源:dag_util.py


示例16: _resolve_update_list

    def _resolve_update_list(self, changed_properties):
        """
        Returns a list of all plasma models which are affected by the
        changed_modules due to there dependency in the
        the plasma_graph.

        Parameters
        ----------

        changed_modules: ~list
            all modules changed in the plasma

        Returns
        -------

            : ~list
            all affected modules.
        """

        descendants_ob = []

        for plasma_property in changed_properties:
            node_name = self.outputs_dict[plasma_property].name
            descendants_ob += nx.descendants(self.graph, node_name)

        descendants_ob = list(set(descendants_ob))
        sort_order = nx.topological_sort(self.graph)

        descendants_ob.sort(key=lambda val: sort_order.index(val))

        logger.debug("Updating modules in the following order:".format("->".join(descendants_ob)))

        return descendants_ob
开发者ID:mvnnn,项目名称:tardis,代码行数:33,代码来源:base.py


示例17: test_topological_sort3

    def test_topological_sort3(self):
        DG = nx.DiGraph()
        DG.add_edges_from([(1, i) for i in range(2, 5)])
        DG.add_edges_from([(2, i) for i in range(5, 9)])
        DG.add_edges_from([(6, i) for i in range(9, 12)])
        DG.add_edges_from([(4, i) for i in range(12, 15)])

        def validate(order):
            ok_(isinstance(order, list))
            assert_equal(set(order), set(DG))
            for u, v in combinations(order, 2):
                assert_false(nx.has_path(DG, v, u))
        validate(list(nx.topological_sort(DG)))

        DG.add_edge(14, 1)
        assert_raises(nx.NetworkXUnfeasible, consume, nx.topological_sort(DG))
开发者ID:aparamon,项目名称:networkx,代码行数:16,代码来源:test_dag.py


示例18: gotermSummarization

	def gotermSummarization(self, P_geneList, P_value, P_minProteinNo):
	#use P_GotermNumber to summarizate a given list of proteins
	#Topologically sort at first

		self.node_Mapping_ProteinList_PV2(P_geneList)
		self.symplify_Goterm_Structure()
		
		#Topologically sort all node, the first element is a leaf and the last element is the root
		New_Top_sort_nodes = networkx.topological_sort(self)

		#go through all nodes in topological order from leaves to the root.
		for nodeTp_child in New_Top_sort_nodes:
			nodePV = self.node[nodeTp_child][self.PV]
			nodeSize = len(self.node[nodeTp_child][self.mapping])

			#if the current node's pv or size is not constrained by the setting conditions, merge this node to the most close parent node.
			if nodePV>P_value or nodeSize<P_minProteinNo:
				L_parrents = self.successors(nodeTp_child)
				L_MinWeight = 100000; L_MinPa = 'none'
				for nodetp in L_parrents:
					if self.edge[nodeTp_child][nodetp]['weight']<L_MinWeight:
						L_MinWeight = self.edge[nodeTp_child][nodetp]['weight']
						L_MinPa = nodetp
				if L_MinPa == 'none':
					pass
				else:
					self.merge_nodes2(nodeTp_child,L_MinPa)

		return self.printResult()
开发者ID:fay19,项目名称:gene_ontology,代码行数:29,代码来源:merge.py


示例19: _iterable_nodes

def _iterable_nodes(graph_in):
    """Returns the iterable nodes in the given graph and their join
    dependencies.

    The nodes are ordered as follows:

    - nodes without an itersource precede nodes with an itersource
    - nodes without an itersource are sorted in reverse topological order
    - nodes with an itersource are sorted in topological order

    This order implies the following:

    - every iterable node without an itersource is expanded before any
      node with an itersource

    - every iterable node without an itersource is expanded before any
      of it's predecessor iterable nodes without an itersource

    - every node with an itersource is expanded before any of it's
      successor nodes with an itersource

    Return the iterable nodes list
    """
    nodes = nx.topological_sort(graph_in)
    inodes = [node for node in nodes if node.iterables is not None]
    inodes_no_src = [node for node in inodes if not node.itersource]
    inodes_src = [node for node in inodes if node.itersource]
    inodes_no_src.reverse()
    return inodes_no_src + inodes_src
开发者ID:JohnGriffiths,项目名称:nipype,代码行数:29,代码来源:utils.py


示例20: _ffconec

def _ffconec(conec):
    """
    Checks if conec is acyclic, sorts it if necessary and returns tuple:
    (conec, inno, hidno, outno) where:
    conec - sorted input connectivity
    inno/hidno/outno  - lists of input/hidden/ouput units
    """
    if len(conec) == 0: raise ValueError("Empty connectivity list")
    graph = NX.DiGraph()
    graph.add_edges_from(conec)
    snodes = NX.topological_sort(graph)
    if not snodes:
        raise TypeError("Network has cycles.")
    else:
        conec = []; inno = []; hidno = []; outno = []
        for node in snodes:
            try:  # This is for networkx-0.3x
                ins = graph.in_edges(node)
                outs = graph.out_edges(node)
            except:  # This is for new networkx-0.99
                ins = (graph.reverse(copy=True)).edges(node)
                ins = [(v,u) for (u,v) in ins] # reversing back!
                outs = graph.edges(node)
            if not ins and node != 0 :  # biases handling
                inno += [node]
            else:
                conec += ins   #Maybe + [(0,node)] i.e. bias
                if not outs: outno += [node]
                else: 
                    if node != 0: hidno += [node] #bias handling again
    return graph, conec, inno, hidno, outno
开发者ID:pombreda,项目名称:aichallenge-1,代码行数:31,代码来源:ffnet.py



注:本文中的networkx.topological_sort函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python networkx.transitivity函数代码示例发布时间:2022-05-27
下一篇:
Python networkx.to_scipy_sparse_matrix函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap