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

Knapsack Problem: Truck - 10t Capacity

The document describes the knapsack problem of determining the optimal combination of items to fit within a knapsack of limited capacity. It presents a table method for calculating the maximum value function f(i,w) to find the optimal output for items 1 through i that have a cumulative weight of w or less. The completed table shows the optimal solution is to include 2 of item 1 and 1 of item 2 for a total value of $15.

Uploaded by

Rachel Avenger
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Knapsack Problem: Truck - 10t Capacity

The document describes the knapsack problem of determining the optimal combination of items to fit within a knapsack of limited capacity. It presents a table method for calculating the maximum value function f(i,w) to find the optimal output for items 1 through i that have a cumulative weight of w or less. The completed table shows the optimal solution is to include 2 of item 1 and 1 of item 2 for a total value of $15.

Uploaded by

Rachel Avenger
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

Knapsack Problem

Truck – 10t capacity

Optimum cargo combination:


•Item 1: $1 (2t)
•Item 2: $2 (3t)
•Item 3: $5 (4t)
•Item 4: $6 (5t)
Knapsack Problem
Output function f(i,w)

Optimum output of a combination of items 1
to i with a cumulated weight of w or less.

•Item 1: x1=$5 ; w1=3t


•Item 2: x2=$7 ; w2=4t
•Item 3: x3=$8 ; w3=5t
Knapsack Problem
Output function f(i,w)

f(i,w)=Max[ xi + f(i,w-wi) ; f(i-1,w) ]

ONE Item i + optimum NO Item i + optimum


combination of weight combination items 1 to
w-wi i-1
Knapsack Problem
Table
1 2 3 4 5 6 7 8 9 10 W
1
2
3

f(i,w)
i
Knapsack Problem
Table
1 2 3 4 5 6 7 8 9 10 W
1 Using only item 1
2
3

i
Knapsack Problem
Table
1 2 3 4 5 6 7 8 9 10 W
1
2 Using only item 1 & 2
3

i
Knapsack Problem
Table
1 2 3 4 5 6 7 8 9 10 W
1
2
3 Using items 1, 2 & 3

i
Knapsack Problem
Table
1 2 3 4 5 6 7 8 9 10 W
1 0 0 5 5 5 10
2
3

0 items n°1 1 items n°1 2 items n°1


w1 = 3 2 w1 = 6
Knapsack Problem
Table
1 2 3 4 5 6 7 8 9 10 w – w2 =
5–4=1
1 0 0 5 5 5 10 10 10 15 15
2 0 0 5 7
3
+ x2 (= 7)

f(i,w)=Max[ xi + f(i,w-wi) ; f(i-1,w) ]


Knapsack Problem
Table
1 2 3 4 5 6 7 8 9 10
1 0 0 5 5 5 10 10 10 15 15
2 0 0 5 7 7
3
+ x2 (= 7)

f(i,w)=Max[ xi + f(i,w-wi) ; f(i-1,w) ]


Knapsack Problem
Table
1 2 3 4 5 6 7 8 9 10 w – w2 =
6–4=2
1 0 0 5 5 5 10 10 10 15 15
2 0 0 5 7 7
3
+ x2 (= 7)

f(i,w)=Max[ xi + f(i,w-wi) ; f(i-1,w) ]


Knapsack Problem
Table
1 2 3 4 5 6 7 8 9 10
1 0 0 5 5 5 10 10 10 15 15
2 0 0 5 7 7 10
3
+ x2 (= 7)

f(i,w)=Max[ xi + f(i,w-wi) ; f(i-1,w) ]


Knapsack Problem

COMPLETED TABLE
1 2 3 4 5 6 7 8 9 10

1 0 0 5 5 5 10 10 10 15 15

2 0 0 5 7 7 10 12 14 15 17

3 0 0 5 7 8 10 12 14 15 17
Knapsack Problem
Path
1 2 3 4 5 6 7 8 9 10

1 0 0 5 5 5 10 10 10 15 15

2 0 0 5 7 7 10 12 14 15 17

3 0 0 5 7 8 10 12 14 15 17

Item 1 Item 1 Item 2

Optimal: 2 x Item 1 + 1 x Item 2

You might also like