Solving Cargo Loading Problem Using Integer Programming in Pytho
Solving Cargo Loading Problem Using Integer Programming in Pytho
Learn how to use Python PuLP to solve Cargo loading problems and Knapsack Problems using
Integer Programming.
Linear programming deals with non-integer solutions but in certain scenarios, we need integer
solutions such as the number of products to manufacture, number of apartments to construct,
number of trees to plan. In this approach, we optimize the linear function and set of linear
constraints on integer variables. Integer programming is widely utilized in the area of job
scheduling, inventory management, transportation, computer science, and production planning.
Contents [ hide ]
1 Types of Integer Programming
2 Knapsack Problem
3 Cargo Loading Problem
4 Understand the problem
5 Initialize LP Model
6 Define Decision Variable
7 Define Objective Function
8 Define the Constraints
9 Solve Model
10 Summary
1. Pure Integer Problems: In this type of problem, all the variables have integer
solution.
2. Mixed Integer Problems: In this type of problem, some of the variables have
integer and some of the variable have the continuous solution.
3. 0-1 Integer Problems: In this type of problem, all the varaibles requires value of 0
or 1.
Knapsack Problem
The knapsack problem is defined as how many units of each different kind of item or product to
put in a knapsack with a given capacity in order to maximize profit. It is also known as the fly-away
kit problem because a jet pilot decides the most valuable items to take abroad a jet. The knapsack
problem is a special case of integer programming where the objective function is maximized with a
single less than or equal to linear constraint. It has many applications in the real world.
Suppose there are n items 1,2,3 … n and the number of units of each item is mi. The weight per unit
of item i is wi, ri is the revenue per unit of item I, and W is the total capacity of cargo.
Objective Function:
Constraints:
Initialize LP Model
In this step, we will import all the classes and functions of pulp module and create a Maximization
LP problem using LpProblem class.
Python
Python
Python
1 # Define Objective
2 model += 12 * x1 + 25 * x2 + 38 * x3
1 # Define Constraints
2 model += x1 + 2*x2 + 3*x3 <= 10 # Cargo storage capacity 10 ton ; pump A is 1 ton, pump B is 2 to
Solve Model
In this step, we will solve the LP problem by calling solve() method. We can print the final value by
using the following for loop.
Python
Output:
A = 1.0
B = 0.0
C = 3.0
Value of Objective Function = 126.0
Summary
In this article, we have learned about Integer Programming, Knapsack Problems, Cargo Loading
Problems, Problem Formulation, and implementation in python using the PuLp library. We have
solved the cargo loading problem using an integer programming problem in Python. Of course, this
is just a simple case study, we can add more constraints to it and make it more complicated. In
upcoming articles, we will write more on different optimization problems and its solution using
Python. You can revise the basics of mathematical concepts in this article and learn about Linear
Programming in this article.
Solving Staff Scheduling Problem using Linear Programming
Latest Posts
MapReduce Algorithm
Networking and Professional Development for Machine Learning Careers in the USA
Airflow Operators
MLOps Tutorial
Python Decorators
Python Generators
About Us
We love Data Science and we are here to provide you Knowledge on Machine Learning, Text Analytics,
NLP, Statistics, Python, and Big Data. We focus on simple, elegant, and easy to learn tutorials.
Resources
AWS
Big Data
Business Analytics
Data Engineering
Deep Learning
Essentials Skills
Interview
Julia
Machine Learning
Mathematics
MLOps
NLP
Optimization Techniques
Python
pandas
Recommender System
Statistics
Text Analytics
Archives
April 2024
September 2023
July 2023
March 2023
February 2023
January 2023
November 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
December 2021
September 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
December 2020
November 2020
October 2020
September 2020
DataCamp
UpGrad
Edureka Data Science
Dataquest
Privacy Policy