## All The Dots Are Connected / It's Not Rocket Science

Transportation and assignment problems with r.

In the previous post “ Linear Programming with R ” we examined the approach to solve general linear programming problems with “Rglpk” and “lpSolve” packages. Today, let’s explore “lpSolve” package in depth with two specific problems of linear programming: transportation and assignment.

## 1. Transportation problem

Code & Output:

The solution is shown as lptrans$solution and the total cost is 20500 as lptrans$objval.

## 2. Assignment problem

Similarly, the solution and the total cost are shown as lpassign$solution and lpassign$objval respectively.

This article was really helpful, but I am facing issue while solving unbalanced transportation problem when there is excess demand. Could you please guide me on what has to be done in this case.

Hello sir, this article was really helpful. But, I am facing issue while solving unbalanced transportation problem when there is excess demand, it gives solution as no feasible solution. works perfectly fine for balanced and excess supply problems. Could you please guide me on why this issue is occurring and a possible solution for the same. Thank you.

- Linear programming

## Solving linear transport problem with lp.transport in R, using lpSolve

- Linnart Felkl

The transportation problem is one of the classical problems teached in linear programming classes. The problem, put simply, states that a given set of customers with a specified demand must be satisfied by another set of supplier with certain capacities (“supply”). For a detailed explanation of the transportation problem you can, e.g. read this: https://econweb.ucsd.edu/~jsobel/172aw02/notes8.pdf .

The lpSolve package available in R can be used for modelling and solving the transportation problem.

I will show how to do this. I define a problem in which 3 suppliers seek to satisfy 4 customers. The suppliers have capacities 100, 300, and 400, respectively. The customers have demand 100, 100, 200, and 400, respectively. Furthermore, the cost for supplying customer i by supplier j is defined for every possible combination and stated in a cost matrix.

Using this information we can model and solve the transportation problem (deciding which demand to fulfill by which supplier) with the lpSolve package in R.

First, I prepare the modeling-part:

Then, I solve the problem:

Let us review the “optimal” costs:

Let us review the optimal solution of the transportation problem (i.e., the optimal material flows to this problem):

The assignment problem is another classical problem, and you can see how I solved it in R here: Cost minimal production scheduling – solving the assignment problem with lpSolve, using lp.assign.

Data scientist focusing on simulation, optimization and modeling in R, SQL, VBA and Python

## You May Also Like

## Optimized SCM capacity scheduling

## Inventory simulation for optimized stock

## Conveyor system optimization procedure

Leave a reply.

- Default Comments
- Facebook Comments

hi. I am trying to “go to the next level”. I want to look deeper than this and say, “OK, truck A costs me $100 and takes 3 weeks, but flight A costs me $200 and takes just 1 week to move the good” For me, i am still trying to move things from A to B, but now i am expanding it to try and look at the total cost of holding the inventory, reduction in cash flow and the cost of delivery. I want to “optimise” my transportation so that maybe 90% of my forecast is shipped via truck, then i can “top up” with the flight if demand requires. Any suggestions how to approach this issue or where to turn for some guidance? Thanks

thanks for your comment.

You can try to formulate your problem as a linear optimization problem, from scratch. For example, the cost of holding inventory can be derived from the travel time, and the travel time depends on transportation distance (one variable) and transportation mode (binary or integer variable).

The objective of covering 90% of your forecast by truck could be formulated as a constraint, or maybe a better approach would be to define two objective functions, and to apply multi-goal linear programming.

If you provide some more info I might very well try to model it and post it, maybe in a simplified version!

## Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed .

- Entries feed
- Comments feed
- WordPress.org

## Privacy Overview

## Unbalanced Transportation Problem Numerical

What is unbalanced transportation problem.

A Transportation Problem where the summation of Supply is not equal to summation of Demand is called Unbalanced Transportation Problem.

## Balance the following problem for BFS using Least Cost Method:

Here, BFS means Basic Feasible Solution. This is also sometimes referenced as IBFS, meaning Initial Basic Feasible Solution.

This problem can also be solved using Vogel's Approximation Method, North West Corner Method or Least Cost Method. But as mentioned in the problem statement we'll be solving it using Least Cost Method.

## Step 1: Balance the Problem

In the given problem:

Σ S u p p l y = 115 \varSigma Supply = 115 Σ S u ppl y = 115 Σ D e m a n d = 145 \varSigma Demand = 145 Σ De man d = 145

The given problem is not balanced as Σ S u p p l y ≠ Σ D e m a n d \varSigma Supply \not = \varSigma Demand Σ S u ppl y = Σ De man d .

To balance this, a dummy row D 1 D_1 D 1 is added with supply of 30 units ( Σ D e m a n d − Σ S u p p l y = 30 ) (\varSigma Demand - \varSigma Supply = 30) ( Σ De man d − Σ S u ppl y = 30 ) in order to balance the problem.

## Step 2: Select the lowest cost and allocate

In this step, we'll start by selecting the lowest cost from the entire matrix and allocate the minimum value from Supply or Demand to it.

Note: When selecting the lowest cost we should NOT consider the dummy row that we added to balance the problem.

## Step 3: Remove the fulfilled row or column and prepare a new matrix

Now we shall remove the row or column for which the demand or supply has been fulfilled and prepare a new matrix.

Now prepare a new matrix:

## Step 4: Repeat the procedure until all the allocations are done

- Column B fulfilled

- Remove column B

- Prepare new matrix

- Repeat allocation where Row 'R' is fulfilled

- Remove row R

- Repeat allocation where Column 'C' is fulfilled

- Remove column C

- Repeat allocation where Row 'Q' is fulfilled

- By this step, we have completed all the allocations in the matrix given in the problem statement.

## Step 5: Calculate the transportation cost

Now that we have completed all the allocations as done above, we'll use all the allocations and calculate the transportation cost.

- Transportation Cost:

In the problem above we have seen that Σ D e m a n d > Σ S u p p l y \varSigma Demand \gt \varSigma Supply Σ De man d > Σ S u ppl y , so we added a Dummy row 'D1' to balance the problem. Likewise, if Σ S u p p l y > Σ D e m a n d \varSigma Supply \gt \varSigma Demand Σ S u ppl y > Σ De man d then, we should add a Dummy column and then solve the problem. Later the problem can be solved by any of the following methods: North-West corner method Least cost method Vogel's Approximation Method (VAM)

## Suggested Notes:

## Modified Distribution Method (MODI) | Transportation Problem | Transportation Model

## Stepping Stone | Transportation Problem | Transportation Model

## Vogel’s Approximation Method (VAM) | Method to Solve Transportation Problem | Transportation Model

## Transportation Model - Introduction

## North West Corner Method | Method to Solve Transportation Problem | Transportation Model

## Least Cost Method | Method to Solve Transportation Problem | Transportation Model

## Tie in selecting row and column (Vogel's Approximation Method - VAM) | Numerical | Solving Transportation Problem | Transportation Model

## Assignment Model | Linear Programming Problem (LPP) | Introduction

## Critical Path Method [CPM] - Steps and Introduction | Network Analysis | Operation Research

## Crashing Special Case - Multiple (Parallel) Critical Paths

## Crashing Special Case - Indirect cost less than Crash Cost

## Basics of Program Evaluation and Review Technique (PERT)

## Numerical on PERT (Program Evaluation and Review Technique)

## Network Analysis - Dealing with Network Construction Basics

## Construct a project network with predecessor relationship | Operation Research | Numerical

## Graphical Method | Methods to solve LPP | Linear Programming

## Basics of Linear Programming

## Linear Programming Problem (LPP) Formulation with Numericals

All comments that you add will await moderation. We'll publish all comments that are topic related, and adhere to our Code of Conduct .

Want to tell us something privately? Contact Us

## Post comment

## Education Lessons

Stay in touch, [notes] operation research, [notes] dynamics of machinery, [notes] maths, [notes] science, [notes] computer aided design.

- DSA for Beginners
- DSA Tutorial
- Data Structures
- Linked List
- Dynamic Programming
- Binary Tree
- Binary Search Tree
- Divide & Conquer
- Mathematical
- Backtracking
- Branch and Bound
- Pattern Searching
- Write an Interview Experience
- Share Your Campus Experience
- Transportation Problem | Set 4 (Vogel’s Approximation Method)
- Transportation Problem | Set 7 ( Degeneracy in Transportation Problem )
- Transportation Problem | Set 2 (NorthWest Corner Method)
- Transportation Problem | Set 1 (Introduction)
- Check if any large number is divisible by 19 or not
- Check if any large number is divisible by 17 or not
- Multiply N complex numbers given as strings
- Transportation Problem | Set 3 (Least Cost Cell Method)
- Transportation Problem | Set 6 (MODI Method – UV Method)
- Determine whether the given integer N is a Peculiar Number or not
- Game Theory (Normal-form Game) | Set 6 (Graphical Method [2 X N] Game)
- Game Theory (Normal-form Game) | Set 4 (Dominance Property-Pure Strategy)
- Count number of pairs with positive sum in an array
- Game Theory (Normal-form Game) | Set 7 (Graphical Method [M X 2] Game)
- Why probability of an event always lie between 0 and 1?
- Reservoir Sampling
- Find the type of triangle from the given sides
- What is the result of ∞ – ∞?
- Game Theory (Normal-form Game) | Set 5 (Dominance Property-Mixed Strategy)
- Aronson’s Sequence
- SQL | Join (Inner, Left, Right and Full Joins)
- find command in Linux with examples
- What is Memory Leak? How can we avoid?
- Asymptotic Notation and Analysis (Based on input size) in Complexity Analysis of Algorithms
- Commonly Asked Data Structure Interview Questions | Set 1
- How to write a Pseudo Code?
- Types of Asymptotic Notations in Complexity Analysis of Algorithms
- Worst, Average and Best Case Analysis of Algorithms
- Mutex vs Semaphore
- SQL | GROUP BY

## Transportation Problem | Set 5 ( Unbalanced )

An introduction to the transportation problem has been discussed in this article. In this article, the method to solve the unbalanced transportation problem will be discussed.

Now that the problem has been updated to a balanced transportation problem, it can be solved using any one of the following methods to solve a balanced transportation problem as discussed in the earlier posts:

- NorthWest Corner Method
- Least Cost Cell Method
- Vogel’s Approximation Method

Solve DSA problems on GfG Practice.

## Please Login to comment...

Improve your coding skills with practice.

## Getting Proactive With Predictive Analysis

Submit support requests and browse self-service resources.

Explore Support

- About IMSL by Perforce
- Careers at Perforce
- Request Support
- Student Licenses

## Solving the Transportation Problem

Minimizing the cost of transporting products from production and storage locations to demand centers is an essential part of maintaining profitability for companies who deal with product distribution. Since transportation costs are generally not controllable, minimizing total cost requires making the best product routing decisions. This essential problem was first formulated as a linear programming problem in the early 1940’s and is popularly known as the transportation problem.

In this blog, we give an overview of the transportation problem and how the transportation algorithm — as implemented in IMSL — can be used to solve different variations of the transportation problem.

## What Is the Transportation Problem?

Balanced transportation problem example, unbalanced transportation problem example.

The transportation problem is a type of linear programming problem designed to minimize the cost of distributing a product from \(M\) sources to \(N\) destinations.

The transportation problem can be described using examples from many fields. One application is the problem of efficiently moving troops from bases to battleground locations. Another is the optimal assignment of agents or workers to different jobs or positions. By far the most common application is of moving goods from multiple factories to multiple warehouse locations, or from warehouses to storefronts.

## Transportation Problem Example

Consider the following example:

XYZ Inc. has two factories in different locations around the country where they produce widgets. Their sales partner has three central warehouses where they ship these widgets to their various customers. The factories can produce a given number of widgets per week each and the expected demand for each warehouse is also known. There is a shipping cost from each factory to each warehouse. Which factory should produce and ship how many widgets to which warehouses to meet the demand at each location with minimal cost?

This problem statement has all the components of a typical transportation problem. The sources and destinations are generic — they could be logging sites and sawmills, factories and warehouses, warehouses and stores, bases, and battlefields, and so on.

In each case, there is some demand or need \(D\) at each of \(N\) locations, some supply \(S\) at each of \(M\) locations, and a cost, \(c\), associated with transporting (or using) one unit from a particular \(M\) location to a particular \(N\) location. There will be a total of \(M\) x \(N\) such costs.

The cost, \(c\), can be a calculation involving factors such as time, distance, material costs, and so on, but it may be any quantity that is relevant to the problem.

Once supplies, demands, and costs are known, the problem is to determine the number of units, \(x\), that should be produced and sent from each of the \(M\) supply centers to each of the \(N\) demand locations.

The total cost is the sum of all individual costs times the individual units to be produced and shipped from each supply center to each demand center. Framing this as an optimization problem, the goal is to minimize the total cost:

$$ \sum_{i=1}^M \sum_{j=1}^N c_{ij}x_{ij} $$

Simultaneously, there are some rules (constraints) that must be satisfied:

- The number of units shipped must be less than or equal to the total supply.
- The number shipped must match, or meet, the demand at each location.
- The number of units to ship must be greater than or equal to zero (no negative values).

In the case of a balanced transportation problem, for which the total demand is equal to the total supply, the constraints have the following mathematical representation:

$$ \sum_{j=1}^N x_{ij} = S_{i}, i=1, …, M $$

$$ \sum_{i=1}^M x_{ij} = D_{j}, j=1, …, N $$

$$ x_{ij} \geqslant 0, i=1 …,M, j=1 …N $$

Note that there may be cases of excess supply or excess demand leading to an unbalanced problem. This case is addressed below and can be solved similarly using dummy variables and possibly penalties for unmet demand or storage costs for excess supply.

The total cost function along with the three constraints define a well-formed linear programming (LP) optimization problem with linear constraints. It is known specifically as the balanced transportation problem.

Unlike many LP problems, the transportation problem is feasible to solve by hand using a series of tables and well-documented strategies such as the Northwest-Corner Method to find an initial basic feasible solution and then using techniques like the Least-Cost Method or the Stepping Stone Method .

Working through a problem by hand simply requires repeatedly drawing tables and manual refinement starting with an initial basic feasible solution. While it can be instructive, solving by hand is not practical or scalable for real-world problems.

For larger problems or to realize any level of scalability, a computer-based method is preferred. Spreadsheet solutions are possible as well, but often require significant rework whenever the number of supply or demand centers changes.

The IMSL Library algorithm allows users to solve problems of nearly any size with a simple programming interface. The IMSL C function is imsl_f_transport() with a short list of required arguments and a few optional arguments. Using the terminology introduced above, the calling sequence using only the required arguments is:

where each variable is defined as:

- x = a pointer to the solution matrix of size M x N containing the solution (the optimal routing of supply)
- M = the number of sources (supply locations)
- N = the number of sinks (demand locations)
- S = an array of size \(M\) containing the supply capacities
- D = an array of size \(N\) containing the demand requirements
- c = an array of size \(M\) x \(N\) containing the per-unit cost matrix

Want to try this for yourself? Request a free trial of IMSL C now. >>

Optional arguments to the function provide additional capabilities such as limiting the number of iterations (by default there is no limit) and output of the dual solution and total cost of the optimal routing.

The algorithm used is a revised simplex method to solve a sparse LP problem with \(M\) + \(N\) constraints and \(M\) x \(N\) variables. Further details of the algorithm can be found in chapter 5 of Sewell (2005).

Consider the word problem stated above again, but this time with some actual values. XYZ Inc. has two factories with weekly production rates of 40 and 20 widgets. These widgets must be shipped to three warehouses that have a demand of 25, 10, and 25 units. The cost to ship between each location is known (see the grid below). Which factory should produce and ship how many widgets to which warehouses to meet the demand at each location with minimal cost?

The standard table format of this problem is:

This table format is used throughout this paper for both the problem statement and solutions. When the upper leftmost cell is “(solution)” the contents are the solution matrix, otherwise it’s a cost matrix of specified units. The central values in the table represent the point-to-point per unit shipping cost, such that it costs $550 to ship from Factory A to Warehouse 1. Note that this is a balanced problem where the total supply of 60 units equals the total demand.

## Balanced Transportation Problem Solution

The C code to solve this problem definition using the IMSL algorithm is as follows, including the optional output parameter to display the total cost:

Executing the program produces the following output:

Using the previous table format, replacing unit costs with the number of units gives:

This table view allows easy confirmation that the supply for each factory and the demand at each warehouse is fully satisfied.

Not every transportation is necessarily balanced. When supply exceeds demand, an alternate technique is not required, especially if there are no storage costs associated with not sending units to the destination. However, when there is excess demand, the problem statement is infeasible as there is no solution that can satisfy the demand at each destination. The IMSL algorithm will issue a warning of IMSL_INSUFFICIENT_CAPACITY if this condition is encountered, although it will still return the best solution possible. When attempting to solve an unbalanced problem, best practices dictate the use of dummy variables to take up the slack.

Consider an example of allocating rental cars. For simplicity, generic locations will be used and the cars are assumed to be fungible (any car can be substituted for any other car). There is also a storage cost to keep an unwanted car at an origin location which must be accounted for. The base problem given is: Sites A, B, and C have 8, 12, and 10 cars on site, while Destinations X, Y, and Z require 9, 7, and 11 cars respectively. The storage cost for each site is 100, 100, and 80. The cost to move the cars between sites is shown in the table:

## Unbalanced Transportation Problem Solution

From this problem statement, it is clear that demand (27 cars) is less than the supply (30 cars), so three cars will need to be kept at one or more source locations. To account for this, one would add a dummy destination site with the appropriate storage cost:

In this form, the problem is balanced. Except for now including the storage cost and location of the extra supply, the solution returned from the IMSL transport function is the same in either case, thus there is no strict requirement in the algorithm for the problem to be balanced. The source code for this problem is included in Appendix A, with the solution matrix as follows, and a total cost of $12,880:

Alternatively, if a problem indicates an excess demand, a similar dummy column can be utilized, especially if there is a known cost for missing the demand (like lost revenue from dissatisfied customers). Sometimes there is no cost associated with missing demand or excess supply, and in those cases the value in the cost matrix for the dummy row or column would simply be zero.

There may also be special cases where one or more destinations cannot be reached from one or more source locations. In this case, the user should use an arbitrarily large number in the cost matrix to encourage the algorithm to allocate zero units for this unreachable condition. A value an order of magnitude or two larger than any other cost in the matrix usually suffices.

Sewell, Granville (2005), Computational Methods of Linear Algebra, second edition, John Wiley & Sons, New York.

## Final Thoughts

In this blog, we looked at the transportation problem and demonstrated the use of the IMSL C algorithm imsl_f_transport() to solve both balanced and unbalanced transportation problems.

In our next blog, we’ll look at two special cases of the transportation problem, the assignment problem, and the transshipment problem.

## Easily Solve the Transportation Problem With IMSL

Solving the transportation problem, regardless of the complexity, is much more surmountable with transportation algorithms included in IMSL.

Whether you’re working in C/C++, Fortran, Java, or Python, you can evaluate the IMSL library for your application free. Try it today via the link below.

Try IMSL Free

## IMAGES

## VIDEO

## COMMENTS

An unbalanced diet can lead to health problems like high blood pressure, obesity, diabetes, tooth decay, coronary heart disease, hypertension, osteoporosis, malnutrition and osteoarthritis.

Signs of unbalanced tires include steering wheel vibration, seat vibration, excessive wear and increased fuel consumption. In order for a vehicle to operate properly, the tires must remain in balance. Unbalanced tires can cause expensive pr...

Whether you’re watching a tutorial, listening to music, or simply enjoying a vlog, there’s nothing more frustrating than encountering sound problems while watching YouTube videos. Muffled audio, echoey voices, or unbalanced sound can quickl...

The transportation problem is a special type of linear programming problem where the objetive consists in minimizing transportation cost of a

This article was really helpful, but I am facing issue while solving unbalanced transportation problem when there is excess demand. Could you

The problem, put simply, states that a given set of customers with a specified demand must be satisfied by another set of supplier with certain

Certified Quality Problem Solving Professional https://academy.bilalconsultancy.uk/c... 9. Power BI + MS Excel (Package)

A Transportation Problem where the summation of Supply is not equal to summation of Demand is called Unbalanced Transportation Problem.

Transportation Problem | Set 5 ( Unbalanced ) · Solution: In this type of problem, the concept of a dummy row or a dummy column will be used.

The transportation problem can be represented as a linear ... such as the unbalanced transportation problem, where the total supply is not

NEW APPROACH TO SOLVE UNBALANCED. TRANSPORTATION PROBLEMS USING LEAST. COST METHOD. A.Sridhar1 and R. Allah Pitchai2. 1Department of Mathematics,.

Unbalanced: When the supply and demand are not equal then it is said to be an unbalanced transportation problem. In this type of problem, either a dummy row

Unbalanced transportation problem, Linear programming Problem, REDI Method, MODI meth- od. ABSTRACT. Unbalanced transportation problem is a special type of

In this blog, we look at how to solve the transportation problem via transportation algorithms for both balanced and unbalanced