private void InstructionPopUpAddButton_Click(object sender, RoutedEventArgs e)
        {
            int taskTime = 0;

            try
            {
                taskTime = Int32.Parse(TaskTime.Text);
            }
            catch (FormatException ex)
            {
                Console.WriteLine(ex.Message);
                taskTime = 0;
            }

            Console.WriteLine("TaskTime: " + taskTime);

            RecipeTask task = new RecipeTask(TaskDescription.Text, taskTime, (bool)isActiveCheckbox.IsChecked);

            myRecipesTabModel.AddRecipeTask(task);
            myRecipesTabModel.StopAddingRecipeTask();

            TaskDescription.Text       = string.Empty;
            TaskTime.Text              = string.Empty;
            isActiveCheckbox.IsChecked = false;
        }
        public MainWindow()
        {
            //currently using this as a test driver, will remove this junk later
            RecipeTask r1 = new RecipeTask("a", 1, true);
            RecipeTask r2 = new RecipeTask("b", 2, true);
            RecipeTask r3 = new RecipeTask("c", 3, true);
            RecipeTask r4 = new RecipeTask("d", 15, true);
            RecipeTask r5 = new RecipeTask("e", 100, false);
            Recipe     re = new Recipe("aa");

            re.addTask(r3);
            re.addTask(r3);
            Recipe re2 = new Recipe("bb");

            re2.addTask(r1);
            re2.addTask(r5);
            re2.addTask(r4);
            Meal m = new Meal("owowowow");

            m.addRecipe(re);
            m.addRecipe(re2);

            m.cook();
            Console.WriteLine("Timereq: " + m.TotalTimeRequired);
            InitializeComponent();
        }
Ejemplo n.º 3
0
        public void AddRecipeTask(RecipeTask newTask)
        {
            foreach (Recipe recipe in recipes)
            {
                if (recipe.Name == currentRecipe.Name)
                {
                    recipe.addTask(newTask);
                    currentRecipe = recipe;
                    OnPropertyChanged("CurrentRecipe");
                }
            }

            UserData.UserRecipes = recipes;
        }
 public void editTask(RecipeTask r, int taskNum)
 {
     tasks[taskNum] = r;
 }
 public void addTask(RecipeTask r)
 {
     tasks.Add(r);
     totalTime += r.TimeRequired;
 }
Ejemplo n.º 6
0
        //cook processes all the data and is the main algorithm.
        //After calling cook(), getTotalTimeRequired() and getSortedRecipeTasks() are natural next steps
        public void cook()
        {
            //terra: i have a gigantic brain
            int numRecipes = recipes.Count;

            if (numRecipes == 0)
            {
                return;
            }

            int [] tasksPerRecipe = new int[numRecipes];
            for (int i = 0; i < numRecipes; i++)
            {
                tasksPerRecipe[i] = recipes[i].getNumTasks();
            }
            //an array of total time remaining at each step. Each row is a recipe, each column is the time to finish.
            int [,] totalTimeRemaining = new int[numRecipes, tasksPerRecipe.Max()];
            int lastTime;

            for (int i = 0; i < numRecipes; i++)
            {
                lastTime = 0;
                for (int j = recipes[i].getNumTasks() - 1; j >= 0; j--)
                {
                    totalTimeRemaining[i, j] = recipes[i].getTasks()[j].getTime() + lastTime;
                    lastTime = totalTimeRemaining[i, j];
                }
            }
            //these are iterators that increment for each recipe's task
            int [] taskIterators = new int[numRecipes];
            for (int i = 0; i < numRecipes; i++)
            {
                taskIterators[i] = 0;
            }
            //these are holds put on a recipe's task while a passive task is happening. 0 is no hold
            int [] holds = new int[numRecipes];
            for (int i = 0; i < numRecipes; i++)
            {
                holds[i] = 0;
            }
            //Here's the juicy part
            totalTimeRequired = 0;
            while (!Enumerable.SequenceEqual(tasksPerRecipe, taskIterators))
            {
                int longestTimeRemaining = 0;
                int longestTimeIndex     = -1;

                //If all recipes that aren't finished are on hold, then set the lowest hold to 0.
                int lowestHold      = Int32.MaxValue;
                int lowestHoldIndex = -1;
                for (int i = 0; i < numRecipes; i++)
                {
                    //make sure recipe isn't done
                    if (taskIterators[i] < tasksPerRecipe[i])
                    {
                        if (holds[i] < lowestHold)
                        {
                            lowestHold      = holds[i];
                            lowestHoldIndex = i;
                        }
                    }
                }

                holds[lowestHoldIndex] = 0;

                for (int i = 0; i < numRecipes; i++)
                {
                    //make sure that recipe isn't done or on hold
                    if (taskIterators[i] < tasksPerRecipe[i] && holds[i] == 0)
                    {
                        //compute max
                        if (totalTimeRemaining[i, taskIterators[i]] > longestTimeRemaining)
                        {
                            longestTimeRemaining = totalTimeRemaining[i, taskIterators[i]];
                            longestTimeIndex     = i;
                        }
                    }
                }

                //This is the recipe task to select to add.
                RecipeTask recipeTask = recipes[longestTimeIndex].getTasks()[taskIterators[longestTimeIndex]];
                sortedRecipeTasks.Add(recipeTask);
                totalTimeRequired += recipeTask.getTime();

                //fixed the time calculation here!
                if (holds[longestTimeIndex] > 0)
                {
                    totalTimeRequired -= recipeTask.getTime();
                }

                //update all of the holds
                for (int i = 0; i < numRecipes; i++)
                {
                    holds[i] = Math.Max(0, holds[i] - recipeTask.getTime());
                }

                //if the task is passive, add a hold
                holds[longestTimeIndex] = !recipeTask.getActive() ? recipeTask.getTime() : 0;

                taskIterators[longestTimeIndex]++; //iterate to next task for that recipe
            }
            //Debugging
            Console.WriteLine("Sorted List:");
            foreach (var recipeTask in sortedRecipeTasks)
            {
                Console.WriteLine(recipeTask.getTime());
            }
            //End Debugging
        }