示例#1
0
    for item in allItems:
        config.append([item])

else:
    # Iterate through the permutations of the items
    for x in itertools.permutations(items):
        bins = []  # Clear the list of bins out after each new permuatation
        Binny = Bin(cap, [bigItem])  # A bin to begin your packing
        bins.append(Binny)
        # Iterate through each item in this permutation
        for item in x:
            # Don't bother finding out how to fit items if it's not better
            if len(bins) >= curMin:
                break
            # Still room in this bin?
            if Binny.free_capacity() >= item:
                Binny.add(item)
            # No...we need a fresh bin
            else:
                Binny = Bin(cap, [])
                Binny.add(item)
                bins.append(Binny)
        # We've put all the items in the perm into bins...
        # If we've reached a new minimum of bins used, save the
        # minimum and keep a "proof" copy of the configuration that worked
        if len(bins) < curMin:
            curMin = len(bins)
            config = copy.deepcopy(bins)
        # If we used the true minimum number of bins, we're definitely done
        if len(bins) == minBins:
            break
示例#2
0
	for item in allItems:
		config.append([item])

else:
	# Iterate through the permutations of the items
	for x in itertools.permutations(items):
		bins = []										# Clear the list of bins out after each new permuatation
		Binny = Bin(cap, [bigItem])	# A bin to begin your packing
		bins.append(Binny)
		# Iterate through each item in this permutation
		for item in x:						
			# Don't bother finding out how to fit items if it's not better
			if len(bins) >= curMin:
				break
			# Still room in this bin? 
			if Binny.free_capacity() >= item:
				Binny.add(item)
			# No...we need a fresh bin
			else:
				Binny = Bin(cap, [])
				Binny.add(item)
				bins.append(Binny)
		# We've put all the items in the perm into bins...
		# If we've reached a new minimum of bins used, save the
		# minimum and keep a "proof" copy of the configuration that worked
		if len(bins) < curMin:
			curMin = len(bins)
			config = copy.deepcopy(bins)
		# If we used the true minimum number of bins, we're definitely done
		if len(bins) == minBins:
			break