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")
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')
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))
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))
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')
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")
def __init__(self, input_stream, record_filter=None, node_separator='=', max_nodes=sys.maxint, max_edges=sys.maxint): """ Parameters ---------- input_stream: iterator with a next(), should contain list of dicts (records) record_filter: only use these keys from input_stream node_separator: separtor between node key and value max_nodes: stop inserting from stream after max_nodes in graph max_edges: stop inserting from stream after max_edges in graph Returns ------- """ # constructor fields self.input_stream = input_stream self.record_filter = record_filter self.node_separator = node_separator self.max_nodes = max_nodes self.max_edges = max_edges # stats self.records_per_second = -1 self.records_processed = 0 # I don't think this is how to handle multiple-inheritance super init, but it seems to work Graph.__init__(self) Thread.__init__(self) self.start()
def __init__(self, data=None, **attr): Graph.__init__(self, **attr) if data is not None: convert.to_networkx_graph(data, create_using=self) # check if it is a tree. if not (G.order() == G.size() + 1 and nx.number_connected_components(G) == 1): raise NetworkXError("Data %s is not a tree" % data) # load graph attributes (must be after convert) self.graph.update(attr) self.edge = self.adj
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.")
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.")
def __init__(self,sif,labels): _Graph.__init__(self) self.labels = {} with open(labels,'r') as fin: for f in fin.readlines(): [oid,cell] = f.split('\t') cell = cell.split(' ')[0] self.labels[oid] = cell with open(sif,'r') as fin: for f in fin.readlines(): [pre,post] = f.split(' pd ') post = post.split('\n')[0] pre = self.labels[pre] post = self.labels[post] if pre == post: continue self.add_edge(pre,post)
def add_layer(self, layer, **attr): if self.num_nodes is 0: self.list_of_layers = [layer] else: self.list_of_layers.append(layer) self.num_nodes_in_layers.append(layer.number_of_nodes()) self.num_layers = len(self.list_of_layers) 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")
def __init__(self, storage, species, aspect=Aspects.BP): GOGraphBase.__init__(self, storage, species, aspect) Graph.__init__(self)
def __init__(self, data=None, **keywords): """ 2013.1.3 wrapper around networkx.Graph """ Graph.__init__(self, data=None, **keywords)
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
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