ó
 ,µ[c        	   @   s  d  Z  d d l Z d d l Z d d l j Z d d l Z d   Z e	 d k re   Z
 d GHd e j e
  e j e
  f GHe j   Z x e
 D] Z e j e  q WxF e
 j d e  D]2 \ Z Z Z e d d	 k  rş e j e e  qş qş We j d
 d  g  e D] Z e e j e   ^ qZ e j e e
 j d g  e D] Z e
 j e ^ qAd e d e e j d d  e j d d  e j    n  d S(   s   
===========
Knuth Miles
===========

`miles_graph()` returns an undirected graph over the 128 US cities from
the datafile `miles_dat.txt`. The cities each have location and population
data.  The edges are labeled with the distance between the two cities.

This example is described in Section 1.1 in Knuth's book (see [1]_ and [2]_).

References.
-----------

.. [1] Donald E. Knuth,
   "The Stanford GraphBase: A Platform for Combinatorial Computing",
   ACM Press, New York, 1993.
.. [2] http://www-cs-faculty.stanford.edu/~knuth/sgb.html


i˙˙˙˙Nc          C   s  d d l  }  |  j d d  } t j   } i  | _ i  | _ g  } x>| j   D]0} | j   } | j d  rv qO n  t	 j
 d  } | j |  rŜ | j   } xÜ | D]0 } | j | | |	 d t |  |	 d }	 q§ WqO d }	 | j d	  \ } }
 | j d
 |  |
 j d  \ } } | j d  \ } } | j |  t |  d t |  d f | j | <t |  d | j | <qO W| S(   sZ    Return the cites example graph in miles_dat.txt
        from the Stanford GraphBase.
    i˙˙˙˙Ns   knuth_miles.txt.gzt   rt   *s   ^\d+t   weighti   t   [i    t   ]t   ,iL  i¸  g     @@(   t   gzipt   opent   nxt   Grapht   positiont
   populationt	   readlinest   decodet
   startswitht   ret   compilet   matcht   splitt   add_edget   intt   insertt   add_nodet   float(   R   t   fht   Gt   citiest   linet   numfindt   distt   dt   cityt   it   coordpopt   coordt   popt   yt   x(    (    s;   share/doc/networkx-2.2/examples/drawing/plot_knuth_miles.pyt   miles_graph'   s2    		 (t   __main__s+   Loaded miles_dat.txt containing 128 cities.s"   digraph has %d nodes with %d edgest   dataR   i,  t   figsizei   t	   node_sizet
   node_colort   with_labelsixì˙˙iô  i0ĝ˙˙iĴ  (   i   i   (!   t   __doc__R   t   syst   matplotlib.pyplott   pyplott   pltt   networkxR   R&   t   __name__R   t   number_of_nodest   number_of_edgesR	   t   Ht   vR   t   edgest   Truet   uR   R   t   figureR   t   degreeR+   t   drawR
   R   t   Falset   xlimt   ylimt   show(    (    (    s;   share/doc/networkx-2.2/examples/drawing/plot_knuth_miles.pyt   <module>   s2   
	'	"( 