Transportation Problem: Balancing

This is part of the course “Optimization for Programmers”.

GitHub Repository with Source Code


Transportation Simplex Method works with a balanced transportation problem. Therefore we need to learn how to make problem balanced if it is not such. And it means to cover two cases — when supply is less than demand and otherwise.

Supply Less Than Demand

40 + 30 < 30 + 50

Here we can see that supply is less than demand. In such a case, we add a fake origin (d₃=10) so that supply became equal to demand. Values c₃₁, c₃₂ represent financial loss related to unmet demand.

c₃₁ = 3. It can mean that the first customer will lose 3$ with each not shipped unit.

Demand Less Than Supply

40 + 30 > 30 + 30

Here we can see that demand is less than supply. In such a case we add a fake destination (s₃ = 1) so that supply became equal to demand. for unused capacity there no cost involved therefor values c₁₃ and c₂₃ are equal to 0.


Let’s write a simple function that receives a transportation problem and returns its balanced version. When supply less than demand we also need to pass penalties(financial losses related to unmet demands).

Next part ->

Reach the next level of focus and productivity with





Indie hacker behind More at

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Install Confluent Kafka Python using docker -Beginners Guide

The Ultimate Guide to GCP’s Logging Query Language


These are just good articles and books

Web scraping multiple Amazon Product pages Dynamically Using Beautiful Soup

Meltano vs Airbyte

HTML Elements

How To Host A Website As A Front End Web Developer in 3 Simple Steps

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Radzion Chachura

Radzion Chachura

Indie hacker behind More at

More from Medium

Conda Virtual Environment(VENV) Management Basics for Machine Learning

What is Flowchart? How flowchart helps in your Coding Practices ? #Python Series-1

Alternative Fix for Incompatible Dunder Method Error in Mypy

Distributed Computing Made Easy with Dask