Posts

Bin Packing with Multiple Bin Sizes

Image
Here is a brute force approach to selecting the optimal set of bins to meet an order when there are multiple stock sizes available. Source on Github Practical Bin Packing ¶ This was motivated by a desire to buy just enough materials to get the job done. In this case the job was a chicken coop I was building. I can buy lumber in standard lengths of 12, 10, 8 or 6 feet at my local building supply store. So what is the lowest cost combination of stock boards that fills the need? In my research I found lots of examples of bin packing with a single size of bin but nothing that fit my situation and limited appetite for in depth study. This code uses a brute force approach to the problem. It enumerates all permutations, discards any that don't meet the bare minimum length then checks each remaining permutation for feasilbility. The feasible options are sorted to find the minmum cost option. In the example below, I first define the stock lengths and their rates . Then I li...

The Travelling Salesman (or Saleswoman) Problem

Image
Poor Willy Loman Imagine you're a sales rep who needs to visit several customers scattered across the country. You want to visit each city just once, in the shortest time or distance and return to your home base.  This is a widely studied optimization problem that has many applications.   It is "NP hard" meaning optimal solutions to real world (big) problems can be prohibitively expensive in terms of computer resources,  As a result, much work has been done to develop algorithms that get near optimal solutions in a feasible amount of time.  I will cover several approaches to this problem using an example from [1] where a prospective college student wants to visit several college campuses across the US before deciding which to attend.   All of the Python scripts and supporting files used for this this post can be found here .   The example forms a "complete graph" i.e. all colleges are connected to every other college.  All of the Python ...