Exemple #1
0
        private List <Menu> breed(List <Menu> menuPopulation)
        {
            List <Menu> res = new List <Menu>();

            Random random            = new Random();
            int    randomMenues      = random.Next(20, 30);
            int    randomItemsToSwap = random.Next(3, 7);

            for (int i = 0; i < randomMenues; i++)
            {
                int randomMenu1 = random.Next(0, 5);
                int randomMenu2 = random.Next(0, 5);

                while (randomMenu2 == randomMenu1)
                {
                    randomMenu2 = random.Next(0, 5);
                }

                Menu newMenu1 = new Menu(menuPopulation[randomMenu1]);
                Menu newMenu2 = new Menu(menuPopulation[randomMenu2]);

                for (int j = 0; j < randomItemsToSwap; j++)
                {
                    // 1 - breakfast, 2 - Lunch, 3 - dinner
                    int randomMeal = random.Next(1, 4);

                    switch ((MealTypeENUM)randomMeal)
                    {
                    case MealTypeENUM.Breakfast:
                    {
                        mergeMeals(newMenu1.Breakfast, newMenu2.Breakfast);
                        break;
                    }

                    case MealTypeENUM.Lunch:
                    {
                        mergeMeals(newMenu1.Lunch, newMenu2.Lunch);
                        break;
                    }

                    case MealTypeENUM.Dinner:
                    {
                        mergeMeals(newMenu1.Dinner, newMenu2.Dinner);
                        break;
                    }
                    }
                }

                res.Add(newMenu1);
                res.Add(newMenu2);
            }

            menuPopulation = menuPopulation.Concat(res).ToList();

            int  randomMutation = random.Next(1, 5);
            Food tmpRM, tmpNew;

            for (int i = 0; i < randomMutation; i++)
            {
                int randomMutationIndex = random.Next(0, menuPopulation.Count());
                // 1 - breakfast, 2 - Lunch, 3 - dinner
                int randomMeal = random.Next(1, 4);

                switch ((MealTypeENUM)randomMeal)
                {
                case MealTypeENUM.Breakfast:
                {
                    int randomFood1 = random.Next(0, menuPopulation[randomMutationIndex].Breakfast.Count);
                    tmpRM = menuPopulation[randomMutationIndex].Breakfast[randomFood1];
                    menuPopulation[randomMutationIndex].Breakfast.RemoveAt(randomFood1);
                    tmpNew = FoodDal.getInstance().GetRandFood(MealTypeENUM.Breakfast);
                    while (tmpNew.FoodID == tmpRM.FoodID)
                    {
                        tmpNew = FoodDal.getInstance().GetRandFood(MealTypeENUM.Breakfast);
                    }
                    menuPopulation[randomMutationIndex].Breakfast.Add(tmpNew);
                    break;
                }

                case MealTypeENUM.Lunch:
                {
                    int randomFood1 = random.Next(0, menuPopulation[randomMutationIndex].Lunch.Count);
                    tmpRM = menuPopulation[randomMutationIndex].Lunch[randomFood1];
                    menuPopulation[randomMutationIndex].Lunch.RemoveAt(randomFood1);
                    tmpNew = FoodDal.getInstance().GetRandFood(MealTypeENUM.Lunch);
                    while (tmpNew.FoodID == tmpRM.FoodID)
                    {
                        tmpNew = FoodDal.getInstance().GetRandFood(MealTypeENUM.Lunch);
                    }
                    menuPopulation[randomMutationIndex].Lunch.Add(tmpNew);
                    break;
                }

                case MealTypeENUM.Dinner:
                {
                    int randomFood1 = random.Next(0, menuPopulation[randomMutationIndex].Dinner.Count);
                    tmpRM = menuPopulation[randomMutationIndex].Dinner[randomFood1];
                    menuPopulation[randomMutationIndex].Dinner.RemoveAt(randomFood1);
                    tmpNew = FoodDal.getInstance().GetRandFood(MealTypeENUM.Dinner);
                    while (tmpNew.FoodID == tmpRM.FoodID)
                    {
                        tmpNew = FoodDal.getInstance().GetRandFood(MealTypeENUM.Dinner);
                    }
                    menuPopulation[randomMutationIndex].Dinner.Add(tmpNew);
                    break;
                }
                }
            }

            return(menuPopulation);
        }
Exemple #2
0
 private FoodActions()
 {
     dal = FoodDal.getInstance();
 }
Exemple #3
0
        static void Main(string[] args)
        {
            FoodDal        food_dal   = FoodDal.getInstance();
            GoalDal        goal_dal   = GoalDal.getInstance();
            MealsInMenuDal mim_dal    = MealsInMenuDal.getInstance();
            MealTypeDal    mt_dal     = MealTypeDal.getInstance();
            MeasurementDal msrmnt_dal = MeasurementDal.getInstance();
            MenuDal        menu_dal   = MenuDal.getInstance();
            UserDal        user_dal   = UserDal.getInstance();

            //Menu menu = menu_dal.GetMenu(1);
            //User user = user_dal.GetUser(4);
            //List<Menu> lstMenues = new List<Menu>();

            //Menu menutest;

            //for (int i = 1; i < 6; i++)
            //{
            //    menutest = menu_dal.GetMenu(i);
            //    lstMenues.Add(menutest);
            //}

            //GeneticAlgo.getInstance().startAlgo(user);

            #region Food
            //food_dal.InsertOrUpdateFood(new Food()
            //{
            //    Name = "orez",
            //    Calories = 3400,
            //    Carbohydrates = 2.22,
            //    Fat = 44.2,
            //    Protein = 5.55,
            //    Category = 1
            //});

            //Food getFoodById = food_dal.GetFoodById(1);

            //List<Food> getAllFoods = food_dal.GetFoods();

            //bool deleteFood = food_dal.DeleteFood(2);
            #endregion

            //User us = new User()
            //{
            //    Birthday = DateTime.Now,
            //    Email = "*****@*****.**",
            //    FirstName = "aba",
            //    Gender = 1,
            //    Height = 1.95,
            //    LastName = "bo",
            //    Password = "******",
            //    Measurement = new Measurement()
            //    {
            //        BodyFat = 15,
            //        Weight = 100
            //    },
            //    Goal = new Goal()
            //    {
            //        BodyFat = 12,
            //        StartingWeight = 100,
            //        GoalWeight = 80
            //    },
            //    MeasurementID = 0,
            //    GoalID = 0
            //};


            //Menu menu = new Menu(0);
            //menu.Breakfast.Add(food_dal.GetFoodById(1));
            //menu.Breakfast.Add(food_dal.GetFoodById(2));
            //menu.Breakfast.Add(food_dal.GetFoodById(13));
            //menu.Lunch.Add(food_dal.GetFoodById(7));
            //menu.Lunch.Add(food_dal.GetFoodById(8));
            //menu.Lunch.Add(food_dal.GetFoodById(9));
            //menu.Dinner.Add(food_dal.GetFoodById(6));
            //menu.Dinner.Add(food_dal.GetFoodById(12));
            //menu.Dinner.Add(food_dal.GetFoodById(13));

            //menu_dal.InsertMenu(menu);

            //Menu menucheck = menu_dal.GetMenuById(1); // WORKS
            //Menu menucheck2 = menu_dal.GetMenu(8); // WORKS
            //List<Menu> menucheck3 = menu_dal.GetMenues(); // WORKS
            //menu_dal.InsertMenu(menu);
            //Menu menucheck2 = menu_dal.GetMenu(10);
            //menucheck2 = menu_dal.IncreasePickRate(menucheck2);



            //bool isLoginOK = UserActions.getInstance().checkLogin("*****@*****.**", "ppa123");

            //List<User> lstusers = user_dal.GetUsers();

            //int userId = user_dal.InsertOrUpdateUser(us);

            //User userFromGetUser = user_dal.GetUser(1);

            //userFromGetUser.Goal.GoalWeight = 88.8;

            //int userIdAfterUpdate = user_dal.InsertOrUpdateUser(userFromGetUser);


            //bool s1 = user_dal.IsUserExists("*****@*****.**");
            //bool s2 = user_dal.IsUserExists("*****@*****.**");

            Console.WriteLine("stam");
        }