Optimisation/knapsack algorithm with multiple contraints in JavaScript
问题 I'm looking for a solution to the knapsack problem where multiple constraints are in place. Say our knapsack has a maximum weight of 30kg and we have a set of 100 objects, each with a weight and each with a benefit. These objects could look like this: { name: 'water bottle', weight: 2, benefit: 5 }, { name: 'potatoes', weight: 10, benefit: 6 } Finding the combination of objects with the highest benefit within the maximum weight is simple enough. Here is a nodeJS plugin showing how it can be