Ticket #5911: trac_5911.patch

File trac_5911.patch, 8.5 KB (added by ncohen, 11 years ago)
  • sage/graphs/graph.py

    # HG changeset patch
    # User Robert L. Miller <rlm@rlmiller.org>
    # Date 1251311834 25200
    # Node ID 12e26dc2dc69e3551b95028004e6121738bb72cd
    # Parent  29c08389a0ab2f10b497157c77f696a02dc2e5c6
    Documentation from graph? and digraph?
    
    diff -r 29c08389a0ab -r 12e26dc2dc69 sage/graphs/graph.py
    a b  
    88628862    Undirected graph.
    88638863
    88648864    A Graph is a set of vertices connected by edges
    8865     (cf. http://en.wikipedia.org/wiki/Graph_(mathematics) )
    8866 
    8867     One can very easily create a graph in sage by typing ::
     8865    (cf. http://en.wikipedia.org/wiki/Graph_(mathematics) ).
     8866
     8867    One can very easily create a graph in sage by typing::
    88688868   
    88698869        sage: g=Graph()
    88708870
    8871     By typing the name of the Graph, one can get some basic informations
     8871    By typing the name of the Graph, one can get some basic information
    88728872    about it::
    88738873
    88748874        sage: g
    88758875        Graph on 0 vertices
    88768876
    8877     This graph is not very interesting as it is by default the empty graph.. But
     8877    This graph is not very interesting as it is by default the empty graph. But
    88788878    Sage contains a large collection of pre-defined graph classes that can be listed
    8879     this way :
    8880    
    8881         * type in Sage : graphs.
     8879    this way:
     8880   
     8881        * Type in Sage : graphs.
    88828882          ( do not press "Enter", and do not forget the final "." )
    8883         * hit "tabulation" two times in a row
    8884    
    8885     You will see the list of methods defined in the class "graphs", all of which
    8886     generate graphs you can play with !
    8887 
    8888     If you want to see what they look like, begin this way ::
    8889    
     8883        * Hit "tab".
     8884   
     8885    You will see a list of methods which will construct named graphs. For
     8886    example::
     8887
    88908888        sage: g=graphs.PetersenGraph()
    88918889        sage: g.plot()
    88928890
     
    88958893        sage: g=graphs.ChvatalGraph()
    88968894        sage: g.plot()
    88978895
    8898     If you are curious about what these graphs are, for example if you wonder what ``RandomGNP``
    8899     actually is, you but have to type::
     8896    In order to obtain more information about these graph constructors, access
     8897    the documentation as follows::
    89008898
    89018899        sage: graphs.RandomGNP?
    89028900
     
    89048902    almost 200 functions on graphs in the Sage library !
    89058903    If your graph is named ``g``, you can list these functions as previously this way
    89068904   
    8907         * type in Sage : ``g.``
     8905        * Type in Sage : ``g.``
    89088906          ( do not press "Enter", and do not forget the final "." )
    8909         * hit "tabulation" two times in a row   
     8907        * Hit "tab".
    89108908
    89118909    As usual, you can get some information about what these functions do by typing
    8912     ( if you want to know about the ``diameter()`` method )::
     8910    (e.g. if you want to know about the ``diameter()`` method)::
    89138911
    89148912        sage: g.diameter?
    89158913
    8916     If you have defined a graph ``g`` having several connected components ( = which is not
    8917     connected... Type ``g.is_connected()`` to know if your graph is connected ), you can
    8918     print each one of its connected components with only two lines :
    8919    
    8920     ( if you do not have such a graph G, here is one for free :  ``g=graphs.RandomGNP(30,.05)``    )::
     8914    If you have defined a graph ``g`` having several connected components ( i.e.
     8915    ``g.is_connected()`` returns False ), you can print each one of its
     8916    connected components with only two lines::
    89218917   
    89228918        sage: for component in g.connected_components():
    89238919        ...      g.subgraph(component).plot()
     
    1077810774class DiGraph(GenericGraph):
    1077910775    """
    1078010776    Directed graph.
    10781    
     10777
     10778    A DiGraph is a set of vertices connected by oriented edges
     10779    (cf. http://en.wikipedia.org/wiki/Digraph_%28mathematics%29 ).
     10780
     10781    One can very easily create a directed graph in sage by typing::
     10782   
     10783        sage: g=DiGraph()
     10784
     10785    By typing the name of the DiGraph, one can get some basic information
     10786    about it::
     10787
     10788        sage: g
     10789        Digraph on 0 vertices
     10790
     10791    This digraph is not very interesting as it is by default the empty graph. But
     10792    Sage contains several pre-defined digraph classes that can be listed
     10793    this way:
     10794   
     10795        * Type in Sage : digraphs.
     10796          ( do not press "Enter", and do not forget the final "." )
     10797        * Hit "tab".
     10798   
     10799    You will see a list of methods which will construct named digraphs. For
     10800    example::
     10801
     10802        sage: g=digraphs.ButterflyGraph(3)
     10803        sage: g.plot()
     10804       
     10805    You can also use the collection of pre-defined graphs, then create a DiGraph
     10806    from them. ::
     10807
     10808        sage: g=DiGraph(graphs.PetersenGraph())
     10809        sage: g.plot()
     10810
     10811    Calling ``Digraph`` on a graph returns the original graph in which every edge
     10812    is replaced by two different edges going toward opposite directions.
     10813
     10814    In order to obtain more information about these degraph constructors, access
     10815    the documentation as follows::
     10816
     10817        sage: digraphs.RandomDirectedGNP?
     10818
     10819    Once you have defined the digraph you want, you can begin to work on it by using the
     10820    almost 200 functions on graphs and digraphs in the Sage library !
     10821    If your digraph is named ``g``, you can list these functions as previously this way
     10822   
     10823        * Type in Sage : ``g.``
     10824          ( do not press "Enter", and do not forget the final "." )
     10825        * Hit "tab".
     10826
     10827    As usual, you can get some information about what these functions do by typing
     10828    (e.g. if you want to know about the ``diameter()`` method)::
     10829
     10830        sage: g.diameter?
     10831
     10832    If you have defined a digraph ``g`` having several connected components ( i.e.
     10833    ``g.is_connected()`` returns False ), you can print each one of its
     10834    connected components with only two lines::
     10835   
     10836        sage: for component in g.connected_components():
     10837        ...      g.subgraph(component).plot()
     10838
     10839    The same methods works for strongly connected components ::
     10840        sage: for component in g.strongly_connected_components():
     10841        ...      g.subgraph(component).plot()
     10842   
     10843
    1078210844    INPUT:
    1078310845
    1078410846    -  ``data`` -  can be any of the following:
    1078510847
     10848       #.  A dictionary of dictionaries
     10849
     10850       #.  A dictionary of lists
     10851
     10852       #.  A numpy matrix or ndarray
     10853
     10854       #.  A Sage adjacency matrix or incidence matrix
     10855
     10856       #.  A pygraphviz agraph
     10857
     10858       #.  A SciPy sparse matrix
     10859
    1078610860       #.  A NetworkX digraph
    1078710861
    10788        #.  A dictionary of dictionaries
    10789 
    10790        #.  A dictionary of lists
    10791 
    10792        #.  A numpy matrix or ndarray
    10793 
    10794        #.  A Sage adjacency matrix or incidence matrix
    10795 
    10796        #.  A pygraphviz agraph
    10797 
    10798        #.  A SciPy sparse matrix
    10799 
    1080010862    -  ``pos`` - a positioning dictionary: for example, the
    1080110863       spring layout from NetworkX for the 5-cycle is::
    1080210864
     
    1085110913   
    1085210914    EXAMPLES:
    1085310915
    10854     #. A NetworkX XDiGraph::
    10855 
    10856             sage: import networkx
    10857             sage: g = networkx.XDiGraph({0:[1,2,3], 2:[4]})
    10858             sage: DiGraph(g)
    10859             Digraph on 5 vertices
    10860    
    10861    
    10862     #. A NetworkX digraph::
    10863 
    10864             sage: import networkx
    10865             sage: g = networkx.DiGraph({0:[1,2,3], 2:[4]})
    10866             sage: DiGraph(g)
    10867             Digraph on 5 vertices
    10868    
    10869        Note that in all cases, we copy the NetworkX structure.
    10870    
    10871        ::
    10872 
    10873             sage: import networkx
    10874             sage: g = networkx.DiGraph({0:[1,2,3], 2:[4]})
    10875             sage: G = DiGraph(g, implementation='networkx')
    10876             sage: H = DiGraph(g, implementation='networkx')
    10877             sage: G._backend._nxg is H._backend._nxg
    10878             False
    1087910916
    1088010917    #. A dictionary of dictionaries::
    1088110918                       
     
    1097611013            ...
    1097711014            RuntimeError: The string seems corrupt: valid characters are
    1097811015            ?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
     11016
     11017    #. A NetworkX XDiGraph::
     11018
     11019            sage: import networkx
     11020            sage: g = networkx.XDiGraph({0:[1,2,3], 2:[4]})
     11021            sage: DiGraph(g)
     11022            Digraph on 5 vertices
     11023   
     11024   
     11025    #. A NetworkX digraph::
     11026
     11027            sage: import networkx
     11028            sage: g = networkx.DiGraph({0:[1,2,3], 2:[4]})
     11029            sage: DiGraph(g)
     11030            Digraph on 5 vertices
     11031   
     11032       Note that in all cases, we copy the NetworkX structure.
     11033   
     11034       ::
     11035
     11036            sage: import networkx
     11037            sage: g = networkx.DiGraph({0:[1,2,3], 2:[4]})
     11038            sage: G = DiGraph(g, implementation='networkx')
     11039            sage: H = DiGraph(g, implementation='networkx')
     11040            sage: G._backend._nxg is H._backend._nxg
     11041            False
     11042
    1097911043       
    1098011044    """
    1098111045    _directed = True