SlideShare a Scribd company logo
1 of 22
Bin-Packing / Knapsacks
Problem
(Combinatorial Optimization Project)
How we use the Knapsacks for
Bin-packing?
Intro of Bin-Packing
Bin packing is the problem of trying to find a set of objects to pack into
containers (or bins). The objects have weights (or volumes), and each
container has a capacity, which is the total weight (or volume) the container
can hold.
One of the most common bin packing problems is knapsacks.
Knapsacks
Goal is to maximize the total
value of items in (typically) a
single bin.
A simple example
Here's a graphical
depiction of a knapsack
problem:
Knapsack Problem Example
Truck – 10t capacity
Optimum cargo combination:
•Item 1: $5 (3t)
•Item 2: $7 (4t)
•Item 3: $8 (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
combination of weight w-wi
NO Item i + optimum
combination items 1 to i-
1
Knapsack Problem
Table
1 2 3 4 5 6 7 8 9 10
1
2
3
w
i f(i,w)
Knapsack Problem
Table
1 2 3 4 5 6 7 8 9 10
1
2
3
w
i
Using only item 1
Knapsack Problem
Table
1 2 3 4 5 6 7 8 9 10
1
2
3
w
i
Using only item 1 & 2
Knapsack Problem
Table
1 2 3 4 5 6 7 8 9 10
1
2
3
w
i
Using items 1, 2 & 3
Knapsack Problem
Table
1 2 3 4 5 6 7 8 9 10
1 0 0 5 5 5 10
2
3
w
2 items n°1
2 w1 = 6
0 items n°1 1 items n°1
w1 = 3
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
3
w-w2 =
5 - 4 = 1
f(i,w)=Max[ xi + f(i,w-wi) ; f(i-1,w) ]
+ x2(=7)
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
f(i,w)=Max[ xi + f(i,w-wi) ; f(i-1,w) ]
+ x2(=7)
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
w-w2 =
6 - 4 = 2
f(i,w)=Max[ xi + f(i,w-wi) ; f(i-1,w) ]
+ x2(=7)
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
f(i,w)=Max[ xi + f(i,w-wi) ; f(i-1,w) ]
+ x2(=7)
Knapsack Problem
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
Completed Table
Optimal: 2 x Item 1 + 1 x Item 2
Item 1 Item 2 Item 3
Python code for Knapsack problem
from ortools.algorithms import pywrapknapsack_solver
def main():
# Create the solver.
solver = pywrapknapsack_solver.KnapsackSolver(
pywrapknapsack_solver.KnapsackSolver.
KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER,
'test')
values = [360, 83, 59, 130, 431, 67, 230, 52, 93,
125, 670, 892, 600, 38, 48, 147, 78, 256,
63, 17, 120, 164, 432, 35, 92, 110, 22,
42, 50, 323, 514, 28, 87, 73, 78, 15,
26, 78, 210, 36, 85, 189, 274, 43, 33,
10, 19, 389, 276, 312]
weights = [[7, 0, 30, 22, 80, 94, 11, 81, 70,
64, 59, 18, 0, 36, 3, 8, 15, 42,
9, 0, 42, 47, 52, 32, 26, 48, 55,
6, 29, 84, 2, 4, 18, 56, 7, 29,
93, 44, 71, 3, 86, 66, 31, 65, 0,
79, 20, 65, 52, 13]]
capacities = [850]
solver.Init(values, weights, capacities)
computed_value = solver.Solve()
packed_items = [x for x in range(0, len(weights[0]))
if solver.BestSolutionContains(x)]
packed_weights = [weights[0][i] for i in packed_items]
total_weight= sum(packed_weights)
Print the output
or result.
print("Packed items: ", packed_items)
print("Packed weights: ", packed_weights)
print("Total value: ", computed_value)
print("Total weight: ", total_weight)
if __name__ == '__main__':
main()
Packed items: [0, 1, 3, 4, 6, 10, 11, 12, 14, 15,
16, 17, 18, 19, 21, 22, 24, 27, 28, 29, 30, 31,
32, 34, 38, 39, 41, 42, 44, 47, 48, 49]
Packed weights: [7, 0, 22, 80, 11, 59, 18, 0, 3,
8, 15, 42, 9, 0, 47, 52, 26, 6, 29, 84, 2, 4, 18, 7,
71, 3, 66, 31, 0, 65, 52, 13]
Total value: 7534
Total weight: 850
Output of the python
code
“Operational research (in British usage), is a
discipline that deals with the application of advanced
analytical methods to help make better decisions.”
Thanks!
GAURAV DUBEY(2017msbda003)
MSc. CS(BIG DATA ANALYTICS)
Central University of
Rajasthan
Bandarsindri, Kishangarh, Ajmer,
pin : 305817.
2017msbda003@curaj.ac.in

More Related Content

What's hot

Knapsack Problem (DP & GREEDY)
Knapsack Problem (DP & GREEDY)Knapsack Problem (DP & GREEDY)
Knapsack Problem (DP & GREEDY)Ridhima Chowdhury
 
Knapsack problem dynamicprogramming
Knapsack problem dynamicprogrammingKnapsack problem dynamicprogramming
Knapsack problem dynamicprogrammingrowntu
 
Greedy algo revision 2
Greedy algo revision 2Greedy algo revision 2
Greedy algo revision 2maamir farooq
 
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups mathsjournal
 
01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic ProgrammingFenil Shah
 
Knapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithmKnapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithmHoneyChintal
 
0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsackAmin Omi
 
Efficient Algorithm for Constructing KU-algebras from Block Codes
Efficient Algorithm for Constructing KU-algebras from Block CodesEfficient Algorithm for Constructing KU-algebras from Block Codes
Efficient Algorithm for Constructing KU-algebras from Block Codesinventionjournals
 
0 1 knapsack using naive recursive approach and top-down dynamic programming ...
0 1 knapsack using naive recursive approach and top-down dynamic programming ...0 1 knapsack using naive recursive approach and top-down dynamic programming ...
0 1 knapsack using naive recursive approach and top-down dynamic programming ...Abhishek Singh
 
Simultaneous Triple Series Equations Involving Konhauser Biorthogonal Polynom...
Simultaneous Triple Series Equations Involving Konhauser Biorthogonal Polynom...Simultaneous Triple Series Equations Involving Konhauser Biorthogonal Polynom...
Simultaneous Triple Series Equations Involving Konhauser Biorthogonal Polynom...IOSR Journals
 
A note on the density of Gumbel-softmax
A note on the density of Gumbel-softmaxA note on the density of Gumbel-softmax
A note on the density of Gumbel-softmaxTomonari Masada
 
On Fuzzy Soft Multi Set and Its Application in Information Systems
On Fuzzy Soft Multi Set and Its Application in Information Systems On Fuzzy Soft Multi Set and Its Application in Information Systems
On Fuzzy Soft Multi Set and Its Application in Information Systems ijcax
 
A Survey- Knapsack Problem Using Dynamic Programming
A Survey- Knapsack Problem Using Dynamic ProgrammingA Survey- Knapsack Problem Using Dynamic Programming
A Survey- Knapsack Problem Using Dynamic ProgrammingEditor IJCTER
 
Student manual
Student manualStudent manual
Student manualec931657
 

What's hot (20)

Knapsack Problem (DP & GREEDY)
Knapsack Problem (DP & GREEDY)Knapsack Problem (DP & GREEDY)
Knapsack Problem (DP & GREEDY)
 
Knapsack problem dynamicprogramming
Knapsack problem dynamicprogrammingKnapsack problem dynamicprogramming
Knapsack problem dynamicprogramming
 
Knapsack
KnapsackKnapsack
Knapsack
 
Greedy algo revision 2
Greedy algo revision 2Greedy algo revision 2
Greedy algo revision 2
 
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
 
01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming
 
Knapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithmKnapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithm
 
0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsack
 
Efficient Algorithm for Constructing KU-algebras from Block Codes
Efficient Algorithm for Constructing KU-algebras from Block CodesEfficient Algorithm for Constructing KU-algebras from Block Codes
Efficient Algorithm for Constructing KU-algebras from Block Codes
 
0 1 knapsack using naive recursive approach and top-down dynamic programming ...
0 1 knapsack using naive recursive approach and top-down dynamic programming ...0 1 knapsack using naive recursive approach and top-down dynamic programming ...
0 1 knapsack using naive recursive approach and top-down dynamic programming ...
 
Simultaneous Triple Series Equations Involving Konhauser Biorthogonal Polynom...
Simultaneous Triple Series Equations Involving Konhauser Biorthogonal Polynom...Simultaneous Triple Series Equations Involving Konhauser Biorthogonal Polynom...
Simultaneous Triple Series Equations Involving Konhauser Biorthogonal Polynom...
 
A note on the density of Gumbel-softmax
A note on the density of Gumbel-softmaxA note on the density of Gumbel-softmax
A note on the density of Gumbel-softmax
 
QMC: Transition Workshop - How to Efficiently Implement Multivariate Decompos...
QMC: Transition Workshop - How to Efficiently Implement Multivariate Decompos...QMC: Transition Workshop - How to Efficiently Implement Multivariate Decompos...
QMC: Transition Workshop - How to Efficiently Implement Multivariate Decompos...
 
On Fuzzy Soft Multi Set and Its Application in Information Systems
On Fuzzy Soft Multi Set and Its Application in Information Systems On Fuzzy Soft Multi Set and Its Application in Information Systems
On Fuzzy Soft Multi Set and Its Application in Information Systems
 
A Survey- Knapsack Problem Using Dynamic Programming
A Survey- Knapsack Problem Using Dynamic ProgrammingA Survey- Knapsack Problem Using Dynamic Programming
A Survey- Knapsack Problem Using Dynamic Programming
 
Indefinite Integral 18
Indefinite Integral 18Indefinite Integral 18
Indefinite Integral 18
 
Backpropagation
BackpropagationBackpropagation
Backpropagation
 
Antiderivatives
AntiderivativesAntiderivatives
Antiderivatives
 
1.7
1.71.7
1.7
 
Student manual
Student manualStudent manual
Student manual
 

Similar to Presentation of knapsack

0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEMMrunal Patil
 
module3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdfmodule3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdfShiwani Gupta
 
DynProg_Knapsack.ppt
DynProg_Knapsack.pptDynProg_Knapsack.ppt
DynProg_Knapsack.pptRuchika Sinha
 
Dynamic programming (dp) in Algorithm
Dynamic programming (dp) in AlgorithmDynamic programming (dp) in Algorithm
Dynamic programming (dp) in AlgorithmRaihanIslamSonet
 
Dynamic Programming for 4th sem cse students
Dynamic Programming for 4th sem cse studentsDynamic Programming for 4th sem cse students
Dynamic Programming for 4th sem cse studentsDeepakGowda357858
 
13 - 06 Feb - Dynamic Programming
13 - 06 Feb - Dynamic Programming13 - 06 Feb - Dynamic Programming
13 - 06 Feb - Dynamic ProgrammingNeeldhara Misra
 
Matematicas para ingenieria 4ta edicion - john bird
Matematicas para ingenieria   4ta edicion - john birdMatematicas para ingenieria   4ta edicion - john bird
Matematicas para ingenieria 4ta edicion - john birdAllan Bernal Espinoza
 
Mathematical optimization and python
Mathematical optimization and pythonMathematical optimization and python
Mathematical optimization and pythonOpen-IT
 

Similar to Presentation of knapsack (20)

0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
 
module3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdfmodule3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdf
 
DynProg_Knapsack.ppt
DynProg_Knapsack.pptDynProg_Knapsack.ppt
DynProg_Knapsack.ppt
 
Dynamic programming (dp) in Algorithm
Dynamic programming (dp) in AlgorithmDynamic programming (dp) in Algorithm
Dynamic programming (dp) in Algorithm
 
Prolog resume
Prolog resumeProlog resume
Prolog resume
 
Prolog resume
Prolog resumeProlog resume
Prolog resume
 
Prolog resume
Prolog resumeProlog resume
Prolog resume
 
Prolog resume
Prolog resumeProlog resume
Prolog resume
 
Prolog resume
Prolog resumeProlog resume
Prolog resume
 
Prolog resume
Prolog resumeProlog resume
Prolog resume
 
Prolog resume
Prolog resumeProlog resume
Prolog resume
 
Dynamic Programming for 4th sem cse students
Dynamic Programming for 4th sem cse studentsDynamic Programming for 4th sem cse students
Dynamic Programming for 4th sem cse students
 
13 - 06 Feb - Dynamic Programming
13 - 06 Feb - Dynamic Programming13 - 06 Feb - Dynamic Programming
13 - 06 Feb - Dynamic Programming
 
Unit 3-Greedy Method
Unit 3-Greedy MethodUnit 3-Greedy Method
Unit 3-Greedy Method
 
AOA ppt.ppt
AOA ppt.pptAOA ppt.ppt
AOA ppt.ppt
 
0-1 knapsack problem
0-1 knapsack problem0-1 knapsack problem
0-1 knapsack problem
 
greedy algorithm Fractional Knapsack
greedy algorithmFractional Knapsack greedy algorithmFractional Knapsack
greedy algorithm Fractional Knapsack
 
Matematicas para ingenieria 4ta edicion - john bird
Matematicas para ingenieria   4ta edicion - john birdMatematicas para ingenieria   4ta edicion - john bird
Matematicas para ingenieria 4ta edicion - john bird
 
4R2012 preTest9A
4R2012 preTest9A4R2012 preTest9A
4R2012 preTest9A
 
Mathematical optimization and python
Mathematical optimization and pythonMathematical optimization and python
Mathematical optimization and python
 

More from Gaurav Dubey

More from Gaurav Dubey (6)

Microsoft exam (2)
Microsoft exam (2)Microsoft exam (2)
Microsoft exam (2)
 
Health care analytics
Health care analyticsHealth care analytics
Health care analytics
 
Banking case study
Banking case studyBanking case study
Banking case study
 
Healthcare
HealthcareHealthcare
Healthcare
 
Marketing analysis
Marketing analysisMarketing analysis
Marketing analysis
 
Value thinking. gaurav
Value thinking. gauravValue thinking. gaurav
Value thinking. gaurav
 

Recently uploaded

1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样vhwb25kk
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...Suhani Kapoor
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfgstagge
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxFurkanTasci3
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)jennyeacort
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptxthyngster
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...soniya singh
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...Pooja Nehwal
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一F sss
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceSapana Sha
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDRafezzaman
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Callshivangimorya083
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts ServiceSapana Sha
 
9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home ServiceSapana Sha
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130Suhani Kapoor
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 

Recently uploaded (20)

1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdf
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptx
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts Service
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts Service
 
9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 

Presentation of knapsack

  • 2. How we use the Knapsacks for Bin-packing?
  • 3. Intro of Bin-Packing Bin packing is the problem of trying to find a set of objects to pack into containers (or bins). The objects have weights (or volumes), and each container has a capacity, which is the total weight (or volume) the container can hold. One of the most common bin packing problems is knapsacks.
  • 4. Knapsacks Goal is to maximize the total value of items in (typically) a single bin. A simple example Here's a graphical depiction of a knapsack problem:
  • 5. Knapsack Problem Example Truck – 10t capacity Optimum cargo combination: •Item 1: $5 (3t) •Item 2: $7 (4t) •Item 3: $8 (5t)
  • 6. 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
  • 7. Knapsack Problem Output function f(i,w) f(i,w)=Max[ xi + f(i,w-wi) ; f(i-1,w) ] ONE Item i + optimum combination of weight w-wi NO Item i + optimum combination items 1 to i- 1
  • 8. Knapsack Problem Table 1 2 3 4 5 6 7 8 9 10 1 2 3 w i f(i,w)
  • 9. Knapsack Problem Table 1 2 3 4 5 6 7 8 9 10 1 2 3 w i Using only item 1
  • 10. Knapsack Problem Table 1 2 3 4 5 6 7 8 9 10 1 2 3 w i Using only item 1 & 2
  • 11. Knapsack Problem Table 1 2 3 4 5 6 7 8 9 10 1 2 3 w i Using items 1, 2 & 3
  • 12. Knapsack Problem Table 1 2 3 4 5 6 7 8 9 10 1 0 0 5 5 5 10 2 3 w 2 items n°1 2 w1 = 6 0 items n°1 1 items n°1 w1 = 3
  • 13. 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 3 w-w2 = 5 - 4 = 1 f(i,w)=Max[ xi + f(i,w-wi) ; f(i-1,w) ] + x2(=7)
  • 14. 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 f(i,w)=Max[ xi + f(i,w-wi) ; f(i-1,w) ] + x2(=7)
  • 15. 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 w-w2 = 6 - 4 = 2 f(i,w)=Max[ xi + f(i,w-wi) ; f(i-1,w) ] + x2(=7)
  • 16. 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 f(i,w)=Max[ xi + f(i,w-wi) ; f(i-1,w) ] + x2(=7)
  • 17. Knapsack Problem 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 Completed Table Optimal: 2 x Item 1 + 1 x Item 2 Item 1 Item 2 Item 3
  • 18. Python code for Knapsack problem from ortools.algorithms import pywrapknapsack_solver def main(): # Create the solver. solver = pywrapknapsack_solver.KnapsackSolver( pywrapknapsack_solver.KnapsackSolver. KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER, 'test') values = [360, 83, 59, 130, 431, 67, 230, 52, 93, 125, 670, 892, 600, 38, 48, 147, 78, 256, 63, 17, 120, 164, 432, 35, 92, 110, 22, 42, 50, 323, 514, 28, 87, 73, 78, 15, 26, 78, 210, 36, 85, 189, 274, 43, 33, 10, 19, 389, 276, 312]
  • 19. weights = [[7, 0, 30, 22, 80, 94, 11, 81, 70, 64, 59, 18, 0, 36, 3, 8, 15, 42, 9, 0, 42, 47, 52, 32, 26, 48, 55, 6, 29, 84, 2, 4, 18, 56, 7, 29, 93, 44, 71, 3, 86, 66, 31, 65, 0, 79, 20, 65, 52, 13]] capacities = [850] solver.Init(values, weights, capacities) computed_value = solver.Solve() packed_items = [x for x in range(0, len(weights[0])) if solver.BestSolutionContains(x)] packed_weights = [weights[0][i] for i in packed_items] total_weight= sum(packed_weights)
  • 20. Print the output or result. print("Packed items: ", packed_items) print("Packed weights: ", packed_weights) print("Total value: ", computed_value) print("Total weight: ", total_weight) if __name__ == '__main__': main() Packed items: [0, 1, 3, 4, 6, 10, 11, 12, 14, 15, 16, 17, 18, 19, 21, 22, 24, 27, 28, 29, 30, 31, 32, 34, 38, 39, 41, 42, 44, 47, 48, 49] Packed weights: [7, 0, 22, 80, 11, 59, 18, 0, 3, 8, 15, 42, 9, 0, 47, 52, 26, 6, 29, 84, 2, 4, 18, 7, 71, 3, 66, 31, 0, 65, 52, 13] Total value: 7534 Total weight: 850 Output of the python code
  • 21. “Operational research (in British usage), is a discipline that deals with the application of advanced analytical methods to help make better decisions.”
  • 22. Thanks! GAURAV DUBEY(2017msbda003) MSc. CS(BIG DATA ANALYTICS) Central University of Rajasthan Bandarsindri, Kishangarh, Ajmer, pin : 305817. 2017msbda003@curaj.ac.in