What you are asking for is a heck of a lot - well beyond what we can give you (we only get a little text box to type in, not a book).
Start with Google:
time table management algorithm[
^] with give you a lot of documents describing different approaches.
But be warned: this is not a trivial task. It is notoriously difficult for an experienced human to do this - computerisinbg it is not going to be a quick job, and you probably have a lot of reading to do!