Some code for discrete optimization