Text this: Solving Spatial Optimization Problems via Lagrangian Relaxation and Automatic Gradient Computation