Download presentation
Presentation is loading. Please wait.
Published byPoppy Arnold Modified over 9 years ago
1
Dave Risch
2
Project Specifications There is a “knapsack” that you want to fill with the most valuable items that are available to you. Each item has a value, weight, and value density. (which is determined by dividing the value/weight) The items then get listed in order of value density. Uses a greedy algorithm to select the highest valued items. Keeps selecting items until the weight of the next best item can’t fit. At that point, it will skip that item and look for the next item that can fit.
3
Goals Create a NP-hard program that uses a greedy algorithm Program will choose the best items for you to take within a certain weight capacity. Output the items, along with their values, weights and value densities.
4
Applications Applications that use a greedy algorithm usually fail to find the optimal solution. Yet when they do work for a certain class, they are generally used because of their speed. Greedy algorithms are used in applications such as Kruskal’s, Prim’s, and Dijkstra’s. Also used in routing. A message is forwarded to the closest neighboring node.
5
Design Use object programming to make items with value, weights and value densities. Put objects in an array, and sort objects in order of their densities. Loop through, choosing the highest value density objects. Add weights until the next item won’t fit the weight restriction. Skip that object and check the object after to see if it will fit and so on until the weight is maxed out. Add selected items to a list, output the item, value, weight and value density.
6
Testing To test the program, I will use different values, weights, value densities to see if it chooses the correct items. Use different weight restrictions to see if it will choose an item even though the item before it exceeded the max weight. Add or remove items that you can take to mix things up.
7
Conclusions so far After further researching, I found you can use dynamic programming to make the knapsack problem more efficient than if you use a greedy algorithm.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.