I often spend much, much, more time QAing and debugging my code than I do actually writing the optimization problem or shaping my data. Are there any tools or techniques to make it easier? I am asking specifically about the challenges operations research adds to programming.
Here is an example: Let's say we wanted to solve a newsvendor problem with shortage costs. An initial optimization model may look like:
$$\max_{Q\geq 0} ~E(-cQ - e(d_i-Q)^+ +v(Q-d_i)^+ ) $$ where $Q$ is the order quantity, $d_i$ is the stochastic demand for each $i \in \{1,\ldots, N\}$, $c$ is the per-unit cost, $e$ is a shortage cost, and $v$ is a salvage value.
However, this has nonlinearities that we have to resolve. The linear model looks like:
$$\max_{Q\geq 0} ~E(-cQ - eS_i^{(1)} +vS_i^{(2)}) \\ \mbox{s.t.} ~ S_i^{(1)} > d-Q~~~~~\forall i \in \{1,\ldots, N\}~~~~~~~~~~ \\ S_i^{(2)} > Q-d~~~~~\forall i \in \{1,\ldots, N\}~~~~\\ S_i^{(1)}, S_i^{(2)} \geq 0~~~~\forall i \in \{1,\ldots, N\}.~~~$$
Even this may not be the final version though. Sometimes we might want to know details that are not easily available from the information in the optimal solution. In the past, I have sometimes added even more variables to see a particular slice of costs.
For a model this many steps from the original, I often find it slow to verify that I haven't mixed up inequalities or left something out. When I am using PuLP, I can inspect the lp model directly, but the slack variables can still make it confusing for practical-sized problems. Is there anything I'm missing in how to handle these two sources of OR-specific programming complexity?