开发者

What is the most flexible way to design a scheduler for automatic task completion, which is also practical to implement?

Let's say you have some number (C) of cats and some number (M) of mice and some number (H) of holes that the cats may be able to find mice in. This is just to generalize a problem and if anything that follows doesn't make real world sense, please remember it's just to provide a silly example so we have something to talk about.

Assuming it takes a non-negligible amount of CPU time to check whether cat c can find mouse m in hole h, how would you design a database to keep track of which combinations you've already checked? What if you need to prioritize the checking of certain combinations? What if you want to be able to schedule the processing of mice M1 to M5 with cats C4 to C9 and holes H3 to H7? What if you want to process this in order of holes first (as in, hole H3 gets checked for all combinations of mice and cats before hole H4) or cats first (C4 for all combinations of others before C5), etc?

Is there some very clever way of generalizing this to N number of things to be combined? For example, what if we needed to add in some number of dogs? 开发者_如何学CIs there some clever way of allowing complicated scheduling prioritization without being overly complicated? What should I be reading to sort out this problem?

The design I'm thinking about right now is something like this:

table: scheduled_tasks columns: first_cat, last_cat, first_mouse, last_mouse, first_hole, last_hole, completed?, cat_order (ie. 1), mouse_order (ie. 2), hole_order (ie. 3)

the _order columns would indicate which loop is the outermost, essentially.

table: completed_tasks columns: cat, mouse, hole, when_completed

or possibly...

table: completed_tasks columns: first_cat, last_cat, first_mouse, last_mouse, first_hole, last_hole which would have first_cat = last_cat, first_mouse = last_mouse, etc. initially and then automatically group together adjacent rows to more quickly search through which tasks had already been completed to avoid doing redundant work.

What would be a good way to generalize this? Perhaps the scheduler program should make a new table if we add more dimensions (ie. dogs) to the mix, or perhaps the table structure should be made more flexible. For example, rather than first_cat, last_cat, ..., there would be a related table "entities_to_cycle" (or something like that) which would have columns: entity, first, last.

Anyway, what are your thoughts on this?

I'm also tagging this PHP/MySQL because I'll be using those to implement this. If this affects your answer, please make a note of where your answer is affected.

Last note: If there are several hundred thousand tasks to be completed, then it seems that breaking the tables up (generalizing and normalizing) would make searching/inserting much more time consuming...


well part of this question i think is answered like this:

cat
-----
cat_id
name

mouse
------
mouse_id
name

hole
------
hole_id
name

mouse_hole
-----------
moue_hole_id
mouse_id
hole_id

either do this part in memory, or save the values in a sturcture like:

cat_task
---------
cat_id
mouse_hole_id
status(?)


Here's one idea: Store a table with columns

Cat(Int), Mouse(Int), Hole(Int), Found(Bool)

and create an index on Cat, Mouse, Hole, (Cat, Mouse), (Cat, Hole), (Mouse, Hole).

This way you can efficiently look up which MousesMice and Holes you've explored for a given cat, or which Holes you've explored for a given Mouse+Cat, etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜