コード例 #1
0
def shopSmart(orderList, fruitShops):
    """
        orderList: List of (fruit, numPound) tuples
        fruitShops: List of FruitShops
    """
    "*** YOUR CODE HERE ***"
    low = 1000000.0
    for shop in fruitShops:
        price = shop.getPriceOfOrder(orderList)
        if price < low:
            low = price
            lowShopName = shop.getName()
    return "<FruitShop: " + lowShopName + ">"
コード例 #2
0
ファイル: shopSmart.py プロジェクト: ankitvora7/CS-188
def shopSmart(orderList, fruitShops):
    """
        orderList: List of (fruit, numPound) tuples
        fruitShops: List of FruitShops
    """
    "*** YOUR CODE HERE ***"
    low = 1000000.0
    for shop in fruitShops:
      price = shop.getPriceOfOrder(orderList)
      if price<low:
        low = price
        lowShopName = shop.getName()
    return "<FruitShop: "+lowShopName+">"
コード例 #3
0
def shopSmart(orderList, fruitShops):
    """
        orderList: List of (fruit, numPound) tuples
        fruitShops: List of FruitShops
    """
    lowestPrice = 9999
    bestShop = None
    for shop in fruitShops:
        cost = shop.getPriceOfOrder(orderList)
        print("shop: " + shop.getName() + " cost: " + str(cost))
        if cost < lowestPrice:
            print("new lowest price: " + str(cost))
            lowestPrice = cost
            bestShop = shop
    return bestShop
コード例 #4
0
ファイル: shopSmart.py プロジェクト: yllaw/cs188
def shopSmart(orderList, fruitShops):
    """
        orderList: List of (fruit, numPound) tuples
        fruitShops: List of FruitShops
    """
    "*** YOUR CODE HERE ***"
    priceOfOrder = [];
    nameOfShop = [];
    cheaptestShop = 0;
    for shop in fruitShops:
      priceOfOrder.append(shop.getPriceOfOrder(orderList))
      nameOfShop.append(shop.getName())
    for i in range(1,len(priceOfOrder)):
      if priceOfOrder[cheaptestShop] > priceOfOrder[i]:
        cheaptestShop = i 
    return "<FruitShop: " + nameOfShop[cheaptestShop] + ">"
コード例 #5
0
ファイル: shopSmart.py プロジェクト: iceNuts/MY-AI-Labs
def shopSmart(orderList, fruitShops):
    """
        orderList: List of (fruit, numPound) tuples
        fruitShops: List of FruitShops
    """
    fruit_shop = None
    shop_cost = 999999999
    for shop in fruitShops :
        cost = 0
        s_name = shop.getName()
        """ignore the exception of non-existence"""
        cost = shop.getPriceOfOrder(orderList)
        if cost <= shop_cost :
            fruit_shop = shop
            shop_cost = cost
    return fruit_shop
コード例 #6
0
def shopSmart(orderList, fruitShops):
    """
        orderList: List of (fruit, numPound) tuples
        fruitShops: List of FruitShops
    """

    leastPrice = float("inf")
    for shops in fruitShops:
        price = shops.getPriceOfOrder(orderList)
        shop = shops
        print "***\tThe price of " + shop.getName() + " is " + str(price)
        if price < leastPrice:
            leastPrice = price
            cheapestShop = shop

    return cheapestShop
コード例 #7
0
ファイル: town.py プロジェクト: Bguillenn/IA---Lab01
    def getFruitCostPerPoundOnRoute(self, fruit, route):
        """
            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
        """
        routeShops = [shop for shop in self.shops if shop.getName() in route]
        costs = []
        for shop in routeShops:
            cost = shop.getCostPerPound(fruit)
            if cost is not None:
                costs.append(cost)
        if not costs:
            # None of the shops carry this fruit
            return None
        return min(costs)
コード例 #8
0
    def getFruitCostPerPoundOnRoute(self, fruit, route):
        """
            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
        """
        routeShops = [ shop for shop in self.shops if shop.getName() in route ]
        costs = []
        for shop in routeShops:
            cost = shop.getCostPerPound(fruit)
            if cost is not None:
                costs.append(cost)
        if not costs:
            # None of the shops carry this fruit
            return None
        return min(costs)
コード例 #9
0
ファイル: shopAroundTown.py プロジェクト: leoleblanc/CS188
def shopAroundTown(orderList, fruitTown, gasCost):
    """
        orderList: List of (fruit, numPound) tuples
        fruitTown: A Town object
        gasCost: A number representing the cost of going one mile
    Returns a list of shops in the order that is the optimal route to take when
    buying the fruit in the orderList
    """
    possibleRoutes = []
    subsets = getAllSubsets(fruitTown.getShops())
    for subset in subsets:
        names = [ shop.getName() for shop in subset ]
        if fruitTown.allFruitsCarriedAtShops(orderList, names):
            possibleRoutes += getAllPermutations(names)
    minCost, bestRoute = None, None
    for route in possibleRoutes:
        cost = fruitTown.getPriceOfOrderOnRoute(orderList, route, gasCost)
        if minCost == None or cost < minCost:
            minCost, bestRoute = cost, route
    return bestRoute
コード例 #10
0
def shopAroundTown(orderList, fruitTown, gasCost):
    """
        orderList: List of (fruit, numPound) tuples
        fruitTown: A Town object
        gasCost: A number representing the cost of going one mile
    Returns a list of shops in the order that is the optimal route to take when
    buying the fruit in the orderList
    """
    possibleRoutes = []
    subsets = getAllSubsets(fruitTown.getShops())
    for subset in subsets:
        names = [shop.getName() for shop in subset]
        if fruitTown.allFruitsCarriedAtShops(orderList, names):
            possibleRoutes += getAllPermutations(subset)
    minCost, bestRoute = None, None
    for route in possibleRoutes:
        cost = fruitTown.getPriceOfOrderOnRoute(orderList, route, gasCost)
        if minCost == None or cost < minCost:
            minCost, bestRoute = cost, route
    return bestRoute