Spring 2015 Mathematics in Management Science Bin Packing The Problem The Algorithms.

Post on 30-Dec-2015

212 views 0 download

Transcript of Spring 2015 Mathematics in Management Science Bin Packing The Problem The Algorithms.

Spring 2015Mathematics in

Management Science

Bin Packing

The Problem

The Algorithms

Different Scheduling Problem

Have collection of idpt tasks (all task times ≤ 10). Instead of asking how long to finish job with 3 processors, instead ask,

“What is fewest number of processors need to finish job in under 20 min?”

A very different question!

Example of a bin-packing problem.

The Bin Packing Problem

Assume have:identical “bins” fixed capacity, andobjects (“weights”) of various sizes

that must be packed in bins.

How can we do this most efficiently (i.e., with fewest bins)?

Example

A company buys bulk wire in 100 ft spools. They use the wire in a variety of lengths in their product. How should they cut the wire so as to use the fewest spools?

Example

A wall unit requires boards of lengths:

6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4

Stock boards come in 9ft lengths.

How should we cut the boards so as to minimize the cost of material?

Variants

Two possibilities:

1. Only know next weight to pack.

(Think assembly line.)

2. Have full knowledge of all needed sizes/weights.

(E.g., a work order that lists everything that is needed.)

Variants

Two possibilities:

1. Only know next wt to pack.

2. Full knowledge all weights.

In (2), it makes sense to first sort the weights in a decreasing list. (Why?)

Leads to two variants of every bin-packing algorithm.

Variants

Two variants of every bin-packing algorithm.

The Bin Packing Problem

Pack wts w1, w2, …,wn into bins.Each bin has fixed capacity. Use as few bins as possible.

A scheduling problem in disguise! unlimited # of procs each with fixed

capacity (Goal: minimize # procs)

Dictionary

Schedulingtask

task time

processor

completion time

completing a task

# of processors

Bin Packingitem to pack

weight of item

bin

bin size

packing an item

# of bins

The Algorithms

Heuristic Algorithms• NF – Next Fit• FF – First Fit• WF – Worst Fit

In last 2, bins stay open until they are completely full.

Decreasing Versions• NFD – Next Fit D• FFD – First Fit D• WFD – Worst Fit D

With these first sort wts into decreasing order, then pack.

Next Fit Packing Algortihm

Only one bin open at a time!

Pack item in current bin.

If item will not fit in current bin:

close this bin & open a new bin.

Continue until all items packed.

Example using Next Fit Packing

Wts 6, 6, 5, 5, 5, 4, 4, 4, 4, 2, 2, 2, 2, 3, 3, 7, 7, 5, 5, 8, 8, 4, 4, 5

Next Fit Packing Algortihm

Advantages – Do not need to know all the weights in advance; only need to know the remaining space in the bin.Disadvantages – The bin packed early on may have had room for small items that come later in the list.

Best method for assembly-line packing.

First Fit & Worst Fit Packing

Keep all bins open until full. Then close.

To pack an item, look at open bins.

FF Place item in first bin in which it fits.

WF Place item in bin with the most space (and into which item fits) .

Only open new bin if item will not fit in any of the already open bins.

16

Bin Packing Methods

Next Fit & First Fit & Worst FitNF A new bin is opened if the weight to be packed next will not fit in the bin that is currently being filled; the current bin is then closed.FF The next weight to be packed is placed in the lowest-numbered bin already opened into which it will fit. If it does not fit in any open bins, a new bin is opened. WF The next weight to be packed is placed into the open bin with the largest amount of room remaining. If it does not fit in any bins, open a new bin.

17

Bin Packing Methods

Next Fit Decreasing (NFD)First Fit Decreasing(FFD)Worse Fit Decreasing(WFD)Decreasing-Time Heuristics NFD, FFD, WFD – Create the priority list by listing the weights in order of decreasing size before applying selected bin-packing method.

Example: Next FitA wall unit requires boards of lengths:6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4

Stock boards come in 9' lengths(!). How should you cut the boards so as to minimize the cost of material?

Use (1) NF and (2) NFD.

Next Fit:

6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4

8

4 65

4

5 2

2

3

7

5 5

8

4

4

3 1 3 1 14 40 2

2

Example: Next FitA wall unit requires boards of lengths:6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4

Stock boards come in 9' lengths(!). How should you cut the boards so as to minimize the cost of material?

Use (1) NF and (2) NFD.

Next Fit Decreasing:

8, 7, 6, 5, 5, 5, 5, 4, 4, 4, 3, 2, 2, 2

8

4 8 76 5 5 5 5 4

44

3

2

2

2

1 102 3 4 4 4 0

Example

8

4 65

7

4

65

3

4

2

8

4 7 2

Pack the following weights: 6, 5, 7, 3, 4, 2 in bins of size 10 using

(1) NF and (2) NFD.

Next Fit: NFD: 7, 6, 5, 4, 3, 2 3

Example: First FitA wall unit requires boards of lengths:

6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4

Stock boards come in 9' lengths(!). How should you cut the boards so as to minimize the cost of material?

Use (1) FF and (2) FFD.

First Fit:

6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4

8

4 8

7

5 55

44 43 2

2

2

65

10 00 0 0 0

Example: First FitA wall unit requires boards of lengths:

6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4

Stock boards come in 91 lengths(!). How should you cut the boards so as to minimize the cost of material?

Use (1) FF and (2) FFD.

First Fit Decreasing:

8, 7, 6, 5, 5, 5, 5, 4, 4, 4, 3, 2, 2, 2

8

4 8

1

76 5 5 5 5

4 4 432 2

2

0 0 0 0 0 0

Example

4

Pack the following weights: 6, 5, 7, 3, 4, 2 in bins of size 10 using

(1) FF and (2) FFD.

First Fit: FFD: 7, 6, 5, 4, 3, 2 1 1 1 0 0 3

8 8

4

3 4 2

76

5

3 4

7 26

5

Example: Worst FitA wall unit requires boards of lengths:6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4

Stock boards come in 9' lengths(!). How should you cut the boards so as to minimize the cost of material?

Use (1) WF and (2) WFD.

Worst Fit:

6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4

8

46 5

4

0

4

2

1

2

2

1

3

75

2

8

1

5 4

0

5

50

Example: Worst FitA wall unit requires boards of lengths:6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4

Stock boards come in 91 lengths(!). How should you cut the boards so as to minimize the cost of material?

Use (1) WF and (2) WFD.

Worst Fit Decreasing:

8, 7, 6, 5, 5, 5, 5, 4, 4, 4, 3, 2, 2, 2

8

4 8

1

76 5 5 5 5

4

0

4

0

4

0

32

2

2

7110

Example

4

Pack the following weights: 6, 5, 7, 3, 4, 2 in bins of size 10 using

(1) WF and (2) WFD.

Worst Fit: WFD: 7, 6, 5, 4, 3, 2 0 2 1 1 1 1

8 8

4

42

3

5

76

2 3 4

76

5

Exercise

Find a question of the form:

Use indicated bin-packing algorithm to place given weight in the supplied, already partially filled, bins.

Place wts in the bins and select the next wt to be added in such a way that each of the 3 algorithms (NF, FF, WF) will place the wt in a di erent bin.ff