node.js - Resource Optimization: which one to use Knapsack, brute-force or any other approach? -
in resource allocation problem have n bucket sizes , m resources. resources should allocated buckets in such way there max utilization. need write algorithm in node js
here's problem: let's have 2 buckets of sizes 50 , 60 respectively. resource sizes 20, 25, 40. following more proper representation possible solutions:
solution 1:
| bucket size | resource(s) allocated | utilization |
| 50 | 20, 25 | 45/50 = 0.9 |
| 60 | 40 | 40/60 = 0.667 |
total utilization in case >1.5
solution 2:
| bucket size | resource(s) allocated | utilization |
| 50 | 25 | 25/50 = 0.5 |
| 60 | 20, 40 | 60/60 = 1.0 |
total utilization in case 1.5
inference:
-- knapsack approach return solution 2 because optimization based on higher bucket size.
-- brute-force approach return both solutions. 1 concern approach have is; given have use node js , single threaded, little skeptic performance when n (buckets) , m (resources) large.
will brute-force fine or there better way/algorithm can solve problem? also, concern i've cited above valid in sense?
knapsack problem (and knapsack problem) npc, means, can find solution brute-force or alghoritms have o-complexity same bruteforce, can better in average case...
it single threaded, little skeptic performance when n (buckets) , m (resources) large.
i not sure, if know how thing works. if not create child threads , handle them (which not easy), every standard language work in 1 thread, therefore in 1 processor. , if want more processors much, can create child threads in node.js. in complexity problems, not matter, if solution takes multiple-time more, if "multiple" constant. in case, suppose "multiple" means 4, if have quad-core.
there 2 solutions :
1)backtracking - advanced brute-force mechanism, can in same cases return solution faster.
2)dynamic programming - if have items relatively low-values, while classic brute-force not able find solution 200 items in expected time of universe itself, dynamic approach can give solution in (mili)seconds.
Comments
Post a Comment