def testBest(maxWeight=20):
    items = buildItems()
    pset = genPowerSet(items)
    taken, val = chooseBest(pset, maxWeight, Item.getValue, Item.getWeight)
    print 'Total value of items taken = ' + str(val)
    for item in taken:
        print '\t', item
Beispiel #2
0
def testBest(maxWeight=20):
    items = buildItems()
    pset = genPowerSet(items)
    taken, val = chooseBest(pset, maxWeight, Item.getValue, Item.getWeight)
    print 'Total value of items taken = ' + str(val)
    for item in taken:
        print '\t', item    
Beispiel #3
0
def testGreedys(maxWeight=20):
    items = buildItems()
    print 'Use greedy by value for knapsack of size maxWeight'
    testGreedy(items, maxWeight, value)
    print 'Use greedy by weight for knapsack of size maxWeight'
    testGreedy(items, maxWeight, weightInverse)
    print 'Use greedy by density for knapsack of size maxWeight'
    testGreedy(items, maxWeight, density)