NPDatalog: a Logic Language for Expressing NP Search and Optimization Problems