# QA techniques for optimization problem coding

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?

• Tell us in detail what kinds of problems you are trying to solve, then perhaps we can give concrete advice on tools which can address them in easy to formulate, modify, understandable, and low error-propensity way You may also have to decide whether you are willing to give up execution speed for ease of use and low error-propensity. Jun 25 '19 at 20:43
• I added some details from the most recent case. I think part of the answer is just that I work on fairly complex models so it takes time to get them right. Jun 25 '19 at 21:21
• You haven't addressed such things as whether the model boils down to a MILP, has nonlinearoitues, and if so, apart from integer restrictions, is it convex, etc. Which solvers you have used or would like to use, etc. Jun 25 '19 at 21:58
• Thanks for the guidance on what to add. Most of how I avoid errors is good naming conventions and lots of QA, so I was unsure how much of the challenge is specific to my problem. Jun 25 '19 at 22:40
• I would suggest to concretize the question to OR-specific problems along the suggestions of Mark. For discussing that complex models take more time to get them right, best naming conventions and the importance of (general) QA, you can probably get better answers on Stack Overflow. Jun 25 '19 at 23:26