def __init__(self, data=None, name='', **attr): """Initialize a graph with edges, name, graph attributes. Parameters ---------- data : input graph Data to initialize graph. If data=None (default) an empty graph is created. The data can be an edge list, or any NetworkX graph object. If the corresponding optional Python packages are installed the data can also be a NumPy matrix or 2d ndarray, a SciPy sparse matrix, or a PyGraphviz graph. name : string, optional (default='') An optional name for the graph. attr : keyword arguments, optional (default= no attributes) Attributes to add to graph as key=value pairs. See Also -------- convert Examples -------- >>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G = nx.Graph(name='my graph') >>> e = [(1,2),(2,3),(3,4)] # list of edges >>> G = nx.Graph(e) Arbitrary graph attribute pairs (key=value) may be assigned >>> G=nx.Graph(e, day="Friday") >>> G.graph {'day': 'Friday'} """ self.graph = {} # dictionary for graph attributes self.node = {} # dictionary for node attributes # We store two adjacency lists: # the predecessors of node n are stored in the dict self.pred # the successors of node n are stored in the dict self.succ=self.adj self.adj = {} # empty adjacency dictionary self.pred = {} # predecessor self.succ = self.adj # successor # attempt to load graph with data if data is not None: convert.from_whatever(data, create_using=self) # load graph attributes (must be after convert) self.graph.update(attr) self.name = name self.edge = self.adj
def __init__(self, data=None, name="", **attr): """Initialize a graph with edges, name, graph attributes. Parameters ---------- data : input graph Data to initialize graph. If data=None (default) an empty graph is created. The data can be an edge list, or any NetworkX graph object. If the corresponding optional Python packages are installed the data can also be a NumPy matrix or 2d ndarray, a SciPy sparse matrix, or a PyGraphviz graph. name : string, optional (default='') An optional name for the graph. attr : keyword arguments, optional (default= no attributes) Attributes to add to graph as key=value pairs. See Also -------- convert Examples -------- >>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G = nx.Graph(name='my graph') >>> e = [(1,2),(2,3),(3,4)] # list of edges >>> G = nx.Graph(e) Arbitrary graph attribute pairs (key=value) may be assigned >>> G=nx.Graph(e, day="Friday") >>> G.graph {'day': 'Friday'} """ self.graph = {} # dictionary for graph attributes self.node = {} # dictionary for node attributes # We store two adjacency lists: # the predecessors of node n are stored in the dict self.pred # the successors of node n are stored in the dict self.succ=self.adj self.adj = {} # empty adjacency dictionary self.pred = {} # predecessor self.succ = self.adj # successor # attempt to load graph with data if data is not None: convert.from_whatever(data, create_using=self) # load graph attributes (must be after convert) self.graph.update(attr) self.name = name self.edge = self.adj
def __init__(self, data=None, name='', weighted=True): """Initialize an empty graph. Examples -------- >>> G=nx.Graph() >>> G=nx.Graph(name='my graph') >>> G=nx.Graph(weighted=False) # don't assume edge data are weights """ self.adj = {} # empty adjacency hash self.weighted = weighted # attempt to load graph with data if data is not None: convert.from_whatever(data,create_using=self) self.name = name
def __init__(self, data=None, name='', weighted=True): """Initialize an empty graph. Examples -------- >>> G=nx.Graph() >>> G=nx.Graph(name='my graph') >>> G=nx.Graph(weighted=False) # don't assume edge data are weights """ self.adj = {} # empty adjacency hash self.weighted = weighted # attempt to load graph with data if data is not None: convert.from_whatever(data, create_using=self) self.name = name
def __init__(self,data=None,**kwds): Tree.__init__(self,**kwds) self.comp={} # dictionary mapping node to component self.nc=0 # component index, start at zero, sequential (with holes) if data is not None: try: self=convert.from_whatever(data,create_using=self) except: raise NetworkXError("Data %s is not a forest"%data)
def __init__(self, data=None, **kwds): Tree.__init__(self, **kwds) self.comp = {} # dictionary mapping node to component self.nc = 0 # component index, start at zero, sequential (with holes) if data is not None: try: self = convert.from_whatever(data, create_using=self) except: raise NetworkXError("Data %s is not a forest" % data)
def __init__(self, data=None, name='', weighted=True): """Initialize an empty directed graph. Examples -------- >>> G=nx.DiGraph() >>> G=nx.DiGraph(name='my graph') >>> G=nx.DiGraph(weighted=False) # don't assume edge data are weights """ # We store two adjacency lists: # the predecessors of node n are stored in the dict self.pred # the successors of node n are stored in the dict self.succ=self.adj self.adj = {} # empty adjacency dictionary self.pred = {} # predecessor self.succ = self.adj # successor self.weighted = weighted # attempt to load graph with data if data is not None: convert.from_whatever(data,create_using=self) self.name=name
def __init__(self, data=None, name='', weighted=True): """Initialize an empty directed graph. Examples -------- >>> G=nx.DiGraph() >>> G=nx.DiGraph(name='my graph') >>> G=nx.DiGraph(weighted=False) # don't assume edge data are weights """ # We store two adjacency lists: # the predecessors of node n are stored in the dict self.pred # the successors of node n are stored in the dict self.succ=self.adj self.adj = {} # empty adjacency dictionary self.pred = {} # predecessor self.succ = self.adj # successor self.weighted = weighted # attempt to load graph with data if data is not None: convert.from_whatever(data, create_using=self) self.name = name
def __init__(self,data=None,**kwds): Graph.__init__(self,**kwds) if data is not None: try: # build a graph G=Graph() G=convert.from_whatever(data,create_using=G) except: raise NetworkXError, "Data %s is not a tree"%data # check if it is a tree. if G.order()==G.size()+1 and \ component.number_connected_components(G)==1: self.adj=G.adj.copy() del G else: raise NetworkXError, "Data %s is not a tree"%data
def __init__(self, data=None, **kwds): Graph.__init__(self, **kwds) if data is not None: try: # build a graph G = Graph() G = convert.from_whatever(data, create_using=G) except: raise NetworkXError, "Data %s is not a tree" % data # check if it is a tree. if G.order()==G.size()+1 and \ component.number_connected_components(G)==1: self.adj = G.adj.copy() del G else: raise NetworkXError, "Data %s is not a tree" % data
def __init__(self, data=None, name='', selfloops=False, multiedges=False, ubigraph_server= 'http://127.0.0.1:20738/RPC2', clear=True, nextid=0): import xmlrpclib try: server_url = ubigraph_server self.server = xmlrpclib.Server(server_url) self.ubigraph = self.server.ubigraph if clear: self.ubigraph.clear() except: raise IOError("No Ubigraph server found") # default node and edge styles self.ubigraph.set_vertex_style_attribute(0, "color", "#ff0000") self.ubigraph.set_vertex_style_attribute(0, "shape", "sphere") self.ubigraph.set_vertex_style_attribute(0, "size", "0.7") self.ubigraph.set_edge_style_attribute(0, "color", "#ffffff") self.ubigraph.set_edge_style_attribute(0, "width", "2.0") self.use_splines=False self.use_node_labels=False self.use_edge_labels=False # keep a mapping from nodes to ubigraph ids self.nodeid={} self.nextid=nextid self.idnode={} self.adj={} # adjacency list self.selfloops=selfloops self.multiedges=multiedges if data is not None: self=convert.from_whatever(data,create_using=self) self.name=name
def __init__(self, data=None, name='', selfloops=False, multiedges=False, ubigraph_server='http://127.0.0.1:20738/RPC2', clear=True, nextid=0): import xmlrpclib try: server_url = ubigraph_server self.server = xmlrpclib.Server(server_url) self.ubigraph = self.server.ubigraph if clear: self.ubigraph.clear() except: raise IOError("No Ubigraph server found") # default node and edge styles self.ubigraph.set_vertex_style_attribute(0, "color", "#ff0000") self.ubigraph.set_vertex_style_attribute(0, "shape", "sphere") self.ubigraph.set_vertex_style_attribute(0, "size", "0.7") self.ubigraph.set_edge_style_attribute(0, "color", "#ffffff") self.ubigraph.set_edge_style_attribute(0, "width", "2.0") self.use_splines = False self.use_node_labels = False self.use_edge_labels = False # keep a mapping from nodes to ubigraph ids self.nodeid = {} self.nextid = nextid self.idnode = {} self.adj = {} # adjacency list self.selfloops = selfloops self.multiedges = multiedges if data is not None: self = convert.from_whatever(data, create_using=self) self.name = name