title: Teacher time schedule algorithm
body: <p>This is a problem I've had on my mind for a long time. Being the son of a teacher and a programmer, it occurred to me early on... but I still haven't found a solution for it.</p>
  
  <p>So this is the problem. One needs to create a time schedule for a school, using some constraints. These are generally divided in two categories:</p>
  
  <p><strong>Sanity Checks</strong>  </p>
  
  <ul>
  <li>A teacher cannot teach two classes at the same time</li>
  <li>A student cannot follow two lessons at the same time</li>
  <li>Some teachers must have at least one day off during the week</li>
  <li>All the days of the week should be covered by the time table</li>
  <li>Subject X must have exactly so-and-so hours each week</li>
  <li>...</li>
  </ul>
  
  <p><strong>Preferences</strong>  </p>
  
  <ul>
  <li>Each teacher's schedule should be as compact as possible (i.e. the teacher should work all hours for the day in a row with no pauses if possible)</li>
  <li>Teachers that have days off should be able to express a preference on which day</li>
  <li>Teachers that work part-time should be able to express a preference whether to work in the beginning or the end of the school day.</li>
  <li>...</li>
  </ul>
  
  <p>Now, after a few years of not finding a solution (and learning a thing or two in the meanwhile...), I realized that this smells like a NP-hard problem.</p>
  
  <p>Is it proven as NP-hard? </p>
  
  <p>Does anyone have an idea on how to crack this thing?</p>
  
  <p>Looking at <a href="https://stackoverflow.com/questions/184195/seating-plan-software-recommendations-does-such-a-beast-even-exist">this</a> question made me think about this problem, and whether genetic algorithms would be usable in this case. However it would be pretty hard to mutate possibilities while maintaining the sanity check rules. Also it's not clear to me how to distinguish incompatible requirements.</p>
  
  <hr>
  
  <p>A small addendum to better specify the problem. This is applied to Italian school style classrooms where all students are associated in different classes (for example: year 1 section A) and the teachers move between classes. All students of the same class have the same schedule, and have no choice over which lessons to attend.</p>