An Extension of Datalog for Modelling and Solving Complex Combinatorial Problems