<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kaizen &#187; linear programming</title>
	<atom:link href="http://farfromneutral.com/kaizen/tag/linear-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://farfromneutral.com/kaizen</link>
	<description>Continuous improvement by small changes.</description>
	<lastBuildDate>Sun, 05 Jul 2009 08:55:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using LPSolve to solve the transportation model</title>
		<link>http://farfromneutral.com/kaizen/using-lpsolve-to-solve-the-transportation-model/</link>
		<comments>http://farfromneutral.com/kaizen/using-lpsolve-to-solve-the-transportation-model/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 16:37:19 +0000</pubDate>
		<dc:creator>Jorge</dc:creator>
				<category><![CDATA[Location Planning]]></category>
		<category><![CDATA[Operations Management]]></category>
		<category><![CDATA[Transportation Model]]></category>
		<category><![CDATA[linear programming]]></category>
		<category><![CDATA[location]]></category>
		<category><![CDATA[lp_solve]]></category>
		<category><![CDATA[management]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[operations]]></category>
		<category><![CDATA[transportation model]]></category>

		<guid isPermaLink="false">http://farfromneutral.com/kaizen/?p=45</guid>
		<description><![CDATA[The model is a special procedure of linear programming for finding the minimum cost for distributing homogeneous units of a product from several points of supply (sources) to a number of points of demand (destinations). In terms I'm more comfortable using, that means that the model answers the question: what are the cheapest routes I can use to send a certain number of products from a certain number of suppliers to a certain number of destinations?]]></description>
			<content:encoded><![CDATA[<p>In the other parts of this series, I have examined options for planning a location for a single facility; this time, allow me to tackle something more complex: the <strong>transportation model</strong> (or transportation problem).</p>
<p>The model is a special procedure of linear programming for finding the minimum cost for distributing homogeneous units of a product from several points of supply (<em>sources</em>) to a number of points of demand (<em>destinations</em>). In terms I&#8217;m more comfortable using, that means that the model answers the question: <em>what are the cheapest routes I can use to send a certain number of products from a certain number of suppliers to a certain number of destinations</em>?</p>
<p>To answer this, of course, we need to know several things beforehand:</p>
<ol>
<li>the number of sources, as well as their capacity to supply the products to distribute;</li>
<li>the number of destinations, as well as their demand; and —</li>
<li>the per-unit cost of shipping the products from a certain source to a certain destination.</li>
</ol>
<p>This model is a <a href="http://en.wikipedia.org/wiki/Linear_programming">linear programming</a> model, that is, the relationships among variables is linear: transportation costs are treated as a direct linear function of the number of units shipped. That means, basically, that the more units you send somewhere, the more it&#8217;s gonna cost you. Being an LP problem, it assumes several things:</p>
<ol>
<li>the items to be shipped are homogeneous, or the same (similar);</li>
<li>shipping cost <em>per unit</em> is the same regardless of the number of units shipped; and —</li>
<li>there is onlly one route or mode of transportation being used between each origin and each destination.</li>
</ol>
<p>To illustrate, suppose a clothing manufacturer has three outlets, each with a known amount of demand, and three factories, their capacities also known. For simplicity&#8217;s sake, let&#8217;s call each outlet A, B, and C, and each factory W, X, and Y. Their capacities, demands, and cost to transport per unit is shown below:</p>
<p><a href="http://farfromneutral.com/kaizen/wp-content/uploads/2008/08/lp_table.jpg"><img class="alignnone size-full wp-image-48" title="lp_table" src="http://farfromneutral.com/kaizen/wp-content/uploads/2008/08/lp_table.jpg" alt="" width="500" height="158" /></a></p>
<p>First, note: total demand and total supply are equal; this is what&#8217;s called a <em>balanced condition</em>, and while highly unlikely in real life situations, it&#8217;s enough to demonstrate the procedure for now.</p>
<p>Solving a problem with so few variables by hand is relatively easy, and I&#8217;ll get into more detail about that later. There&#8217;s also a nifty tool for both Microsoft Excel and Sun Open Office Calc called solver that tackles precisely this problem, albeit with some limitations. This time around though, I&#8217;ll illustrate solving this problem using <a href="http://lpsolve.sourceforge.net/5.5/">lp_solve</a>, a <cite> <strong>free</strong> (see <a href="http://lpsolve.sourceforge.net/5.5/LGPL.htm">LGPL</a> for the GNU lesser general public license) linear (integer) programming solver based on the revised simplex method and the Branch-and-bound method for the integers</cite>.</p>
<h4>Why lp_solve?</h4>
<p>Well, if I could only provide one answer for this, it&#8217;d be because it&#8217;s free. Free as in <em>freedom</em>. To use, alter, sell, do stuff. Fortunately, there are other answers as well: it&#8217;s robust and powerful, has an API for a lot of programming languages so you can call the results from, say, Python, and best of all, it&#8217;s very easy to use.</p>
<h4>The process</h4>
<p>Looking at the cost to transport per unit table, we can pretty much see that we don&#8217;t want to be sending any significant number of products from X to B, or Y to C, because they have the highest cost. Instead, we want to maximize the route from W to A, since it&#8217;s significantly cheaper. Unfortunately, W can only supply 56 units, so we&#8217;d have to get the 16 from somewhere; hopefully from Y, since it&#8217;s cheaper than X. But if we do that, we might end up sending from X to B again, which is a no-no. Trying to solve this with mentally is hard — there&#8217;s just too many things to consider. Enter linear programming.</p>
<p>Before we can begin, we need to look at its linear programming formulation — this is the hardest part, trust me, and since it&#8217;s a very specific case of linear programming, that means there&#8217;s really just one way to formulate it. First, consider the decision variables: three factories and three outlets, so we have (3*3) nine decision variables, which we&#8217;ll name as a combination of their names: WA, WB, WC, XA, XB, XC, YA, YB, YC. The first letter identifies the source, or factory, and the second letter identifies their destination, or outlet. Recall, our <em>objective function</em>, that is, what we want our function to do, would be to minimize the total transportation cost; we write it this way:</p>
<p><code>min: 4wa + 8wb + 8wc + 16xa + 24xb + 16xc + 8ya + 16yb + 24yc;</code></p>
<p>Well I&#8217;ll be darned, that looks a lot like C code, doesn&#8217;t it? And it behaves much as you&#8217;d expect: a quick look at the table graphic above and you&#8217;ll see that we&#8217;re basically adding the product of each per-unit cost to each decision variable &#8211; which just so happens to correspond to the cells on the table. Since it&#8217;d cost $4.00 to send a unit of product from W to A, we have <code>4wa</code>, and so on. Nifty.</p>
<p>Next, we&#8217;ll look at the constraints: since each source has a maximum capacity to supply the product, and each destination has a minimum demand, we&#8217;d write that down like this:</p>
<p><code><br />
wa + wb + wc &lt;= 56; /* plant "W" can't ship more than 56 units */<br />
xa + xb + xc &lt;= 82; /* plant "X" can't ship more than 82 units */<br />
ya + yb + yc &lt;= 77; /* plant "Y" can't ship more than 77 units */</code><br />
<code><br />
wa + xa + ya &gt;= 72; /* destination "A" requires at least 72 units */<br />
wb + xb + yb &gt;= 102;/* destination "B" requires at least 102 units */<br />
wc + xc + yc &gt;= 41; /* destination "C" requires at least 41 units */</code></p>
<p>Note that the comments enclosed by /* and */ are exactly that: comments.</p>
<p>With that done, we have enough to solve our problem using lp_solve; simply press the F9 key. Here I&#8217;m using the lp_solve <abbr title="ntegrated Development Environment. A GUI workbench for developing code, featuring facilities like symbolic debugging, version control, and data-structure browsing.">IDE</abbr>, which is available for the Windows platform, but I&#8217;ve run it under WinE and ahd no problems. The results are illustrated below:</p>
<p><a href="http://farfromneutral.com/kaizen/wp-content/uploads/2008/08/lp_solve_1.jpg"><img class="alignnone size-full wp-image-49" title="lp_solve_1" src="http://farfromneutral.com/kaizen/wp-content/uploads/2008/08/lp_solve_1.jpg" alt="" width="500" height="485" /></a></p>
<p><a href="http://farfromneutral.com/kaizen/wp-content/uploads/2008/08/lp_sovle_2.jpg"><img class="alignnone size-full wp-image-50" title="lp_sovle_2" src="http://farfromneutral.com/kaizen/wp-content/uploads/2008/08/lp_sovle_2.jpg" alt="" width="304" height="372" /></a></p>
<p class="clear">What the data is telling us here is that we can send 56 units from W to A, 41 units from X to A, another 41 units from X to C, 31 from Y to A, and 46 from Y to B. Using our objective function above, we can calculate the cost for this solution:</p>
<p><code>cost = 4*0 + 8*56 + 8*0 + 16*41 + 24*0 + 16*41 + 8*31 + 16*46 + 24*0 = 448 + 656 + 656 + 248 + 736 = 2,744</code></p>
<p>So our solution will end up costing $2,744.00, which is the minimum cost do do the transaction.</p>
]]></content:encoded>
			<wfw:commentRss>http://farfromneutral.com/kaizen/using-lpsolve-to-solve-the-transportation-model/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
