private static RecipesOptimization DeepExplorationNode(Dictionary <string, Ingredient> ingredientsLocalOriginal, bool maximizeCount, RecipesOptimization origin, RecipesOptimization best, Dictionary <string, Recipe> Recipes) { foreach (Recipe rec in Recipes.Values) { RecipesOptimization actual = origin.Clone(); Dictionary <string, Ingredient> ingredientsLocal = new Dictionary <string, Ingredient>(); foreach (Ingredient ingr in ingredientsLocalOriginal.Values) { ingredientsLocal.Add(ingr.name, ingr.Clone()); } bool usable = true; foreach (Ingredient ing in rec.ingredients) { if (ingredientsLocal[ing.name].quantity < ing.quantity) { usable = false; } } if (usable) { foreach (Ingredient ing in rec.ingredients) { ingredientsLocal[ing.name].quantity = ingredientsLocal[ing.name].quantity - ing.quantity; actual.unusedInventoryCount = actual.unusedInventoryCount - ing.quantity; } actual.recipeCount = actual.recipeCount + 1; bool find = false; foreach (RecipeCount Rc in actual.recipes) { if (Rc.id == rec.id) { Rc.count = Rc.count + 1; find = true; } } if (!find) { RecipeCount aux = new RecipeCount(rec.id); aux.count = 1; actual.recipes.Add(aux); } if (actual.recipeCount > best.recipeCount & maximizeCount) { best = actual; } else if (actual.unusedInventoryCount < best.unusedInventoryCount & !maximizeCount) { best = actual; } best = DeepExplorationNode(ingredientsLocal, maximizeCount, actual, best, Recipes); } } return(best); }
// // GET: /Home/ public ActionResult Index() { var recipeCount = new RecipeCount { Time = _clock.Now, NumRecipes = _repository.Count }; return(View(recipeCount)); }
private void AddRecipe() { RecipeCount.Add(RecipeCount.Count + 1); RecipeCount = new List <int>(RecipeCount); }