Example #1
0
        private GroupDiet GetDiet()
        {
            var groupDiet = new GroupDiet();

            groupDiet.Meals.Add(new GroupMeal());
            groupDiet.Meals.Add(new GroupMeal());
            groupDiet.Meals.Add(new GroupMeal());
            groupDiet.Meals.Add(new GroupMeal());
            groupDiet.Meals.Add(new GroupMeal());

            var split = new RecipeGroupSplit(2);

            split.Adjustments.RemoveAt(1);
            split.Recipe = new Recipe
            {
                NominalWeight   = 100,
                NutritionValues = new NutritionValues
                {
                    Calories = 250,
                    Proteins = 250
                }
            };
            groupDiet.Meals[2].Recipes.Add(split);

            return(groupDiet);
        }
Example #2
0
        private void PerformRecipesLevelMutation(GroupMeal meal, double mutationProbability)
        {
            if (_random.NextDouble() < mutationProbability)
            {
                //add new split
                var split = new RecipeGroupSplit {
                    Recipe = _recipesForMealType[meal.MealType].GetRandomItem()
                };
                var adjustment = new RecipeAdjustment
                {
                    AmountMultiplier = RecipeGroupSplit.Multipliers.GetRandomItem(),
                    PersonId         = _random.Next(_groupSize)
                };

                var duplicate = meal.Recipes.FirstOrDefault(r => r.Recipe == split.Recipe);
                if (duplicate == null)
                {
                    meal.Recipes.Add(split);
                }
                else if (duplicate.Adjustments.All(a => a.PersonId != adjustment.PersonId))
                {
                    duplicate.Adjustments.Add(adjustment);
                }
            }

            foreach (var recipeGroupSplit in meal.Recipes)
            {
                if (_random.NextDouble() < mutationProbability)
                {
                    //add adjustment to split
                    if (recipeGroupSplit.Adjustments.Count < _groupSize)
                    {
                        recipeGroupSplit.Adjustments.Add(GetRandomMissingAdjustment(recipeGroupSplit.Adjustments));
                    }
                }

                for (var adjIndex = recipeGroupSplit.Adjustments.Count - 1; adjIndex >= 0; adjIndex--)
                {
                    if (!(_random.NextDouble() < mutationProbability))
                    {
                        continue;
                    }
                    if (_random.NextDouble() < 0.5)
                    {
                        //remove adjustment from split
                        recipeGroupSplit.Adjustments.RemoveAt(adjIndex);
                    }
                    else
                    {
                        //change multiplier
                        recipeGroupSplit.Adjustments[adjIndex].AmountMultiplier = RecipeGroupSplit.Multipliers.GetRandomItem();
                    }
                }
            }
            meal.Recipes.RemoveAll(r => !r.Adjustments.Any());
        }
Example #3
0
        private RecipeGroupSplit GetRanodmNotInvlolvedRecipe(List <Recipe> includedRecipes)
        {
            var recipeGroupSplit = new RecipeGroupSplit(_personalData.Count);

            do
            {
                recipeGroupSplit.Recipe = _recipes.GetRandomItem();
            } while (includedRecipes.Contains(recipeGroupSplit.Recipe));

            return(recipeGroupSplit);
        }
Example #4
0
 private static RecipeData CreateRecipeData(RecipeGroupSplit recipeGroupSplit)
 {
     return(new RecipeData
     {
         Id = recipeGroupSplit.Recipe.Id,
         Splits =
             recipeGroupSplit.Adjustments.Select(
                 ad => new SplitData {
             Multiplier = ad.AmountMultiplier, PersonId = ad.PersonId
         }).ToList()
     });
 }