java - Bin packing bruteforce method -


i need make program solves bin packing problem, made first fit , greedy algorithms, lecturer says in cases won't find minimal solution problem. decided try bruteforce, have no clue how should check possible solutions. yea.. can explain me or give pseudo-code or something. appreciate lot.

note bin-packing np-hard problem, meaning take excessively long run brute force on it, relatively small input, brute force np-hard problems never idea. link above shows alternatives (or approximations). i'll continue...

recursion makes brute force easy. once understand a basic recursive algorithm, continue reading...

basic idea: (for 3 items, 2 bins, assuming fits, if doesn't skip branch)

put first item in first bin.   put second item in first bin.     put third item in first bin.       woo-hoo! have solution!     remove third item first bin , put second bin.       woo-hoo! have solution!     remove third item second bin.   remove second item first bin , put second bin.     put third item in first bin.       woo-hoo! have solution!     remove third item first bin , put second bin.       woo-hoo! have solution!     remove third item second bin.   remove second item second bin. remove first item first bin , put second bin.   put second item in first bin.     put third item in first bin.       woo-hoo! have solution!     remove third item first bin , put second bin.       woo-hoo! have solution!     remove third item second bin.   remove second item first bin , put second bin.     put third item in first bin.       woo-hoo! have solution!     remove third item first bin , put second bin.       woo-hoo! have solution!     remove third item second bin.   remove second item second bin. remove first item second bin. 

(see how many steps there already? , 3 items , 2 bins)

pseudo-code:

recurse(int itemid)   if pastlastitem(itemid)     if betterthanbestsolution       bestsolution = currentassignment     return   each bin i:     putintobin(itemid, i)     recurse(itemid+1)     removefrombin(itemid, i) 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -