CSIS-385: Homework 4 (Big Project)

advertisement
CSIS-385: Homework 4 (Big Project)
This project can be completed in groups of size 3 or smaller. See schedule for due date. Deliverables will be
described in two weeks.
Overview: Implement 4 Algorithms: Implement Optimal Brute-Force algorithms for the Knapsack and Bin Packing
Problems. Implement Near-Optimal Greedy algorithms for the Knapsack and Bin Packing Problems
Knapsack Problem (not the continuous Knapsack
problem): The sack can hold 100 lbs. You are given N
items that each have a weight and a value. Your goal is
to fill the sack with the most valuable subset of items.
To solve this problem optimally requires considering all
possible subsets 2N.
the next best decision and (2) adjust or modify an
existing solution incrementally if the solution can be
improved. You should try several different variations,
but you must submit your best algorithm for each of the
two problems.
Algorithm Details
Bin Packing Problem: You can buy an infinite number
of suitcases (bins) that can each store 10 lbs worth of
stuff. You are given N items where each item has a
different weight. Your goal is to pack all N items using
the minimum number of suitcases (bins). To solve this
problem optimally requires consider all permutations N!
Optimal Brute-Force Algorithms: These algorithms
must consider all possibilities in order to find the
optimal solution.
For the Knapsack Problem, you have to generate all the
subsets of N items. Some of the subsets won’t fit into
the sack. For example, if items A and B each weigh 60
lbs. then you don’t have to consider any subset with both
A and B. Depending upon the weights of items, you can
find an optimal solution without considering all 2N
subsets. Your optimal algorithm should be as efficient as
possible.
For the Bin Packing Problem, you have to generate all
the permutations (orderings) of N items. One or more of
the permutations are optimal, which means that if we
pack items in this particular order then we will use the
minimum number of suitcases. Some of the items may
have the same weight, so you don’t have to consider all
permutations. For example, if items A and B each weigh
2 lbs., then there is no difference between considering
permutation {A, B} and {B, A}. In fact, each pair of
items with identical weights cuts the number of
permutations in half. Your optimal algorithm should be
as efficient as possible.
Near-Optimal Greedy Algorithms: Try to develop
clever algorithms for solving the two problems. Rather
than try all possibilities, these algorithms should take
some greedy steps, i.e., decisions that are optimal at the
time but may not lead to a final optimal solution. A
general strategy is to take N greedy steps to generate a
solution and then backtrack, i.e., make different
decisions to try to improve the solution. Backtracking
can take two forms: (1) undo a greedy decision and try
For the Knapsack Problem, your programs should input
a file where each line represents an item: Item Number,
Weight, and Value.
1 51 32
2 44 25
3 10 8
The example has three items. Item 2 has a
weight of 44 and a value of 25.
Your program should output a list of the items that were
placed in the sack, their total weight (which should be
close to 100 lbs.), and their total value.
For the Bin Packing Problem, your program should
input a file where each line represents an item: Item
Number, Weight
1 5.3
2 1.2
3 2.33
49
The example has four times. Item 3 has a
weight of 2.33.
1: {1,2,3} 8.83
2: {4} 9
Your program should output a
list of each bin, the items in each
bin, and weight of each bin
Input Generators: To test your program, you should
create random input generators for each problem.
For the Knapsack Problem, the generator should make
N/2 items with random weights and values between 0
and 50, and N/2 items with random weights and values
between 0 and 20.
For the Bin Packing Problem, the generator should
make N/2 items with random weights between 0 and 10,
and N/2 items with random weights between 4 and 7.
Important: You can tune your Near-Optimal Greedy
Algorithms based on the characteristics of the input
generators.
Download