Example #1
0
    def __init__(self, data=None, **attr):
        """Initialize a graph with edges, name, or 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.

        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.edge_key_dict_factory = self.edge_key_dict_factory
        Graph.__init__(self, data, **attr)
Example #2
0
    def __init__(self, incoming_graph_data=None, **attr):
        """Initialize a graph with edges, name, or graph attributes.

        Parameters
        ----------
        incoming_graph_data : input graph
            Data to initialize graph.  If incoming_graph_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.

        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.edge_key_dict_factory = self.edge_key_dict_factory
        Graph.__init__(self, incoming_graph_data, **attr)
Example #3
0
    def __init__(self,
                 NodesPos=None,
                 Edges=None,
                 Radii=None,
                 data=None,
                 Types=None):
        G.__init__(self, data=data)

        # attributes to be stored
        self.SetGeomGraph(NodesPos, Edges, Radii, Types)
        self.Area = 0
Example #4
0
 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
Example #5
0
 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
Example #6
0
 def __init__(self, data=None, **attr):
     self.edge_key_dict_factory = self.edge_key_dict_factory
     Graph.__init__(self, data, **attr)
Example #7
0
 def __init__(self, data=None, **attr):
     self.edge_key_dict_factory = self.edge_key_dict_factory
     Graph.__init__(self, data, **attr)
Example #8
0
 def __init__(self, oldCG=None):
     """
     """
     Graph.__init__(self, oldCG)
     self.matrix = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
Example #9
0
    def __init__(self,
                 incoming_graph_data=None,
                 multigraph_input=None,
                 **attr):
        """Initialize a graph with edges, name, or graph attributes.

        Parameters
        ----------
        incoming_graph_data : input graph
            Data to initialize graph.  If incoming_graph_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.

        multigraph_input : bool or None (default None)
            Note: Only used when `incoming_graph_data` is a dict.
            If True, `incoming_graph_data` is assumed to be a
            dict-of-dict-of-dict-of-dict structure keyed by
            node to neighbor to edge keys to edge data for multi-edges.
            A NetworkXError is raised if this is not the case.
            If False, :func:`to_networkx_graph` is used to try to determine
            the dict's graph data structure as either a dict-of-dict-of-dict
            keyed by node to neighbor to edge data, or a dict-of-iterable
            keyed by node to neighbors.
            If None, the treatment for True is tried, but if it fails,
            the treatment for False is tried.

        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.edge_key_dict_factory = self.edge_key_dict_factory
        # multigraph_input can be None/True/False. So check "is not False"
        if isinstance(incoming_graph_data,
                      dict) and multigraph_input is not False:
            Graph.__init__(self)
            try:
                convert.from_dict_of_dicts(incoming_graph_data,
                                           create_using=self,
                                           multigraph_input=True)
                self.graph.update(attr)
            except Exception as err:
                if multigraph_input is True:
                    raise nx.NetworkXError(
                        f"converting multigraph_input raised:\n{type(err)}: {err}"
                    )
                Graph.__init__(self, incoming_graph_data, **attr)
        else:
            Graph.__init__(self, incoming_graph_data, **attr)
Example #10
0
 def __init__(self):
     Graph.__init__(self)