Python Implementations of Packing Algorithm -


I am working for an application, I need something like the packing algorithm applied in Python. The basic idea is that I have objects of different sizes that I need to fit in the n cans, where the number of cans is limited and both the objects and the bins Size is definitely fixed. Items / cans can be either 1D or 2D, interested in seeing both. (I think 3D objects probably need more than I need.)

I know that there is a variety of this problem algorithm, decreasing the fit in such a Yekaterinburg And the first fit is to subtract, but I was hoping there might be an implementation in Python (or PHP / C ++ / Java, actually I'm not that pickup). any idea?

  "" "Split a list in sublists whose amount is one Using the first reduction subtraction algorithm is not more than a maximum. For a simple explanation of the method see http://www.ams.org/new-in-math/cover/bins1.html. "" "Category Bin ( Item): "container" for items that have a running yoga "" "def __init __ (self): self.items = [] self.sum = 0 def attached (self, items): self.items. Append (item) DEF :) self.sum + = item DEF ("printable representation" "return" bin (s) C =% d, item =% s) '% (self.sum, str (self.items themselves)) __str pack (values, MAXVALUE): value = according to the order (values, reverse = true) in compartment = [] values For items: Try to fit the item in a bin for # bin in bin: If bin.sum + item & lt; = MAXVALUE: # printing 'add', items, 'to', bin bin. Append ( Item) Break tour: # Item was not fit in any bin, a new bin # printing 'new bin to make', item bin = bin () Bin.append (item) bins.append (Bin) return bins if __name__ == '__main__': Importance A random def pack EndShow (ALIT, Maxvalue): "" Pack a list in the compartment and show results "list with 'print' yoga, yoga (ALIT) , 'Minimum' is required, (Yoga (ALISIT) + maximum value-1) / MAXVALUE, 'cans' box = pack (alist, MAXVALUE) print' using solution ', lane (cans),' cans : ': Print bin print alist = [10,9,8,7 for bin in bin, 6,5,4,3,2,1] Packs endosho (ALA EIT, 11) ALIT = [Random. Range (1) in the Rendent (1, 11) range (100)] Pax EndShow (ALIIT, 11)    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -