本文整理汇总了Python中networkx.DiGraph.add_node方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.add_node方法的具体用法?Python DiGraph.add_node怎么用?Python DiGraph.add_node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.DiGraph
的用法示例。
在下文中一共展示了DiGraph.add_node方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: select_binary_groups
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_node [as 别名]
def select_binary_groups(groups, root=desc.root):
def get_bin_group(grps, bin_grps, rt, graph):
level = grps.successors(rt)
if not level:
bin_grps.append(graph)
return bin_grps
elif len(level) == 2:
graph.add_nodes_from(level)
graph.add_edge(rt, level[0], grps.get_edge_data(rt, level[0]))
graph.add_edge(rt, level[1], grps.get_edge_data(rt, level[1]))
if grps.successors(level[0]):
get_bin_group(grps, bin_grps, rt=level[0], graph=graph)
else:
get_bin_group(grps, bin_grps, rt=level[1], graph=graph)
else:
level.sort()
for i in xrange(0, len(level), 2):
g = DiGraph(graph)
g.add_nodes_from([level[i], level[i + 1]])
g.add_edge(rt, level[i], grps.get_edge_data(rt, level[i]))
g.add_edge(rt, level[i + 1], grps.get_edge_data(rt, level[i + 1]))
if grps.successors(level[i]):
get_bin_group(grps, bin_grps, rt=level[i], graph=g)
else:
get_bin_group(grps, bin_grps, rt=level[i + 1], graph=g)
dg = DiGraph()
dg.add_node(root)
bin_groups = []
get_bin_group(groups, bin_grps=bin_groups, rt=root, graph=dg)
return bin_groups
示例2: build_graph
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_node [as 别名]
def build_graph(alternatives, outranking, credibility=False):
"""There are some conventions to follow in this function:
1. labels (i.e. alternatives' ids) are kept in graph's dictionary (see:
graph.graph)
2. aggregated nodes (only numbers, as list) are kept under 'aggr' key in
node's dict (see: graph.nodes(data=True))
3. weights on the edges are kept under 'weight' key in edge's dict -
similarly as with nodes (see: graph.edges(data=True))
"""
graph = DiGraph() # we need directed graph for this
# creating nodes...
for i, alt in enumerate(alternatives):
graph.add_node(i)
graph.graph.update({i: alt})
# creating edges...
for i, alt in enumerate(alternatives):
relations = outranking.get(alt)
if not relations: # if graph is built from intersectionDistillation
continue
for relation in relations.items():
if relation[1] == 1.0:
weight = credibility[alt][relation[0]] if credibility else None
graph.add_edge(i, alternatives.index(relation[0]),
weight=weight)
return graph
示例3: compute_dependent_cohorts
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_node [as 别名]
def compute_dependent_cohorts(self, objects, deletion):
model_map = defaultdict(list)
n = len(objects)
r = range(n)
indexed_objects = zip(r, objects)
mG = self.model_dependency_graph[deletion]
oG = DiGraph()
for i in r:
oG.add_node(i)
for v0, v1 in mG.edges():
try:
for i0 in range(n):
for i1 in range(n):
if i0 != i1:
if not deletion and self.concrete_path_exists(
objects[i0], objects[i1]):
oG.add_edge(i0, i1)
elif deletion and self.concrete_path_exists(objects[i1], objects[i0]):
oG.add_edge(i0, i1)
except KeyError:
pass
components = weakly_connected_component_subgraphs(oG)
cohort_indexes = [reversed(topological_sort(g)) for g in components]
cohorts = [[objects[i] for i in cohort_index]
for cohort_index in cohort_indexes]
return cohorts
示例4: lazy_load_trees
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_node [as 别名]
def lazy_load_trees(skeleton_ids, node_properties):
""" Return a lazy collection of pairs of (long, DiGraph)
representing (skeleton_id, tree).
The node_properties is a list of strings, each being a name of a column
in the django model of the Treenode table that is not the treenode id, parent_id
or skeleton_id. """
values_list = ('id', 'parent_id', 'skeleton_id')
props = tuple(set(node_properties) - set(values_list))
values_list += props
ts = Treenode.objects.filter(skeleton__in=skeleton_ids) \
.order_by('skeleton') \
.values_list(*values_list)
skid = None
tree = None
for t in ts:
if t[2] != skid:
if tree:
yield (skid, tree)
# Prepare for the next one
skid = t[2]
tree = DiGraph()
fields = {k: v for k,v in izip(props, islice(t, 3, 3 + len(props)))}
tree.add_node(t[0], fields)
if t[1]:
# From child to parent
tree.add_edge(t[0], t[1])
if tree:
yield (skid, tree)
示例5: main
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_node [as 别名]
def main():
# Create an example Boolean circuit.
#
# This circuit has a ∧ at the output and two ∨s at the next layer.
# The third layer has a variable x that appears in the left ∨, a
# variable y that appears in both the left and right ∨s, and a
# negation for the variable z that appears as the sole node in the
# fourth layer.
circuit = DiGraph()
# Layer 0
circuit.add_node(0, label='∧')
# Layer 1
circuit.add_node(1, label='∨')
circuit.add_node(2, label='∨')
circuit.add_edge(0, 1)
circuit.add_edge(0, 2)
# Layer 2
circuit.add_node(3, label='x')
circuit.add_node(4, label='y')
circuit.add_node(5, label='¬')
circuit.add_edge(1, 3)
circuit.add_edge(1, 4)
circuit.add_edge(2, 4)
circuit.add_edge(2, 5)
# Layer 3
circuit.add_node(6, label='z')
circuit.add_edge(5, 6)
# Convert the circuit to an equivalent formula.
formula = circuit_to_formula(circuit)
print(formula_to_string(formula))
示例6: test_remove_node
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_node [as 别名]
def test_remove_node():
mock_mapp = DiGraph()
mock_mapp.add_node('X')
mock_mapp.add_edges_from([('A', 'B', {'TP': ['X']}),
('B', 'C', {'TP': ['Y']})])
MapGraph.remove_node.im_func(mock_mapp, 'X')
nt.assert_equal(mock_mapp.edges(), [('B', 'C')])
示例7: addCell
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_node [as 别名]
def addCell(self, cell, gateName=None):
mod = self.__nl.mods[self.__nl.topMod]
yaml = self.__nl.yaml
self.__cells.add(cell)
name = gateName if gateName else mod.cells[cell].submodname
if "clocks" in yaml[name]:
self.__flops.add(cell)
digraph.add_node(self, cell)
示例8: DiGraph
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_node [as 别名]
def vytvořím_networkx_graf():
from networkx import DiGraph, write_graphml
graf = DiGraph()
graf.add_node(1, time='5pm')
graf.add_node(2)
graf.add_edge(1,2, weight=25)
write_graphml(graf, './data/networkx.graphml')
示例9: get_connection_graph
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_node [as 别名]
def get_connection_graph(names, connections):
G = DiGraph()
# add names to check if it is connected
for n in names:
G.add_node(n)
for c in connections:
dp1 = c.dp1
dp2 = c.dp2
G.add_edge(dp1, dp2)
return G
示例10: getStageGraph
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_node [as 别名]
def getStageGraph(self, phase):
graph = DiGraph()
for stage in self.structureInfo[phase][consts.STAGES_KEY].keys():
graph.add_node(stage)
graph.node[stage]["name"] = str(stage)
for edge in self.structureInfo[phase][consts.STAGE_TO_STAGE_KEY]:
graph.add_edge(edge[consts.SRC_KEY], edge[consts.DEST_KEY])
return graph
示例11: build_allele_graph
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_node [as 别名]
def build_allele_graph(self, num_alleles=None):
"""
Method that builds segregation graph from the given pedigree. See the
constructor for descriptions of parameters.
Returns
-------
G : networkx.DiGraph
NetworkX DiGraph representation of the segregation network defined
by the given pedigree and allele assignments. Nodes of the graph
are named using the following conventions:
allele node = id_parent_locus
ex.: 1_0_0 -> paternal allele of locus 0 for ID = 1
ex.: 2_1_3 -> maternal allele of locus 3 for ID = 2
segregation node = S_parent_child_locus
ex.: S_1_6_1 -> segrgation indicator of parent ID = 1
to child ID = 6 for locus 1
"""
num_alleles = num_alleles if num_alleles else self.len
G = DiGraph()
# for each allele
for i in range(num_alleles):
# for each k = parent, v = [children, sex]
for k,v in self.ped.pedigree.items():
#for k in self.ped.ped_graph.nodes():
# make parent nodes, one for each allele, at locus i
G.add_node(self.mk_nd(k, 1, i))
G.add_node(self.mk_nd(k, 0, i))
# for each k = parent, v = [children, sex]
for k,v in self.ped.pedigree.items():
# for each child of k
for c in v['cs']:
# determine if parent is male or female
type = 0 if v['sex'] == 'm' else 1
# add edges from parent alleles to children alleles
G.add_edge(self.mk_nd(k, 1, i), self.mk_nd(c, type, i))
G.add_edge(self.mk_nd(k, 0, i), self.mk_nd(c, type, i))
# add other allele of child, just in case it's not in the graph
G.add_node(self.mk_nd(c, int(not type), i))
# add segregation node edge
G.add_edge(self.mk_nd('S', k, c, i), self.mk_nd(c, type, i))
# if applicable, add edge between segregation indicators
if i > 0:
G.add_edge(self.mk_nd('S', k, c, i - 1), self.mk_nd('S', k, c, i))
# for UAI: vars are indexed by topological sort
self.vars = topological_sort(G)
self.var_idxs = dict([(v,i) for i,v in enumerate(self.vars)])
self.allele_graph = G
return G
示例12: createDiGraphCopy
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_node [as 别名]
def createDiGraphCopy(self, geneTuples):
copyGraph = DiGraph()
for node in self:
if len(self.getGenesByNode(node).intersection(geneTuples)) > 0 or len(self.getPropagatedGenesByNode(node).intersection(geneTuples)) > 0:
copyGraph.add_node(node, {'gene':set(self.getGenesByNode(node).intersection(geneTuples)), 'propGene':set(self.getPropagatedGenesByNode(node).intersection(geneTuples)), 'pmid': set(self.getPubMedByNode(node)), 'mergeGene': set(), 'mergePMID': set(), 'mergeCount': 0, 'infoLoss': 0})
for i in copyGraph:
for edge in self.edge[i]:
if edge in copyGraph:
copyGraph.add_edge(i, edge, self.edge[i][edge])
return copyGraph
示例13: subgroup_identification
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_node [as 别名]
def subgroup_identification(sample, mode,
a_logrank=desc.a_logrank,
cov_at_level=desc.cov_at_level,
min_sub_size=desc.min_sub_size):
subgroups = DiGraph()
cov_used = {key: val for key in sample.keys() for val in [False]}
subgroups.add_node(desc.root)
global global_counter
global_counter = 1
sub_ident(sample, subgroups, cov_used, a_logrank, cov_at_level, min_sub_size, mode,
parent=desc.root, recurs_level=1)
return subgroups
示例14: __init__
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_node [as 别名]
def __init__(self, debug=0):
digraph.__init__(self)
self.__debug = debug
self.__inputs = set()
self.__outputs = set()
self.__cells = set()
self.__flops = set()
self.__virtual = dict() # maps name --> gate
self.__pins = dict()
self.__flopsIn = dict()
# create input, output nodes
digraph.add_node(self, "__INPUTS__")
digraph.add_node(self, "__OUTPUTS__")
示例15: _rename_nodes
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_node [as 别名]
def _rename_nodes(self, graph):
new_graph = DiGraph()
# print len(self._node_names)
for node in graph.nodes():
# Add all the nodes with the names given in the data set
new_node_name = self._node_names[node]
new_graph.add_node(new_node_name)
for edge in graph.edges():
# Add all the with the names given in the data set
new_source_node = self._node_names[ edge[0] ]
new_destination_node = self._node_names[ edge[1] ]
new_graph.add_edge(new_source_node, new_destination_node)
new_graph.name = self._network_name
return new_graph