Skip to content

C++ code for various methods of solving transportation problem

Notifications You must be signed in to change notification settings

Chahat-M/Transportation-Problem-LPP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Transportation-Problem-LPP

Transportation Problem is a kind of Linear Programming Problem (LPP) in which goods are transported from a set of sources to a set of destination subject to the supply and demand of the sources and destination respectively such that the total cost of transportation is minimized.

There are two types of transportation problems:

  1. Balanced - When both supplies and demands are equal.
  2. Unbalanced - When both supplies and demands are unequal.

In this project only balanced problems are dealt as for now though the condition is still tested using test_equality() function.

Methods to solve:

To find the Initial Basic Feasible Solution (IBFS) there are three methods:

  1. NorthWest Corner Method (NWM)
  2. Least Cost Cell Method (LCCM)
  3. Vogel's Approximation Method (Vogels)

Usage

Clone the repository using the command:

git clone https://github.com/Chahat-M/Transportation-Problem-LPP.git

To compile the program and run, follow these steps:

  1. Compile the input.cpp file using the command below, which creates the object code file input.o
g++ -c -I./include src/input.cpp
  1. Then compile the file of the program you want to use which will generate the object code file filename.o.
g++ -c -I./include src/filename.cpp

For example, if you want to compile LCCM.cpp file, use LCCM instead of filename. This will create a LCCM.o object code file.

  1. To create an executable by linking both the object code file, follow the command:
g++ -o output input.o filename.o
  1. To run the program sucessfully, use the follwing command:
./output

An alternative approach:

Compile both the files together input.cpp and the program file you want to run using the command:

g++ -c -I./include src/input.cpp src/filename.cpp

This will auto-generate an object code file a.out which can then be executed.

./a.out

Project Structure:

|-- .vscode
  |-- launch.json
  |-- settings.json
  |-- tasks.json
|-- include
  |-- input.hpp
|-- src
  |-- NWM.cpp
  |-- LCCM.cpp
  |-- Vogels.cpp
  |-- input.cpp
|-- README.md
|-- a.out

Sample Example

The input for all the program files looks like:

Enter no. of sources and destination respectively: 3 4
Entries of the matrix:
3 1 7 4
2 6 5 9
8 3 3 2
Enter supply quantity for each source
300 400 500
Enter demand quantity for each destination
250 350 400 200

If LCCM.cpp file is executed, the output (as per the above input) will look like:

Optimum Cost 2850
IBFS matrix:
0 300 0 0 
250 0 150 0 
0 50 250 200

About

C++ code for various methods of solving transportation problem

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages