![]() The ORLib dataset proposed by Chu and Beasley (1998). The SAC-94 dataset, based on a variety of real-world problems. Now choose the suitable solution set depending on the ratio values as explained in starting.All benchmarks instances from three well known multidimensional knapsack problem (MKP) libraries are provided in a standard format here, as used in Drake et al. Similarly, the W1, W2, W3 are the summation of the weights of these sets. The R1, R2, R3 are further subsets of the ratio set depending on the ratio being less, equal or greater than that of the median element. We are comparing this value to the randomly selected r value and then segregating based on the comparison of the ratio. Similarly, represents the ith elements profit is to the ith weight value. ![]() W is the summation of the entire weight of this set, used to compare with the capacity of your knapsack. In the solution you have pasted: R is the set of ratios, profit/weight The recurrence here is T(n)=T(n/2) O(n), and we have that T(n)=O(n), as desired. ![]() If you can't, then you can throw out the n/2 items of lower value, and then try to solve the problem again with only the n/2 items of highest value. If you can, then do so, and recursively solve this problem for the n/2 items of lower value given that you've already filled the knapsack. Then, also in linear time, you can figure out if you can fit all items that are at least that valuable in the knapsack or not. In linear time, you can find the median item in terms of value per unit weight. See how the algorithm you quote combines the technique of quickselect with the greedy approach.Understand the classical greedy algorithm for fractional knapsack.I suggest the following route to understand the algorithm: The algorithm you describe uses the same trick use in quickselect to reduce the running time to $O(n)$, at the cost of making the algorithm randomized. Implementing this algorithm requires sorting the list $p_i/w_i$, which takes time $O(n\log n)$. If you run out, choose the next one, and put as much of it as possible. You can implement this without dividing $W$ into a $1000$ pieces: Choose the item with maximal $p_i/w_i$, and put as much of it as possible. If we run out, we choose the item with the next largest $p_i/w_i$, and so on. When choosing what to put in a slot, we would like to maximize our profit, and so we choose the item with maximal $p_i/w_i$, and put it as many pieces as possible. For an item weighing $w_i$, we have $w_i/(W/1000)$ pieces (suppose for the moment that this is an integer), and each of them is worth $p_i/(w_i/(W/1000))$. Suppose you divide $W$ into a $1000$ "slots", which you want to fill with the most profitable item-parts of weight $W/1000$. What would you do? Naturally, you would first put as much gold as you can - namely, all of it, and then you would put it as many bananas as you can - namely, a tenth of it, for a total profit of $1000.1$. You also have bananas, with a profit of $1$ and weight $10$. You have raw gold, with a profit of $1000$ and weight $1$. For each item $x_i$, you are allowed to put any fraction $\theta \in $ of it, which will give you profit $\theta p_i$ and weight $\theta w_i$. You want to maximize your profit under the constraint that the total weight is at most $W$. I assume that you have $n$ items $x_i$, each having profit $p_i$ and weight $w_i$. It would be nice if you stated the problem.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |