Home / Operations Research / Transportation Problem Calculator
Operations Research and Optimization
Transportation Problem Calculator (Least Cost + MODI)
In short: the transportation problem finds the cheapest way to ship from sources to destinations. Enter a cost matrix with supplies and demands below, and this tool returns the optimal shipment plan and minimum total cost, balancing unbalanced problems automatically with a zero-cost dummy.
Solve a transportation problem
minimize Σ cₓₕ xₓₕ subject to supplies and demands → optimal shipment plan
Minimum total cost
1,020
Enter a cost matrix, supplies, and demands to solve.
What the transportation problem solves
The transportation problem is one of the oldest and most useful models in operations research, and its question is intensely practical: given several places that can supply a good and several places that need it, each route with its own per-unit shipping cost, how much should move on each route to meet every demand from the available supply at the lowest total cost? It is the mathematics behind distributing product from factories to warehouses, from warehouses to stores, from power plants to regions, or any situation where a homogeneous commodity flows from sources to destinations and cost depends on the route. Because the structure recurs everywhere in logistics, the model is a staple of both the classroom and the distribution planner’s toolkit.
What makes the problem tractable and elegant is its structure. The only constraints are that each source ships out exactly its supply and each destination receives exactly its demand, and the objective is a simple sum of route cost times units shipped. That special form means the problem always has a whole-number optimal solution when supplies and demands are whole numbers, and it can be solved by fast dedicated methods rather than general-purpose optimization. It also means a balanced problem, where total supply equals total demand, always has a feasible solution, and any imbalance can be repaired by adding a dummy source or destination to soak up the difference.
This calculator finds the provably optimal shipment plan for any transportation problem you enter. Type the cost matrix with one source per line, list the supplies and the demands, and it returns the optimal allocation, how many units to send on each route, together with the minimum total cost and the number of routes used. It balances unbalanced problems automatically by adding a zero-cost dummy and tells you which one it added, and it handles the degeneracy that trips up hand solutions. Everything runs in your browser, and nothing you enter is stored.
How this calculator works, step by step
Start with the cost matrix. Enter one source per line, and on each line put the per-unit shipping cost to each destination, separated by spaces or commas, keeping the destinations in the same order on every line. Then list the supplies, one number per source in the same order as the lines, and the demands, one number per destination in the same order as the columns. The calculator opens with a worked three-source, four-destination example already filled in, so you can see a complete optimal plan and its cost before changing anything.
As soon as the input is valid the tool solves it. It first checks whether the problem is balanced; if total supply and total demand differ, it adds a dummy source or destination at zero cost to balance them and notes this below the result. It then builds an initial feasible plan by the least-cost method and improves it to the optimum with the MODI method, handling any degeneracy along the way. The whole process is instant and re-runs live as you edit, so you can explore how changing a cost or a supply shifts the optimal plan.
The result panel headlines the minimum total cost, then shows the optimal allocation as a matrix: rows are the sources, columns are the destinations, and each cell is how many units to ship on that route, with a dot where a route is unused. The supply and demand totals frame the matrix so you can verify every source is emptied and every destination filled. Below, a note states whether the problem was balanced or which dummy was added, and a chart breaks the total cost down by source. Download a PDF or CSV of the plan or share it; all of it happens locally.
How the solver reaches the optimum
The calculator uses the two-stage approach that is standard for the transportation problem, because the structure rewards a specialized method far more efficient than throwing the general simplex at it. The first stage produces a feasible starting plan: the least-cost method scans for the cheapest available route, ships as much as that route’s supply and demand allow, crosses off whichever is exhausted, and repeats until everything is allocated. This gives a plan that already respects every supply and demand, and by favouring cheap routes it usually starts close to optimal, though it is rarely optimal on its own.
The second stage is the MODI method, which turns a feasible plan into the optimal one. It assigns each source and each destination a potential, chosen so that for every route actually used, the source potential plus the destination potential equals that route’s cost.
With those potentials in hand, it evaluates every unused route: if the route’s cost is less than the sum of its two potentials, sending units along it would lower the total cost, so the plan is not yet optimal. The method then traces a closed loop that alternates between used routes, shifts as many units around that loop as possible into the improving route, and recomputes.
When no unused route beats its potentials, the plan is optimal and the method stops. Degeneracy, when too few routes are in use for the potentials to be computed, is handled by inserting a zero-unit route, which this calculator does automatically so the process never stalls.
Five worked examples you can follow
Example 1: the default balanced problem
The calculator opens with three sources of supply 35, 50, and 40 and four destinations of demand 45, 20, 30, and 30, a balanced problem since both total 125, with the cost matrix shown. The optimal plan ships at a minimum total cost of 1,020. Reading the allocation, you can see which routes carry units and which stay empty, and that every source is fully shipped and every destination fully supplied. This is the canonical textbook problem, and it is a good one to change a single cost in and watch the optimal routing and total cost shift in response.
Example 2: supply exceeds demand
Suppose the sources can supply more than the destinations need. Enter supplies that total more than the demands, and the calculator balances the problem by adding a dummy destination whose demand equals the surplus and whose shipping cost is zero from every source. The optimal plan then routes the genuinely needed units at least cost and sends the leftover supply to the dummy. Reading the result, the units assigned to that dummy destination are exactly the supply that is best left unshipped, which tells you not only how to ship but how much capacity is surplus and where it sits.
Example 3: demand exceeds supply
Now the reverse: the destinations need more than the sources can provide. The calculator adds a dummy source whose supply equals the shortfall, again at zero cost, and solves. The units the optimal plan draws from that dummy source are the demand that cannot be met, and their location tells you which destinations go short in the least-cost plan. This is valuable in practice, because when you cannot satisfy everyone the model shows the cheapest way to allocate what you have and makes the unavoidable shortfall explicit rather than hiding it.
Example 4: a small hand-checkable case
Try a two-source, two-destination problem with costs 4 and 6 in the first row and 5 and 3 in the second, supplies 20 and 30, and demands 10 and 40. The least-cost method fills the cheapest route first, the second source to the second destination at cost 3, and the optimum works out to a total cost of 190. A case this small can be checked by hand in a minute, which makes it a good way to confirm you are reading the allocation matrix correctly before trusting the tool on a larger problem where hand-checking is impractical.
Example 5: reading the cost breakdown
For any solved problem, the chart shows how the total cost divides among the sources, the sum of units shipped times cost for each source’s routes. This is often the most useful managerial view: it tells you which supply point accounts for most of the shipping bill, which can point to where a cost reduction, a closer supplier, or a capacity change would save the most. The allocation matrix says how to ship; the cost breakdown says where the money goes, and reading them together turns the optimum from a single number into an actionable distribution plan.
Three expert tips for distribution planning
Let the dummy tell you the slack
When the problem is unbalanced, do not ignore the dummy row or column. Its shipments are exactly your surplus capacity or your unmet demand, which is often the insight you actually needed.
Keep the matrix aligned
Every cost row must have one entry per destination, in the same order, and the supply and demand lists must match the rows and columns. A shifted number silently solves a different problem.
Whole numbers in, whole numbers out
If your supplies and demands are integers, the optimal shipments will be too, automatically. You never need to round, so treat any fractional-looking result as a sign of a mistyped input.
Balancing supply and demand
A transportation problem can only be solved once total supply equals total demand, because the solution must ship out every unit of supply and fill every unit of demand, which is impossible if the two totals differ. Real problems are frequently unbalanced, a plant network with more capacity than orders, or a set of stores whose needs exceed what the warehouses hold, so balancing is a routine first step rather than an exception. The standard technique is to add a dummy, an artificial source or destination that exists only to absorb the mismatch, with a shipping cost of zero on every one of its routes so that it changes the feasibility of the problem without changing its real cost.
Which dummy you add depends on the direction of the imbalance, and the interpretation of its shipments is where the practical value lies. When supply exceeds demand, a dummy destination is added with a demand equal to the surplus; the units the optimal plan sends to it are the supply that is cheapest to leave unshipped, and their source tells you which location holds the excess capacity.
When demand exceeds supply, a dummy source is added with a supply equal to the shortfall; the units drawn from it are the demand that cannot be met, and their destination tells you who goes short. This calculator detects the imbalance, adds the correct dummy automatically, solves the balanced version, and states in the note which dummy it used, so you get both the optimal plan for the real routes and a clear reading of the surplus or shortfall.
Treating the dummy as informative rather than as a mere technical fix is what turns an unbalanced problem into a capacity or service insight.
A special, well-behaved linear program
The transportation problem is formally a linear program: minimize the total of cost times units over all routes, subject to each source shipping its supply and each destination receiving its demand, with all shipments non-negative.
In principle you could feed it to the general simplex method, the engine behind the linear programming calculator, and get the same answer. But its structure is so special that it deserves and rewards its own method, which is why it has one.
The constraint matrix has a particular network form in which every variable appears in exactly two constraints, one supply and one demand, and that form is what the transportation simplex and MODI exploit to solve the problem with far less work than the general algorithm.
That structure also delivers a property general linear programs do not guarantee: integrality. Whenever the supplies and demands are whole numbers, the optimal shipment plan comes out in whole numbers automatically, with no need for the harder machinery of integer programming. This is not luck; it follows from a deep feature of the network structure, and it is why you can trust the calculator’s allocations to be shippable quantities rather than fractions that would have to be rounded.
The transportation problem is also the parent of two close relatives: the assignment problem, which is a transportation problem where every supply and demand is one, and the transshipment problem, which allows intermediate nodes that both receive and send.
Recognizing the transportation problem as a specially structured linear program is what connects it to the wider optimization toolkit while explaining why it gets a dedicated solver, and its shadow-price-like potentials are the same dual information the general linear program would produce.
Common mistakes in transportation models
A handful of errors recur and produce wrong or confusing results. Watch for these.
- Forgetting to balance. Solving without equal totals is meaningless. The calculator balances automatically, but if you balance by hand, add the dummy on the correct side.
- Ignoring the dummy’s shipments. The units on a dummy row or column are real information, your surplus or shortfall, not just filler to be discarded.
- Misaligned matrix. Each cost row must list one cost per destination in the same order, and supplies and demands must match rows and columns. A shifted entry solves a different problem silently.
- Stopping at the initial plan. A northwest-corner or least-cost starting plan is feasible but usually not optimal. It must be improved to optimality, which this tool does; a plan alone is not the answer.
- Confusing cost with quantity. The matrix holds per-unit costs, while the result holds units shipped. Entering quantities where costs belong inverts the whole problem.
- Assuming a unique solution. Some problems have several optimal plans with the same total cost. A different but equally optimal allocation is not an error.
- Reading a fractional shipment as valid. With whole-number supplies and demands the optimum is whole-number; a fraction signals a typo in the input, not a real plan.
Where this model fits in the toolkit
The transportation problem sits in the optimization cluster of operations research, and the Operations Research hub groups it with the models that share its DNA.
It is a specially structured linear program, so when your problem is genuinely about shipping from sources to destinations at least cost, this dedicated tool solves it more directly than the general simplex while giving the same optimum; when your problem has a different structure, the general linear programming calculator is the right choice.
The assignment problem, matching agents to tasks one-to-one, is the transportation problem’s special case where every supply and demand equals one, and it gets its own calculator because an even faster method fits that case.
Beyond the optimization cluster, the transportation model connects to the supply-chain tools through the decisions it informs and consumes. The supplies you enter often come from capacity or inventory positions computed elsewhere, and the demands from forecasts; the optimal routing it produces feeds the distribution and logistics decisions that the supply-chain silo addresses.
Where the transportation problem finds the cheapest static shipment plan, queuing theory and the stochastic models handle the timing and variability of flows through the network, and the cost structure it optimizes is exactly the kind of figure that feeds back into network-design and facility-location decisions. Seen this way, it is the quantitative core of least-cost distribution, one link in the chain from forecast to capacity to routing.
Return to the Operations Research hub for the full set of models.
The origin of the model
The transportation problem has a distinguished lineage that mirrors the birth of optimization itself. It was first formulated by Frank Hitchcock in 1941, which is why it is sometimes called the Hitchcock problem, and closely related work was done independently by the Soviet mathematician Leonid Kantorovich, whose study of optimal resource allocation, including transportation of goods, was part of the body of work for which he shared the 1975 Nobel Prize in economics. Tjalling Koopmans, who shared that prize, also worked on the transportation of cargo during the Second World War, and the problem’s wartime relevance to moving materiel efficiently helped drive early interest in it.
The dedicated solution methods came soon after the general theory of linear programming. Once George Dantzig developed the simplex method in the late 1940s, its specialization to the network structure of the transportation problem followed quickly, and the MODI and stepping-stone methods became standard teaching tools because they make the logic of optimization visible on a simple grid.
The problem endures in curricula and practice for the same reasons it did at the start: it captures a universal logistics question in a form simple enough to solve by hand yet rich enough to teach the core ideas of feasibility, optimality, and duality.
That combination, a real problem, a clean structure, and a transparent method, is why the transportation problem remains a first stop in operations research decades after Hitchcock first wrote it down, and why a calculator that solves it to optimality is a genuinely useful planning tool rather than only an academic exercise.
The three ways to build a starting plan
Every method for the transportation problem begins by constructing an initial feasible plan, one that satisfies all the supplies and demands without yet worrying about cost, and three classic methods do this with increasing sophistication. The northwest-corner method is the simplest: start at the top-left cell, ship as much as its supply and demand allow, move right or down as each is exhausted, and continue to the bottom-right. It ignores cost entirely, so it is the fastest to apply by hand but usually produces the most expensive starting plan, leaving the most work for the optimization stage.
The least-cost method, which this calculator uses, looks at cost while building the plan: it repeatedly finds the cheapest cell that still has both supply and demand available, ships the most it can there, and crosses off whatever is exhausted. Because it fills cheap routes first, it typically starts far closer to the optimum than northwest-corner.
Vogel’s approximation method (VAM) goes further still, and is often the best of the three: for each row and column it computes a penalty, the difference between the two lowest costs, which measures how much extra you pay if you miss the cheapest route, then allocates to the cheapest cell in whichever row or column has the largest penalty.
VAM frequently lands on the optimal plan straight away or within an iteration of it.
The important point is that the choice of starting method does not change the final answer. All three produce a feasible plan, and the MODI optimization stage drives any feasible plan to the same optimal cost; the methods differ only in how many optimization steps remain. This calculator optimizes to true optimality regardless of the start, so you get the guaranteed minimum-cost plan whether or not the initial least-cost plan happened to be optimal. Knowing the three methods still matters for coursework, where you are often asked to apply a specific one, and for intuition about why a good start saves work.
The penalty idea behind Vogel’s method is worth carrying even when a computer does the arithmetic, because it captures a genuine planning instinct: the routes to watch are not simply the cheap ones but the ones where being forced onto the second-best option costs the most. A row whose two cheapest costs are 2 and 3 can tolerate missing its best route, while a row whose two cheapest are 2 and 15 cannot, and allocating to the high-penalty row first avoids being trapped into that expensive fallback later. That is why Vogel’s plans start so close to optimal, and why an experienced planner eyeballing a cost matrix instinctively protects the routes with the steepest penalty for substitution.
Setting up a real distribution problem
Translating a real logistics situation into a transportation model is mostly a matter of deciding what the sources, destinations, and costs really are, and doing it consistently.
The sources are wherever the commodity originates and has a fixed available quantity, plants, warehouses, ports, or suppliers, and each one’s supply is how much it can send over the planning period.
The destinations are wherever it is consumed and has a required quantity, stores, regions, customers, or downstream plants, and each one’s demand is how much it needs over the same period. Keeping the period consistent, a week, a month, a season, matters, because supply, demand, and cost must all refer to the same horizon or the plan is meaningless.
The cost entries are the subtlest part, because they must be per unit and must be comparable across every route. The natural choice is the shipping cost to move one unit from a given source to a given destination, but it can be any linear per-unit cost you want to minimize, total landed cost, distance, transit time, or carbon, as long as you use the same measure throughout and it genuinely scales with the number of units.
If a route is impossible, a source that cannot serve a destination at all, give it a very large cost so the optimizer avoids it rather than leaving it blank.
The model assumes cost is strictly proportional to quantity with no fixed charges, no volume discounts, and no capacity limits on individual routes; when those features are present the plain transportation model is an approximation, and the honest response is either to accept it as a first-pass estimate or to move to a richer network model.
Finally, aggregate sensibly. A national distribution network might have hundreds of stores, but grouping them into regions with combined demand keeps the model small enough to reason about while still capturing the routing decision that matters. The art of applying the model well is choosing a level of aggregation that is fine enough to be useful and coarse enough to be tractable, and then checking that the resulting plan makes physical sense before acting on it. A model is a simplification, and the value of solving it lies as much in the structure it forces you to make explicit, who can supply whom, and at what cost, as in the specific numbers it returns.
When the model needs more than this
The plain transportation problem is deliberately narrow, and knowing its boundaries is part of using it well.
It assumes a single homogeneous commodity, one product that is interchangeable across all sources and destinations; when several distinct products share a network and compete for the same capacity, that is a multi-commodity flow problem, which needs a more general network model.
It assumes goods move directly from a source to a destination; when shipments can pass through intermediate hubs that both receive and forward, the transshipment problem extends the model by treating those hubs as nodes that are both destinations and sources, and it too can be reduced to a transportation-like linear program but with more structure.
The model also assumes unlimited capacity on each individual route and purely linear costs. When a particular lane can carry only so much, a capacitated transportation problem adds an upper bound to each route; when costs include fixed charges for using a route at all, or break at volume thresholds, the problem becomes a fixed-charge or piecewise problem that needs integer or mixed-integer methods.
None of these is a reason to distrust the plain model for the many situations that fit it, but they mark the point where you should reach for a more capable tool.
This calculator solves the classic uncapacitated, single-commodity, linear-cost transportation problem to optimality, which covers the great majority of teaching problems and a large share of real least-cost distribution decisions; when your situation has capacities, hubs, or multiple products, treat its answer as a useful bound and baseline rather than the final plan.
Input format and quick reference
Enter the cost matrix with one source per line and a per-unit cost for each destination on that line, separated by spaces or commas, keeping destinations in the same order across lines. Enter supplies as one number per source in line order, and demands as one number per destination in column order. Totals need not match; the calculator balances automatically. The reference below explains each part of the result.
| Output | What it means |
|---|---|
| Minimum total cost | The lowest possible total shipping cost, over all feasible plans |
| Allocation matrix | Units to ship on each source-to-destination route (a dot means unused) |
| Supply / demand row | The totals framing the matrix; every source empties and every destination fills |
| Dummy source | Added when demand exceeds supply; its shipments are demand left unmet |
| Dummy destination | Added when supply exceeds demand; its shipments are supply left unshipped |
| Cost by source | How the total cost divides across the supply points |
Frequently asked questions
What is the transportation problem?
The transportation problem is a classic optimization model that finds the cheapest way to ship a commodity from several supply points to several demand points. Each source has a fixed amount available, each destination needs a fixed amount, and each route from a source to a destination has a known per-unit cost. The goal is to decide how much to ship on each route so that every supply is used, every demand is met, and the total shipping cost is as low as possible. It is one of the most widely taught models in operations research and the foundation of least-cost distribution planning.
How does this calculator find the optimal shipment plan?
It works in two stages, the standard method taught in operations research. First it builds an initial feasible plan with the least-cost method, filling the cheapest routes first until all supply and demand are used. Then it improves that plan to the true optimum with the MODI method (also called the u-v or modified-distribution method), which computes a potential for each row and column, checks whether any unused route would lower the cost, and if so shifts shipments around a closed loop to use it. It repeats until no route can improve the cost, which guarantees the optimal solution.
What is a balanced versus unbalanced problem?
A transportation problem is balanced when total supply exactly equals total demand; only then does a feasible plan that uses all supply and meets all demand exist. When they differ, the problem is unbalanced, and it must be balanced before solving by adding a dummy source or destination. If demand exceeds supply, a dummy source supplies the shortfall at zero cost, and its shipments represent demand that goes unmet. If supply exceeds demand, a dummy destination absorbs the surplus at zero cost, and its shipments represent supply left unshipped. This calculator balances automatically and tells you which dummy it added.
What is a dummy source or destination?
A dummy is an artificial source or destination added to balance an unbalanced problem, with a supply or demand equal to the mismatch and a shipping cost of zero on every route. Because shipping to or from the dummy costs nothing, it does not affect the real cost; it simply absorbs the surplus or covers the shortfall so the solution method can run. After solving, the units assigned to a dummy destination are the supply that is not shipped anywhere, and the units from a dummy source are the demand that is not satisfied, which is often useful information in itself.
What is the least-cost method?
The least-cost method is a way to build a good starting plan: repeatedly find the route with the lowest unit cost that still has supply and demand available, ship as much as possible on it, and cross off whichever source or destination is exhausted. It tends to produce a cheaper starting point than the simpler northwest-corner method, which ignores cost, so the optimization stage has less work to do. This calculator uses the least-cost method for the initial plan and then optimizes it, so the method you start with does not change the final answer, only the number of steps to reach it.
What is the MODI method?
The MODI method, short for modified distribution and also called the u-v method, is the procedure that takes a feasible plan and checks whether it is optimal, improving it if not. It assigns a potential value to each source and each destination so that for every used route the two potentials add up to its cost, then for each unused route it computes whether adding it would lower the total cost. If any would, it identifies a closed loop of routes and shifts shipments around it to bring the improving route into use, and repeats. When no unused route can lower the cost, the plan is optimal. It is more systematic than the older stepping-stone method but reaches the same optimum.
Can it handle more than three sources or destinations?
Yes. The method works for any number of sources and destinations; you simply add more rows to the cost matrix and more numbers to the supply and demand lists. Practical hand solutions stay small because the arithmetic grows, but the calculator handles larger matrices without trouble. Keep the dimensions consistent: the number of cost rows must equal the number of supplies, and every row must have as many costs as there are demands, or the calculator will flag the input as invalid.
Is the transportation problem the same as linear programming?
It is a special, highly structured case of linear programming. Any transportation problem can be written as a linear program, minimizing total cost subject to supply and demand constraints, and solved with the simplex method. But because its structure is so specific, dedicated algorithms like the transportation simplex and MODI solve it far faster than the general simplex, and a useful bonus of that structure is that when all supplies and demands are whole numbers, the optimal shipments are automatically whole numbers too, with no need for integer programming.
What is degeneracy in the transportation problem?
A transportation solution is degenerate when it uses fewer routes than the number needed for the method to compute the row and column potentials, which is one less than the number of sources plus destinations. It happens when a shipment exhausts a source and a destination at the same time. The MODI method needs that full count of routes to work, so when a plan is degenerate the procedure adds a zero-shipment route to make up the number without changing the cost. This calculator handles degeneracy automatically, so you never have to manage it by hand.
Does the starting method change the final answer?
No. Northwest-corner, least-cost, and Vogel\u2019s approximation are all ways to build an initial feasible plan, and they usually give different starting plans, but the optimization stage drives every one of them to the same optimal cost. The only difference is how much work the optimization has to do: a better starting plan, such as one from Vogel\u2019s method, is often already optimal or close, while a northwest-corner start may take more iterations. Because this calculator optimizes to true optimality regardless, the final shipment plan and cost do not depend on the starting method.
Do these calculators store the numbers I enter?
No. This calculator runs entirely in your browser. The cost matrix, supplies, and demands you enter are never sent to our servers, stored, or shared. You can download a PDF or CSV of your solution locally, and nothing leaves your device. See our Privacy Policy for details.
Is the transportation problem calculator free?
Yes. The transportation problem calculator is completely free, with no account, sign-up, or paywall, and no limit on how often you run it. It returns the optimal shipment allocation, the minimum total cost, the number of routes used, and automatic balancing of unbalanced problems, with a cost-by-source chart and PDF and CSV export at no cost.
Related operations research calculators
More tools in this silo. Return to the Operations Research hub for the full set.
Sources, disclaimer, and editorial transparency
This calculator solves the transportation problem with a least-cost initial solution and the MODI (u-v) optimization method, the standard operations research technique (Hitchcock formulation; transportation simplex). This calculator and guide are built and reviewed by the OpsCalculators team; see our Editorial Policy for how each tool is researched, built, and tested.
Results are accurate estimates for planning and education, not certified engineering advice, and assume a single homogeneous commodity with linear, route-independent costs; transshipment and multi-commodity problems need a richer model. Validate against your own data before committing shipments. See our full Disclaimer. OpsCalculators.com is operated by MAFHH INTERNATIONAL LTD. Your inputs are processed in your browser and are never stored; see our Privacy Policy.