1

We are a group of first-year students studying computer science.

We are working on a project called "The electronical diet plan" (directly translated)

We want to make a program in C# that on a weekly basic calculate a diet plan that fullfiels/satisfies some criteria:

Your daily energy intake should not exceed the calculated calorie needs. (Ex. If we calculate that a person should eat 2000 calories per day, the diet plan should plan approximately 2000 calories)

The daily energy (calories) should be distributed as follows:

  • Fat 25-35%
  • Carbohydrates 50-60%
  • Proteins 10-20%

We have a "database" with food and how much fat, carbohydrates and proteins it contains + the approximate price. And we have a "database" with recipies and how much time it takes to cook it.

SO: We want to make a program that on a weekly basic calculate a good diet plan which satisfies the daily energy need (and how it should be distributed (fat, carbohydrates, proteins)). The program should also plan a diet plan that not takes a lot of time and not cost to much (the user defines a upper bound for the price pr. week).

SO.. We want help to find a method/algorithm that can combinate 3-6 dishes per day which satisfied this ^^ We have been looking at a lot of combinational optimizations algorithms/problems but mostly "The knapsack problem".

But these algorithms/problem is only satisfying one criteria or trying to find the "cheapest" solution. -> We want to satisfy a lot of criteria and want to find the best solution (not cheapest.. ex. fat has to be between 25-35%, not just be the lowest value)

We hope that some of you can help us with a good algorithm.

4

1 回答 1

3

当谈到寻找“最便宜”的解决方案而不是“最好的”时,您只需要重新定义“便宜”。

在优化理论中,通常指的是要最小化的成本函数-在您的情况下,“成本”可能是“与 30% 的脂肪百分比差异”,即吃 30% 的脂肪不需要任何成本,而吃 20% 作为 40%。当然,为了使方法更复杂,你可以称重,这样吃太多脂肪比吃太少更“昂贵”。

现在,如果您为每个标准创建成本,您还必须一起权衡它们,正如 mellamokb 在评论中指出的那样;为此,只需计算加权总成本。你最终会得到类似下面的东西:

饮食成本=(价格的重要性)*价格+(时间的重要性)*时间+(脂肪的重要性)*(与脂肪目标的偏差)+等...

如果你想让它不可能超出预算(花费的钱),你可以添加一些术语,比如
over budget ? infinity : 0让算法在预算内找到解决方案。您还可以限制用餐的重复等 - 或多或少是您的想象力(和计算能力)设置了限制。

现在您有了成本函数,您可以开始着手解决问题:最小化饮食成本。突然间,所有那些找到“最便宜”解决方案的算法都变得有意义了……;)


请注意,制定此成本函数通常是困难的部分。根据您权衡成本的方式,您会找到非常不同的解决方案;并非所有这些都是有用的(实际上它们中的大多数可能不会有用)。

于 2013-04-17T19:46:03.200 回答