Scheduling program/algorithm

Status
You're currently viewing only floccinau's posts. Click here to go back to viewing the entire thread.
Not open for further replies.
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
 
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
You're currently viewing only floccinau's posts. Click here to go back to viewing the entire thread.
Not open for further replies.