本文整理汇总了Python中networkx.Graph.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.__init__方法的具体用法?Python Graph.__init__怎么用?Python Graph.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.Graph
的用法示例。
在下文中一共展示了Graph.__init__方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import __init__ [as 别名]
def __init__(self, data=None, name='', file=None, **attr):
Graph.__init__(self, data=data,name=name,**attr)
if file is None:
import sys
self.fh=sys.stdout
else:
self.fh=open(file,'w')
示例2: add_layer
# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import __init__ [as 别名]
def add_layer(self, layer, **attr):
if self.num_nodes_in_layers is 0:
self.list_of_layers=[layer]
else:
self.list_of_layers.append(layer)
self.num_layers = len(self.list_of_layers)
self.num_nodes_in_layers = self.list_of_layers[0].number_of_nodes()
for i,j in layer.edges():
self.intra_layer_edges.append((
i+(len(self.list_of_layers)-1)*layer.number_of_nodes(),
j+(len(self.list_of_layers)-1)*layer.number_of_nodes()))
try:
Graph.__init__(self,
Graph(disjoint_union_all(self.list_of_layers),
**attr))
except multinetxError:
raise multinetxError("Multiplex cannot inherit Graph properly")
## Check if all graphs have the same number of nodes
for lg in self.list_of_layers:
try:
assert(lg.number_of_nodes() == self.num_nodes_in_layers)
except AssertionError:
raise multinetxError("Graph at layer does not have the same number of nodes")
示例3: __init__
# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import __init__ [as 别名]
def __init__(self, environment=None, channelType=None, algorithms=(),
networkRouting=True, propagation_type=2, **kwargs):
Graph.__init__(self)
self._environment = environment or Environment()
# assert(isinstance(self.environment, Environment))
self.channelType = channelType or ChannelType(self._environment)
if isinstance(self.channelType, Doi):
doi = kwargs.pop('doi', 0)
print "In DOI %s" %doi
self.channelType.set_params(doi=doi)
self.channelType.environment = self._environment
self.propagation = propagation.PropagationModel(propagation_type=propagation_type)
self.pos = {}
self.ori = {}
self.labels = {}
#self.star = star_graph
self.name = "WSN"
self._algorithms = ()
self.algorithms = algorithms or settings.ALGORITHMS
self.algorithmState = {'index': 0, 'step': 1, 'finished': False}
self.outbox = []
self.networkRouting = networkRouting
self.comm_range = kwargs.pop('commRange', None) or settings.COMM_RANGE
logger.info("Instance of Network has been initialized with %s (%s)" % (self.propagation, self.comm_range))
示例4: __init__
# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import __init__ [as 别名]
def __init__(self, environment=None, channelType=None, algorithms=(), networkRouting=True, **kwargs):
self._environment = environment or Environment()
# assert(isinstance(self.environment, Environment))
self.channelType = channelType or ChannelType(self._environment)
self.channelType.environment = self._environment
self.pos = {}
self.ori = {}
self.labels = {}
Graph.__init__(self)
self._algorithms = ()
self.algorithms = algorithms or settings.ALGORITHMS
self.algorithmState = {"index": 0, "step": 1, "finished": False}
self.outbox = []
self.networkRouting = networkRouting
logger.info("Instance of Network has been initialized.")
示例5: __init__
# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import __init__ [as 别名]
def __init__(self, storage, species, aspect=Aspects.BP):
GOGraphBase.__init__(self, storage, species, aspect)
Graph.__init__(self)
示例6: __init__
# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import __init__ [as 别名]
def __init__(self,
list_of_layers=None,
inter_adjacency_matrix=None,
**attr):
"""Constructor of a MultilayerGraph.
It creates a symmetric (undirected) MultilayerGraph object
inheriting methods from networkx.Graph
Parameters:
-----------
list_of_layers : Python list of networkx.Graph objects
inter_adjacency_matrix : a lil sparse matrix (NxN) with zero
diagonal elements and off-diagonal
block elements defined by the
inter-connectivity architecture.
Return: a MultilayerGraph object
Examples:
---------
import multinetx as mx
N = 10
g1 = mx.erdos_renyi_graph(N,0.07,seed=218)
g2 = mx.erdos_renyi_graph(N,0.07,seed=211)
g3 = mx.erdos_renyi_graph(N,0.07,seed=211)
adj_block = mx.lil_matrix(np.zeros((N*3,N*3)))
adj_block[0: N, N:2*N] = np.identity(N) # L_12
adj_block[0: N,2*N:3*N] = np.identity(N) # L_13
#adj_block[N:2*N,2*N:3*N] = np.identity(N) # L_23
adj_block += adj_block.T
mg = mx.MultilayerGraph(list_of_layers=[g1,g2,g3],
inter_adjacency_matrix=adj_block)
mg.set_edges_weights(inter_layer_edges_weight=4)
mg.set_intra_edges_weights(layer=0,weight=1)
mg.set_intra_edges_weights(layer=1,weight=2)
mg.set_intra_edges_weights(layer=2,weight=3)
"""
## Give an empty graph in the list_of_layers
if list_of_layers is None:
self.list_of_layers = [Graph()]
else:
self.list_of_layers = list_of_layers
## Number of layers
self.num_layers = len(self.list_of_layers)
## Number of nodes in each layer
self.num_nodes_in_layers = self.list_of_layers[0].number_of_nodes()
## Create the MultilayerGraph without inter-layer links.
try:
Graph.__init__(self,
Graph(disjoint_union_all(self.list_of_layers),
**attr))
except multinetxError:
raise multinetxError("Multiplex cannot inherit Graph properly")
## Check if all graphs have the same number of nodes
for lg in self.list_of_layers:
try:
assert(lg.number_of_nodes() == self.num_nodes_in_layers)
except AssertionError:
raise multinetxError("Graph at layer does not have")
## Make a zero lil matrix for inter_adjacency_matrix
if inter_adjacency_matrix is None:
inter_adjacency_matrix = \
lil_matrix(zeros(
(self.num_nodes_in_layers*self.num_layers,
self.num_nodes_in_layers*self.num_layers)))
## Check if the matrix inter_adjacency_matrix is lil
try:
assert(inter_adjacency_matrix.format == "lil")
except AssertionError:
raise multinetxError("interconnecting_adjacency_matrix "\
"is not scipy.sparse.lil")
## Lists for intra-layer and inter-layer edges
if list_of_layers is None:
self.intra_layer_edges = []
else:
self.intra_layer_edges = self.edges()
self.inter_layer_edges = []
## Inter-layer connection
self.layers_interconnect(inter_adjacency_matrix)
## MultiNetX name
self.name = "multilayer"
for layer in self.list_of_layers:
self.name += "_" + layer.name