Artificial Intelligence Stack Exchange is a question and answer site for people interested in conceptual questions about life and challenges in a world where "cognitive" functions can be mimicked in purely digital environment. It only takes a minute to sign up.
What you're looking for is most likely constraint programming (CP). Essentially, with a CP model you declare a set of variables and a set of constraints (and an objective, optionally). Then a solver will solve your model and find a solution if one exists (if you had specified an objective, it will find the best solution).
Here is an example which is very silimar to your problem (a MiniZinc model which solves the problem is included). You can download MiniZinc and try it out for yourself.