Recipe scheduler

(cliffs at the bottom)

In a few days I'm cooking for 15 people and the meal itself involves making 6 mini-meals (6 different italian dishes). So while i was writing out a menu I thought I would write a C++ program that allowed me to input the food name, cooking instructions and time to do said instruction. I could then arrange things so that I had a list of what to do when. This was really more of a 'database' (or information storage rather) exercise than anything else as I'm sure pen and paper would have done the job in 5 mons. The output I wanted was to be in the form...

0:00 (time elapsed since the start of cooking)
Meal1
Do this
5 mins (how long this part will take to cook)

0:05
Meal1
Do this next thing
10 mins

0:08
Meal2
Start meal2
7 mins

0:15
Everythings Finished.



Now this turned out to be a hell of a lot more difficult than I thought it would be. The main difficulty was arranging everything in order at the end and figuring out a way to store the data such that I could retrieve it and get all the info needed.

The method I used is likely the worst method possible and I sort of botched it all together just to make it work in time so I'd like to see other folks opinions on how they would do this.

I basically created 3 text files.

One (FILE_1) storing the following

Meal name
Instruction
Cooking time
-blank-
...etc

another (FILE_2) storing the following
Meal Name
Instruction
How much time this meal has left
-blank-


and the final file was the sorted output.


So upon running the program, I create 2 vectors to retrieve the data from FILE_1 and FILE_2. I then add in a new recipe, this get's added to each vector in the correct format. Then using the max cooking time for any one dish and the two vectors, I run through all my data and sort it into the correct format to output to the final text file.

My codes fairly long and ugly as hell (held together with duct tape sort of code) so I haven't posted it up but I'd like to know how you guys would tackle this problem. Specifically what sort of storage method would you use and what sort of data structures within the code (list perhaps?).

(I also included am erase option that can remove a certain meal type)


Cliffs for those that want to skip the above.
- Create a cooking schedule program that allows you to input several recipes and outputs a schedule that tells you when to start doing things.
- How to store the info and what type of data structures to use in the code.
Last edited on
I see repetition of information between the two files, unless i am understanding this incorrectly (it could be very possible): Both files contain "Instruction", and I imagine the instruction is the same in both. I don't see the need for this. Why not this?

Single file:
Meal name
Instruction
Cooking time
Time left for this meal
---blank line---

I also don't know that "Time left for this meal" is and therefore cannot understand how it would alter the time calculations.
[Warning: post below may not even remotely answer your question.]

Cooking a meal is a (Project) Scheduling exercise: a set of activities ("boil water", "cut tomatoes", etc.) and a set of precedence rules ("can't cook rice before water is boiling", "can't add vegetables until they are cut", etc.), possibly with resource constraints (you can do only one "manual" thing at a time, but something can be baking or boiling in the meantime).

If you're up for a bit of work, you could program a basic scheduler; there are some more-than-decent greedy heuristics that are very simple to implement. Generally, they all boil down to:

0) Initialize list of activities, set all to "unfinished, unscheduled".
1) At time T, find all (unscheduled/unfinished) activities that have no unfinished predecessors and for which the required resources are available.
2) In case of multiple available tasks, use a priority list as a decision mechanism.
3) Schedule task(s) selected in 2. Calculate T_finished for newly scheduled task(s).
4) Advance T to minimum of T_finished for all currently scheduled activities.
5) Mark finished activities. Return to 1.

The output will be a timeline of what activity should be started when, in which order.

The useful data structure for this type of algorithm is a Priority Queue, generally implemented as some sort of Heap (stick to Binary Heaps if you're new to this!).

To easily organize your data:
-Keep an array/valarray/vector of Tasks, unordered, in the way they were read in.
-Keep an a/va/vec of Task pointers, for your implementation of the PQ/Heap.
-Keep an a/va/vec of Task pointers for the final output; vec[0] will be a pointer to the Task that has to be started first.
Gaminic's reply reminded me of Critical Path: http://en.wikipedia.org/wiki/Critical_path_method .
@webJose: Indeed! I'm not sure if CP (or CC) project management can handle resource constraints, but that's a very easy technique to use for "simple" problems. In retrospect, I probably should've started off with that.
@Web Yeah fully aware of that but it was just to keep things together So I could follow what was going on. The reason for the two different timings is that, when I originally made this thing, I just had the cooking time but when I would reopen the program to add more recipies, there was no easy way for me to sort things based solely on cooking time. I.e. If I had 2 things...

Meal1, step1, takes 1 min
Meal1, step2, takes 1 min

Meal2, step1, takes 1 min
Meal2, step2, takes 1 min

Reading just that info in wouldn't give you an idea of where to put things in the final output unless you grouped things together by meal name and did some adding up and modifications. Hence I made a file containing just...


Meal1, step1, 2 min left
Meal1, step2, 1 min left

Meal2, step1, 2 min left
Meal2, step2, 1 min left

Then this can clearly be ordered with the 2 min things coming before the 1 min things in the final output.


@Gaminic I'll have a look at that thanks.


My method was basically...

Vector of the form.

Meal name
Instruction
Time left before meal is done
-blank- (just for clarity when debugging)

Then I would run through the vector selecting the largest 'Time left before meal is done' entries and output this to a final text file but replacing the 'time left before meal is done' part with 'Cooking time for this instruction' which was contained within my other vector.

Only thing I also had to do was keep track of the maximum cooking time so as to be able to output the 0:00 timer parts.


I suppose part of the reason for keeping the extra info in both text files (meal, instruction twice etc) was so I could use the same indexes and not worry about having to use index k for one thing and index 4*k for another. Would likely end up getting in a mess.
Last edited on
Topic archived. No new replies allowed.