Problem: Given a set of obligatory and optional courses each being available only in certain time slots (there are 7 time slots) generate all possible timetables.
Example:
For obligatory courses:
- MAT101 - 1, 2, 5
- HIS102 - 2, 4, 6
- ENG105 - 3, 6, 7
And optional courses:
- LIT103 - 3, 4, 6
- CHE101 - 7, 1, 2
- BIO101 - 5, 4, 7
- MAT201 - 6, 5, 1
- ANT201 - 1
(not every optional course must be included in a timetable)
One of the possible solutions would be:
- MAT101 [obligatory]
- HIS102 [obligatory]
- LIT103
- BIO101
- MAT201
- ENG105 [obligatory]
- CHE101
What's the most efficient way to write it in PHP?
I'm currently trying to develop a brute-force solution, but it's a very tedious task and I'm looking for more efficient ways to do it. I figured out it's a NP-complete problem and searched for PHP classes helpful in solving such a problems, but I'm afraid there is no such a class available at the moment.