Algorithm for choosing foods based on macro nutrients -


I have a large group of food ingredients, each of which has protein, carb and fat properties. Example:

  Food Name PCF Food 1 10 5 3 Food 2 3 10 8 Food 3 4 20 5 I have to type a function that looks like this:  
  Private listing & lt; Food & gt; CombineFoodsBasedOnMacro (P, C, F)   

This function should choose two different foods and add them to different amounts so that when we select P, C and F Add the quantity of foods they are close to passed P, C, F parameters.

Example

  CombineFoodsBasedOnMacro (45, 40, 20)   

Acceptable 'answer' can be: < Which will be the total amount:

  P = 44, C = 40, F  

= 17

My question is, what algorithm can I use for such calculation / approximation?

This problem is NP-hard , and for multilevel instead of set There is generalization, and thus there is no known polynomial solution to the problem (and most believe that such a solution is not present).

You can use this problem to try and solve, such as:

  at least sum (x_s) (number of sets), St: S. Um (x_s | for all sets) #p (s) * x_s> = p // To repeat c, f x_s = 0 || X_s = 1   

Note that #p (s) is not a variable, so this integer is fine for linear programming.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -