0% found this document useful (0 votes)
145 views

Container Loading Problem

The document describes the container loading problem where the goal is to load a ship with containers of varying weights while not exceeding the ship's cargo capacity. It presents the problem mathematically as maximizing the number of containers loaded subject to the total weight constraint. It proposes a greedy algorithm that loads containers in order of increasing weight and proves its optimality using induction.

Uploaded by

f20210467
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
145 views

Container Loading Problem

The document describes the container loading problem where the goal is to load a ship with containers of varying weights while not exceeding the ship's cargo capacity. It presents the problem mathematically as maximizing the number of containers loaded subject to the total weight constraint. It proposes a greedy algorithm that loads containers in order of increasing weight and proves its optimality using induction.

Uploaded by

f20210467
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Container Loading Problem

Problem
• A large ship is to be loaded with cargo.
• Cargo is containerized (same size)
• Different containers have different weights.
• The ship can handle cargo load of fixed
capacity.
• Load the ship with maximum number of
containers.
• Model it mathematically.
Mathematical model
• Let wi be the weight of the ith container, where 1 ≤ i
≤ n.
• Let c be the cargo capacity of the ship.
• Let xi be an indicator variable with value 1 or 0 such
that if ith container is loaded then x i is 1 else 0.
• Thus we wish to assign values to x i that satisfy the
constraints ∑ wi xi ≤ c.
• The objective function is : Maximize ∑ x i
Algorithm
• Load the ship one container after another.

• Greedy approach :
– From the remaining containers, select the one
with least weight.
Example
• Suppose that n = 8, [w1, w2, …, w8] = [100, 200, 50, 90, 150,
50, 20, 80], and c = 400.

• The order in which containers will be loaded


• Container should be loaded in order 7, 3, 6, 8, 4, 1, 5, 2 .
• Greedy strategy says to load 7, 3, 6, 8, 4, 1 and stop.
• Weight loaded is 390. Loading container 5 will exceed
capacity 400.
• Thus solution vector is x = [1, 0, 1, 1, 0, 1, 1, 1] and
∑ xi =6
Pseudocode
Algorithm ContainerLoading (c , capacity,numberOfContainers,
x){
Sort (c, numberOfContainers);
n:= numberOfContainers;
//initialize x
For i:= 1 to n do
x[i] := 0.
//select containers in order
i := 1;
while (i ≤ n && c[i].weight ≤ capacity)
{
//enough capacity for container c[i].id
x[c[i].id]:= 1;
capacity = capacity – c[i].weight;
i++;
}
The main result
• Theorem: The greedy algorithm generates
optimal loadings.
• Proof : Let x =[x1, …, xn] solution produced by
greedy algorithm.
• Let y = [y1, …, yn] be any feasible solution.

• Claim : ∑ xi ≥ ∑ yi
• WLOG containers are ordered so that wi ≤ wi+1,
1 ≤ i ≤ n.

• As the greedy algorithm works, there exists a k


, 0 ≤ k ≤ n, such that xi =1 for i ≤ k and xi =0 for
i > k.
• Use induction on the number p of positions such
that xi ≠ yi .
• Base case: If p = 0, x and y are the same and
hence ∑ xi ≥ ∑ yi is satisifed.
• Induction Hypothesis: Let m be any arbitrary
natural number and assume that ∑ xi ≥ ∑ yi
whenever p ≤m.
• Induction step: We need to show ∑ xi ≥ ∑ yi
when p = m+1.
Induction Step
• Find the least integer j, 1 ≤ j ≤ n such that xj ≠ yj.
• Since p ≠ 0, such a j exists.
• Also j ≤ k as otherwise y is not a feasible solution. (why?)

• Thus xj = 1, yj = 0.
• Set yj = 1. If y remains a feasible solution then call it z.
• If resulting y is infeasible solution there must be an l in
the range [k+1, n] for which yl = 1. Set yl = 0. Let z
denote the resulting y. As wj ≤ wl, z is a feasible loading.
• In either case ∑zi ≥ ∑yi and z differs from x in
at most p-1 = m positions.

• From the induction hypothesis, it follows that


∑ x i ≥ ∑ zi .

• Hence combining we get ∑ xi ≥ ∑ zi ≥ ∑yi .


• Hence proved.

You might also like