Scheduling program/algorithm

Status
Not open for further replies.
So every fall/spring I have to register for classes. I want to sign up for 4 or 5 classes. Now, as I go to a big university, there are several sections available for each of the classes I want to take. The problem is, to figure out what the best schedule is is a pain in the neck. You know the drill, you go, "I want to take this class. And then this one. Uh oh, if I take that one I can't the previous one." you get the idea. So I thought to myself, what if I wrote a program to print out ALL possible schedules for any number of classes you want to take. You could even sort on various fields like: "Fewest days a week", "Least amount of slack time between classes", etc.

So then I thought to myself that even though this SOUNDS like a simple program, I couldn't come up with a good algorithm to do this. Methinks you would need to do a lot of recursion and backtracking, or maybe I'm missing something obvious. Any ideas sirs? :confused:
 
I don't get what's so hard about this. Define a function generateSchedules which:

1) took two arguments. The first is the set of possible classes to add. The second is a partial schedule.
2) Returned a set of all possible schedules.
3) Did 2) by removing the first class from the set of available classes. It then recurses on the current schedule and the reduced set of classes, and unions that with the result of recursing on the old schedule plus the removed class and the reduced set of classes.

This will generate all possible schedules. If you want to avoid double-scheduling, you merely add in a check to make sure that classes added to the schedule in the second recursive call don't conflict. If you want to ensure 4 or 5 classes, then whenever you get down to a maximum of three classes in the schedule, you return the empty set, and whenever you reach 5 classes in the schedule, you return the current schedule. There are a bunch of other filters you can apply in a similar manner.

This will be an exponential algorithm on the number of classes you're choosing from. In the case that you restrict it to 5 classes per schedule, that'll reduce it to O(n^5) running time. You'd better restrict your class set pretty well to start with.

Sorting the schedules by some criteria may be done easily after the generation of schedules.

floccinau
 

gregthebunny

Ars Scholae Palatinae
675
haha, i did the same thing for my software engineering class this semester.

it's a java app that reads class info from an sql database.

you can filter out classes that start too early or too late (you specify time) and class sizes and such and after all the classes are filtered, it'll generate all the possible schedules w/o time conflicts.

[edit]

the entire thing is at geocities.com/bluwhired if you want to check it out.

there's no pseudocode, so you'll have to actually look at all the classes.

the interesting part you want is in ourclasses.java

[This message was edited by gregthebunny on May 21, 2002 at 00:28.]
 
Originally posted by aquinas:
pseudocode? Not for the filtering part, just figuring out all possible schedules.

Code:
scheduleSet generateSchedules(Schedule schedule, classSet classes)
{
    if (there are no more classes)
        return the set containing schedule;
    Class curConsidered = classes.getAnyMember();
    classSet newClasses = classes.remove(curConsidered);

    // We aren't taking the current class.
    scheduleSet set1 = generateSchedules(schedule, newClasses);

    // We are taking the current class.
    scheduleSet set2 = generateSchedules(schedule + curConsidered, newClasses);

    return union(set1, set2);
}
 
Status
Not open for further replies.