DC3: A learning method for optimization with hard constraints