ó
?úźWc           @   s#   d  d l  Z  d d d     YZ d S(   i˙˙˙˙Nt   Townc           B   sG   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C   s   | |  _  | |  _ d S(   sq  
            shops: List of FruitShop objects

            distances: Dictionary with keys as pairs (tuples) of names of places
            ('home' or name strings of FruitShops) and numbers for values which
            represent the distance between the two places in miles, e.g.
            {('home','shop1') : 1, ('home','shop2') : 1, ('shop1','shop2') : 2}
        N(   t   shopst	   distances(   t   selfR   R   (    (    sK   /Users/saia/public_html/classes/527-s18/proj/python_basics/tutorial/town.pyt   __init__   s    		c         C   s   g  |  j  D] } | j   | k r
 | ^ q
 } g  } x9 | D]1 } | j |  } | d k	 r; | j |  q; q; W| sz d St |  S(   sâ   
            fruit: Fruit string

            route: List of shop names
        Returns the best cost per pound of 'fruit' at any of the shops along 
        the route. If none of the shops carry 'fruit', returns None
        N(   R   t   getNamet   getCostPerPoundt   Nonet   appendt   min(   R   t   fruitt   routet   shopt
   routeShopst   costst   cost(    (    sK   /Users/saia/public_html/classes/527-s18/proj/python_basics/tutorial/town.pyt   getFruitCostPerPoundOnRoute   s    .c         C   s/   d g  | D] \ } } |  j | |  ^ q
 k S(   sÖ   
            orderList: List of (fruit, numPounds) tuples

            shops: List of shop names
        Returns whether all fruit in the order list can be purchased at at least
        one of these shops.
        N(   R   R   (   R   t	   orderListR   R
   t   _(    (    sK   /Users/saia/public_html/classes/527-s18/proj/python_basics/tutorial/town.pyt   allFruitsCarriedAtShops2   s    c         C   s7   | | f |  j  k r& |  j  | | f S|  j  | | f S(   sî   
            loc1: A name of a place ('home' or the name of a FruitShop in town)

            loc2: A name of a place ('home' or the name of a FruitShop in town)
        Returns the distance between these two places in this town.
        (   R   (   R   t   loc1t   loc2(    (    sK   /Users/saia/public_html/classes/527-s18/proj/python_basics/tutorial/town.pyt   getDistance=   s    c         C   s   | s
 d S|  j  d | d  } x@ t t |  d  D]( } | |  j  | | | | d  7} q7 W| |  j  | d d  7} | S(   sž   
            route: List of shop names
        Returns the total distance traveled by starting at 'home', going to 
        each shop on the route in order, then returning to 'home'
        i    t   homei   i˙˙˙˙(   R   t   xranget   len(   R   R   t   totalDistancet   i(    (    sK   /Users/saia/public_html/classes/527-s18/proj/python_basics/tutorial/town.pyt   getTotalDistanceOnRouteH   s    &c         C   s]   |  j  |  | } xC | D]; \ } } |  j | |  } | d k	 r | | | 7} q q W| S(   s&  
            orderList: List of (fruit, numPounds) tuples

            route: List of shop names

            gasCost: A number representing the cost of driving 1 mile
        Returns cost of orderList on this route. If any fruit are not available
        on this route, returns None. 
        N(   R   R   R   (   R   R   R   t   gasCostt	   totalCostR
   t	   numPoundst   costPerPound(    (    sK   /Users/saia/public_html/classes/527-s18/proj/python_basics/tutorial/town.pyt   getPriceOfOrderOnRouteV   s    
c         C   s   |  j  S(   N(   R   (   R   (    (    sK   /Users/saia/public_html/classes/527-s18/proj/python_basics/tutorial/town.pyt   getShopsg   s    (	   t   __name__t
   __module__R   R   R   R   R   R!   R"   (    (    (    sK   /Users/saia/public_html/classes/527-s18/proj/python_basics/tutorial/town.pyR       s   						(    (   R   R    (    (    (    sK   /Users/saia/public_html/classes/527-s18/proj/python_basics/tutorial/town.pyt   <module>   s   