SlowGuess/NeurIPS_2023_OCR huggingface dataset:
$$
\left[ \begin{array}{c} f _ {G x} (x, c, G, h) \\ 0 \end{array} \right] + \left[ \begin{array}{c c} f _ {x x} (x, c, G, h) & - A ^ {\top} \\ A & 0 \end{array} \right] \left[ \begin{array}{c} \frac {\partial x}{\partial G} \\ \frac {\partial y}{\partial G} \end{array} \right] = 0 \tag {11}
$$
By solving this system of equalities, we can obtain
Since  $f(x, c, G, h) = c^\top x - \mu \sum_{i=1}^d \ln(x_i) - \mu \sum_{i=1}^q \ln(G_i^\top x - h_i)$ , we have
$$
\begin{array}{l} f _ {x _ {j}} (x, c, G, h) = c _ {j} - \mu x _ {j} ^ {- 1} - \mu \sum_ {i = 1} ^ {q} G _ {i j} / \left(G _ {i} ^ {\top} x - h _ {i}\right) \\ f _ {x _ {k} x _ {j}} (x, c, G, h) = \left\{ \begin{array}{c} \mu \bar {x _ {j} ^ {- 2}} + \mu \sum_ {i = 1} ^ {q} G _ {i j} ^ {2} / \left(G _ {i} ^ {\top} x - h _ {i}\right) ^ {2}, \quad j = k \\ \mu \sum_ {i = 1} ^ {q} G _ {i j} G _ {i k} / \left(G _ {i} ^ {\top} x - h _ {i}\right) ^ {2}, \quad j \neq k \end{array} \right. \tag {12} \\ \end{array}
$$
Lemma B.3. Consider the LP relaxation (7), defining  $x^{*}$  as a function of  $c, A, b, G$  and  $h$ . Then, under this definition of  $x^{*}$ ,
$$
\frac {\partial x ^ {*}}{\partial h} = \left(H ^ {- 1} A ^ {\top} \left(A H ^ {- 1} A ^ {\top}\right) ^ {- 1} A H ^ {- 1} - H ^ {- 1}\right) f _ {h x} (x, c, G, h)
$$
where  $H = f_{xx}$  is defined as in Lemma B.2 and
$$
f _ {h _ {\ell} x _ {j}} (x, c, G, h) = - \mu G _ {\ell j} / (G _ {\ell} ^ {\top} x - h _ {\ell}) ^ {2}
$$
$$
\frac {\partial x ^ {*}}{\partial h} = - H ^ {- 1} f _ {h x} (x, c, G, h)
$$
which is the same as the Lemma 2 in [12].
Proof. As stated in the proof of Lemma B.2, using the Lagrangian relaxation and the Karush-Kuhn-Tucker (KKT) conditions, we obtain:
$$
\begin{array}{c} f _ {x} (x, c, G, h) - A ^ {\top} y = 0 \\ A x - b = 0 \end{array} \tag {13}
$$
The implicit differentiation of these KKT conditions with respect to  $h$  allows us to get the following system of equalities:
$$
\left[ \begin{array}{c} f _ {h x} (x, c, G, h) \\ 0 \end{array} \right] + \left[ \begin{array}{c c} f _ {x x} (x, c, G, h) & - A ^ {\top} \\ A & 0 \end{array} \right] \left[ \begin{array}{c} \frac {\partial x}{\partial h} \\ \frac {\partial y}{\partial h} \end{array} \right] = 0 \tag {14}
$$
where  $H = f_{xx}$  is defined as in Lemma B.2. Since  $f(x, c, G, h) = c^\top x - \mu \sum_{i=1}^d \ln(x_i) - \mu \sum_{i=1}^q \ln(G_i x - h_i)$ , we have
$$
f _ {h _ {\ell} x _ {j}} (x) = - \mu G _ {\ell j} / \left(G _ {\ell} ^ {\top} x - h _ {\ell}\right) ^ {2}
$$
Lemma B.4. Consider the LP relaxation (7), defining  $x^{*}$  as a function of  $c, A, b, G$  and  $h$ . Then, under this definition of  $x^{*}$ ,
$$
\frac {\partial x ^ {*}}{\partial A _ {i j}} = H ^ {- 1} \left(- A ^ {\top} \left(A H ^ {- 1} A ^ {\top}\right) ^ {- 1} \left(I _ {2} x + A H ^ {- 1} I _ {1} y\right) + I _ {1} y\right)
$$
where  $I_1 = -\frac{\partial A^\top}{\partial A_{ij}}$ ,  $I_2 = \frac{\partial A}{\partial A_{ij}}$ , and  $H = f_{xx}$  is defined as in Lemma B.2.
$$
\begin{array}{c} f _ {x} (x, c, G, h) - A ^ {\top} y = 0 \\ A x - b = 0 \end{array} \tag {15}
$$
Since  $A \in \mathbb{R}^{p \times d}$ , fix  $i \in \{1, \ldots, p\}, j \in \{1, \ldots, d\}$ , the implicit differentiation of these KKT conditions with respect to  $A_{ij}$  allows us to get the following system of equalities:
$$
\left[ \begin{array}{c} - \frac {\partial A ^ {\top}}{\partial A _ {i j}} y \\ \frac {\partial A}{\partial A _ {i j}} x \end{array} \right] + \left[ \begin{array}{c c} f _ {x x} (x, c, G, h) & - A ^ {\top} \\ A & 0 \end{array} \right] \left[ \begin{array}{c} \frac {\partial x}{\partial A _ {i j}} \\ \frac {\partial y}{\partial A _ {i j}} \end{array} \right] = 0 \tag {16}
$$
Let  $I_1 = -\frac{\partial A^\top}{\partial A_{ij}}$ ,  $I_2 = \frac{\partial A}{\partial A_{ij}}$ . By solving this system of equalities, we can obtain
$$
\frac {\partial x ^ {*}}{\partial A _ {i j}} = H ^ {- 1} (- A ^ {\top} (A H ^ {- 1} A ^ {\top}) ^ {- 1} (I _ {2} x + A H ^ {- 1} I _ {1} y) + I _ {1} y)
$$
where  $H = f_{xx}$  is defined as in Lemma B.2.
Lemma B.5. Consider the LP relaxation (7), defining  $x^{*}$  as a function of  $c, A, b, G$  and  $h$ . Then, under this definition of  $x^{*}$ ,
$$
\frac {\partial x ^ {*}}{\partial b} = H ^ {- 1} A ^ {\top} \left(A H ^ {- 1} A ^ {\top}\right) ^ {- 1} I
$$
$$
\begin{array}{c} f _ {x} (x, c, G, h) - A ^ {\top} y = 0 \\ A x - b = 0 \end{array} \tag {17}
$$
The implicit differentiation of these KKT conditions with respect to  $b$  allows us to get the following system of equalities:
$$
\left[ \begin{array}{c} 0 \\ - I \end{array} \right] + \left[ \begin{array}{c c} f _ {x x} (x, c, G, h) & - A ^ {\top} \\ A & 0 \end{array} \right] \left[ \begin{array}{c} \frac {\partial x}{\partial b} \\ \frac {\partial y}{\partial b} \end{array} \right] = 0 \tag {18}
$$
C Details for Case Studies
Since the penalty function partly or solely affects the terms  $\left.\frac{\partial P Reg(\hat{\theta},\theta)}{\partial x_2^*}\right|_{x_1^*},\left.\frac{\partial P Reg(\hat{\theta},\theta)}{\partial x_1^*}\right|_{x_2^*}$ , and  $\left.\frac{\partial x_2^*}{\partial x_1^*}\right|$  we give three case studies for our framework to show how to design the penalty function and compute gradients using the corresponding penalty function.
C.1 Alloy Production Problem
We first demonstrate, using the example of the alloy production problem, how our framework can tackle problems solvable by the prior work of Hu et al. [12]. An alloy production factory needs to produce a certain amount of a particular alloy, requiring a mixture of  $M$  kinds of metals. To that end, it must acquire at least  $req_{m}$  tons of each of the  $m \in [M]$  metals. The raw materials are to be obtained from  $K$  suppliers, each supplying a different type of ore. The factory plans to buy ores from sites and then extract the metals themselves. The ore supplied by site  $k \in [K]$  contains a  $con_{km} \in [0,1]$  fraction of material  $m$  at a price of  $cost_{k}$  per ton. The goal of the factory is to meet its requirements for each metal at the minimum cost. However, the precise metal concentrations (averaged in a batch) are unknown before the factory actually completes metal extraction. The factory will estimate metal concentrations based on historical buying records, considering features such as the ore type, ore origin, site-reported preliminary samples and so on. Then the factory will decide how much ore to order from each site. This is the Stage 1 solution. The Stage 1 OP is the alloy production problem using the estimated metal concentrations  $c\hat{o}n$ , and can be formulated as follows:
$$
x _ {1} ^ {*} = \underset {x} {\arg \min } c o s t ^ {\top} x \qquad \text {s . t .} \hat {c o n} ^ {\top} x \geq r e q, x \geq 0
$$
After the factory obtains the ores and completes metal extraction, i.e., in Stage 2, the precise metal concentrations/amounts are known. Since the purchased ores are already processed, the factory cannot return ores even if it has bought too much. However, if the obtained metals do not satisfy the requirements, the factory can post-hoc decide to last-minute order more ores at a higher price, for example,  $(1 + \sigma_{k})\cos t_{k}$  per ton from the site  $k$ , where  $\sigma_{k} \geq 0$  is a non-negative tunable scalar parameter. In this scenario, the penalty function is:
$$
P e n \left(x _ {1} ^ {*} \rightarrow x\right) = \left(\sigma \circ c o s t\right) ^ {\top} \left(x - x _ {1} ^ {*}\right) \tag {19}
$$
where  $\circ$  is the Hadamard/entrywise product.
With respect to the above penalty function, we are now ready to define the Stage 2 OP:
$$
x _ {2} ^ {*} = \underset {x} {\arg \min } c o s t ^ {\top} x + (\sigma \circ c o s t) ^ {\top} (x - x _ {1} ^ {*}) \quad \text {s . t .} c o n ^ {\top} x \geq r e q, x \geq x _ {1} ^ {*} \tag {20}
$$
Note that since the precise metal concentrations  $con$  are revealed, the true concentrations are used as the problem parameters instead of the estimated concentrations. The final amount of ores bought from each site, including the ores bought in both Stage 1 and Stage 2, is the Stage 2 solution.
The above formulation is based on the "soft commitment" modelling approach discussed in Appendix A.1.
The post-hoc regret for the alloy production problem can be explicitly written as:
$$
P R e g (\hat {\theta}, \theta) = c o s t ^ {\top} x _ {2} ^ {*} + (\sigma \circ c o s t) ^ {\top} \left(x _ {2} ^ {*} - x _ {1} ^ {*}\right) - c o s t ^ {\top} x ^ {*} (c o n) \tag {21}
$$
where  $x^{*}(con)$  is an optimal solution of the alloy production problem under the true concentrations  $con$ . We now show how to compute the relevant gradients as discussed in Section 4 and Appendix B.
Using Equation (21), it is straightforward to compute that the  $i$ -th item in vector  $\left.\frac{\partial PReg(\hat{\theta},\theta)}{\partial x_2^*}\right|_{x_1^*}$  and the  $i$ -th item in vector  $\left.\frac{\partial PReg(\hat{\theta},\theta)}{\partial x_1^*}\right|_{x_2^*}:\left(\frac{\partial PReg(\hat{\theta},\theta)}{\partial x_2^*}\right|_{x_1^*}\bigg)_i = (1 + \sigma_i)\cos t_i,\left(\frac{\partial PReg(\hat{\theta},\theta)}{\partial x_1^*}\right|_{x_2^*}\bigg)_i = -\sigma_i\cos t_i.$
Now we show how to compute the approximation of the remaining term,  $\frac{\partial x_2^*}{\partial x_1^*}$ .
Approximation  $\frac{\partial x_2^*}{\partial x_1^*}$ . We use the same interior-point LP solver to help compute the relevant derivatives. First, the estimated parameters are fed into the LP solver to solve the Stage 1 OP to obtain the Stage 1 optimal solution  $x_1^*$  and the corresponding  $\mu$ , which are used to compute the term  $\frac{\partial x_1^*}{\partial\hat{\theta}}$ . Then the Stage 1 optimal solution  $x_1^*$  and the true parameters are fed into the LP solver to solve the Stage 2 OP to obtain the Stage 2 optimal solution  $x_2^*$  and the corresponding  $\mu$ , which are used to compute the term  $\frac{\partial x_2^*}{\partial x_1^*}$ . Consider the Stage 2 OP in program (20). It is clear that the Stage 2 OP is a MILP, with  $x_2^*$  in the objective and  $x_1^*$  in  $h$  of the constraints. Applying Lemma B.3, we can compute an approximate gradient of the  $\frac{\partial x_2^*}{\partial x_1^*}$  term.
C.2 Variant of 0-1 Knapsack
The second example, which we call the proxy buyer problem, is a variant of the 0-1 knapsack problem. The unknown parameters appear in both the objective and constraints. This problem, as we shall see, can be handled by our framework, but not by the prior approach by Hu et al. [12], since the problem is inherently discrete and cannot be formulated as LPs.
A proxy buyer is a person who purchases goods for others possibly for a profit. Consider a proxy buyer who is from City A, with a very high cost of living, who regularly travels to City B with a much lower cost of living. Given her regular travels, her friends in City A have asked her to help purchase everyday-life products, which are significantly cheaper in City B, yet the time and transportation cost from City A to City B makes it prohibitive for most people to just go to City B themselves. The traveller commutes between City A and City B once every three months, and has a known and limited capacity cap of goods she could carry and bring back. Before each trip, her friends would make requests for things to buy. For simplicity, one request contains one item. If the buyer brings back the item as requested, her friends will pay her  $20\%$  of the price-tag  $p_i$  of each item  $i$  as a courtesy-thankyou. We denote this "profit" by  $f_i$ , i.e.,  $f_i = 20\% p_i$ .
The buyer is popular, and many friends ask her for favours. One day before the buyer leaves for City B, the buyer needs to decide which of her friends' requests to accept, given the limited capacity, and inform them accordingly. The buyer wants to maximize the total amount of courtesy-thankyou money she gets, subject to the hard constraint of the limited suitcase capacity cap. However, the precise price  $p_i$  of each item  $i$  is unknown, due to the uncertainty of the price itself, the volatility of the exchange rate, and the uncertainty of the discount activities of the items. Thus, the "profit"  $f_i$  of buying item  $i$  is unknown. In addition, the exact size  $s_i$  of each item  $i$  is also estimated. The buyer will estimate the profit, i.e., the prices, and the sizes based on past experiences, considering features such as time-of-year, holiday-or-not, brand and so on. The buyer will decide which requests to accept based on the estimation. This is the Stage 1 solution. The Stage 1 OP is the proxy buyer problem using the estimated sizes  $\hat{s}$  and estimated profits  $\hat{f}$ :
$$
x _ {1} ^ {*} = \underset {x} {\arg \max } \hat {f} ^ {\top} x, \quad \text {s . t .} \hat {s} ^ {\top} x \leq c a p,   x \in \{0, 1 \}
$$
After the buyer arrives at City B, the buyer knows the precise price and size of each item. If she cannot carry all the accepted requests, for example, if the packaging for certain items have changed since she last bought them, the buyer will necessarily need to drop some of these requests. The buyer usually feels bad about reneging on a promise to her friends, and treats her friends to a meal as an apology if the request cannot be fulfilled after she promised. For simplicity, we assume that the price of the apology-meal is linear in the profit of the dropped request, since more expensive items are considered "more important" requests. Here, the linearity factor is independent of the request. That is, if she drops item  $i$ , she has to spend  $\sigma f_{i}$  amount of money, where  $\sigma \geq 0$  is a non-negative tunable scalar parameter. In this scenario, the penalty function is:
$$
P e n \left(x _ {1} ^ {*} \rightarrow x\right) = \sigma f ^ {\top} \left(x _ {1} ^ {*} - x\right) \tag {22}
$$
We are now ready to define the Stage 2 OP with respect to the above penalty function:
$$
x _ {2} ^ {*} = \underset {x} {\arg \max } f ^ {\top} x - \sigma f ^ {\top} \left(x _ {1} ^ {*} - x\right), \quad \text {s . t .} s ^ {\top} x \leq c a p, x \leq x _ {1} ^ {*}, x \in \{0, 1 \} \tag {23}
$$
The requests that were finally filled, namely the items that were actually bought by the buyer and brought home to City A, forms the Stage 2 solution.
Then the simplified form of the post-hoc regret for the proxy buyer problem can be written as:
$$
P R e g (\hat {\theta}, \theta) = f ^ {\top} x ^ {*} (f, s) - f ^ {\top} x _ {2} ^ {*} + \sigma f ^ {\top} \left(x _ {1} ^ {*} - x _ {2} ^ {*}\right) \tag {24}
$$
where  $x^{*}(f,s)$  is an optimal solution of the proxy buyer problem under the true proxy fees  $f$  and true sizes  $s$ .
Using Equation (24), it is straightforward to compute that the  $i$ -th item in vector  $\left.\frac{\partial PReg(\hat{\theta},\theta)}{\partial x_2^*}\right|_{x_1^*}$  and the  $i$ -th item in vector  $\left.\frac{\partial PReg(\hat{\theta},\theta)}{\partial x_1^*}\right|_{x_2^*}:\left(\frac{\partial PReg(\hat{\theta},\theta)}{\partial x_2^*}\right|_{x_1^*}\bigg)_i = (-1 - \sigma)f_i,\left(\frac{\partial PReg(\hat{\theta},\theta)}{\partial x_1^*}\right|_{x_2^*}\bigg)_i = \sigma f_i.$
Approximation  $\frac{\partial x_2^*}{\partial x_1^*}$ . Similar to the computation in Section C.1, we obtain the Stage 1 optimal solution  $x_1^*$ , the Stage 2 optimal solution  $x_2^*$ , and the corresponding  $\mu$  from the interior-point LP compute the term  $\frac{\partial x_2^*}{\partial x_1^*}$ . Consider the Stage 2 OP in program (23), it is clear that the Stage 2 OP is a MILP, with  $x_2^*$  in the objective and  $x_1^*$  in  $h$  of the constraints. Applying Lemma B.3, we can compute an approximate gradient of the  $\frac{\partial x_2^*}{\partial x_1^*}$  term.
C.3 Nurse Scheduling Problem
Our last example is the nurse scheduling problem (NSP), which can be handled by our framework but not by the prior work of Hu et al. [12] since it is neither a packing LP nor a covering LP.
Consider a large optometry center that needs to assign nurses to shifts per day to meet patients' needs. Every Monday morning, the center collects the nurses' preferences for each shift of the following week. Since nurses may have their own activities and errands during unscheduled shifts, they want to be informed of their schedules as early as possible. After the preferences are collected, on Monday night, the center sets a preliminary shift schedule for the upcoming week based on the estimated number of patients for each shift. Suppose there are  $n$  nurses,  $k$  days, and  $s$  shifts per day, then the number of the total shifts is  $t = k \times s$ . We formulate the decision variables as a Boolean vector  $x \in \{0,1\}^d$ , where  $d = n \times k \times s$ . Let  $P \in \{1,2,3,4\}^d$  represent the value of each nurse's preferences for a particular shift (the higher the number the better), and  $H \in \mathbb{N}^t$  represents the number of patients in each shift, which are unknown and need to be predicted. Each nurse  $i$  can serve  $m_i$  patients in one shift. The objective is to maximize the nurses' preferences under a set of constraints: (1) the schedule must satisfy the patient demand, under each shift (2) each nurse must be scheduled for exactly one shift each day (3) no nurse may be scheduled to work a night shift followed immediately by a morning shift. The Stage 1 OP is the NSP using the estimated number of patients  $\hat{H}$ :
$$
\begin{array}{l} x _ {1} ^ {*} = \underset {x} {\arg \max } P ^ {\top} x \\ \text {s . t .} \sum_ {i = 0} ^ {n - 1} m _ {i} x _ {i t + j} \geq \hat {H} _ {j} \quad \forall j \in \{0, \dots , t - 1 \} \\ \sum_ {q = 0} ^ {s - 1} x _ {i t + s j + q} = 1 \qquad \begin{array}{c} \forall i = \{0, \ldots , n - 1 \}, \\ j = \{0, \ldots , k - 1 \} \end{array} \\ x _ {i t + s j + s - 1} + x _ {i t + s j + s} \leq 1 \begin{array}{c} \forall i = \{0, \ldots , n - 1 \}, \\ j = \{0, \ldots , k - 2 \} \end{array} \\ x \in \{0, 1 \} \\ \end{array}
$$
To provide better service to patients, the optometry center has implemented an appointment system that requires patients to schedule an appointment in advance to receive medical care. Reservations for the upcoming week, from Monday to Sunday, close every Sunday evening. At this point, the center knows the precise number of patients for each shift of the next week. The center might adjust the shift schedule to satisfy the actual patient demand or to improve the overall nurse preferences. However, due to the late notice for schedule changes, the nurse's preference may become lower. For example, if a nurse is rescheduled to a shift for which her original preference is 5, now her preference for this shift may become 4 due to the late notice. Besides, a nurse may be more unhappy to be changed to
a low-preference shift. In this scenario, since the nurses' preferences are in  $\{1,2,3,4\}$ , the penalty function can be formulated as:
$$
P e n \left(x _ {1} ^ {*} \rightarrow x\right) = \sum_ {i = 0} ^ {d - 1} P e n \left(x _ {1} ^ {*} \rightarrow x\right) _ {i} \tag {25}
$$
where the  $i$ -th item in the penalty function is:
$$
P e n (x _ {1} ^ {*} \to x) _ {i} = \left\{ \begin{array}{l l} \gamma_ {i} (5 - P _ {i}) ^ {2} (x _ {i} - x _ {1 i} ^ {*}) & x _ {i} \geq x _ {1 i} ^ {*} \\ 0 & x _ {i} <   x _ {1 i} ^ {*} \end{array} \right.
$$
$$
\begin{array}{l} x _ {2} ^ {*} = \underset {x} {\arg \max } P ^ {\top} x - \sum_ {i = 0} ^ {d - 1} P e n (x _ {1} ^ {*} \to x) _ {i} \\ \text {s . t .} \sum_ {i = 0} ^ {n - 1} m _ {i} x _ {i t + j} \geq H _ {j} \quad \forall j \in \{0, \dots , t - 1 \} \\ \sum_ {q = 0} ^ {s - 1} x _ {i t + s j + q} = 1 \qquad \begin{array}{c} \forall i = \{0, \ldots , n - 1 \}, \\ j = \{0, \ldots , k - 1 \} \end{array} \\ x _ {i t + s j + s - 1} + x _ {i t + s j + s} \leq 1 \begin{array}{c} \forall i = \{0, \ldots , n - 1 \}, \\ j = \{0, \ldots , k - 2 \} \end{array} \\ x \in \{0, 1 \} \\ \end{array}
$$
Then the simplified form of the post-hoc regret for the NSP can be written as:
$$
P R e g (\hat {\theta}, \theta) = P ^ {\top} x ^ {*} (H) - P ^ {\top} x _ {2} ^ {*} + \sum_ {i = 0} ^ {d - 1} P e n \left(x _ {1} ^ {*} \rightarrow x _ {2} ^ {*}\right) _ {i} \tag {26}
$$
Using Equation (26), it is straightforward to compute that the  $i$ -th item in vector  $\left.\frac{\partial P Reg(\hat{\theta},\theta)}{\partial x_2^*}\right|_{x_1^*}$  and the  $i$ -th item in vector  $\left.\frac{\partial P Reg(\hat{\theta},\theta)}{\partial x_1^*}\right|_{x_2^*}$ :
$$
\left(\frac{\partial P R e g(\hat{\theta},\theta)}{\partial x_{2}^{*}}\bigg|_{x_{1}^{*}}\right)_{i} = \left\{ \begin{array}{ll} - P_{i} + 2\gamma_{i}(5 - P_{i}) & x_{2i}^{*}\geq x_{1i}^{*}\\ -P_{i} & x_{2i}^{*} <   x_{1i}^{*} \end{array} \right.
$$
$$
\left(\frac{\partial P R e g(\hat{\theta},\theta)}{\partial x_{1}^{*}}\bigg|_{x_{2}^{*}}\right)_{i} = \left\{ \begin{array}{ll} - 2\gamma_{i}(5 - P_{i}) & x_{2i}^{*}\geq x_{1i}^{*}\\ 0 & x_{2i}^{*} <   x_{1i}^{*} \end{array} \right.
$$
Approximation  $\frac{\partial x_2^*}{\partial x_1^*}$ . Similar to the computation in Section C.1, we obtain the Stage 1 optimal solution  $x_1^*$ , the Stage 2 optimal solution  $x_2^*$ , and the corresponding  $\mu$  from the interior-point LP compute the term  $\frac{\partial x_2^*}{\partial x_1^*}$ . Using the penalty function in Equation (25), the Stage 2 OP can be formulated
as a MILP by adding new variables  $\sigma$  and one more constraint:
$$
x _ {2} ^ {*} = \underset {x} {\arg \max } P ^ {\top} x - \sum_ {i = 0} ^ {d - 1} \gamma_ {i} (5 - P _ {i}) ^ {2} \sigma_ {i}
$$
s.t.  $\sum_{i = 0}^{n - 1}m_i x_{it + j}\geq H_j\quad \forall j\in \{0,\dots ,t - 1\}$
$$
\sum_ {q = 0} ^ {s - 1} x _ {i t + s j + q} = 1 \quad \begin{array}{c} \forall i = \{0, \ldots , n - 1 \}, \\ j = \{0, \ldots , k - 1 \} \end{array}
$$
$$
x _ {i t + s j + s - 1} + x _ {i t + s j + s} \leq 1 \quad \begin{array}{c} \forall i = \{0, \ldots , n - 1 \}, \\ j = \{0, \ldots , k - 2 \} \end{array}
$$
$$
\sigma_ {i} \geq x _ {i} - x _ {1 i} ^ {*} \quad \forall i = \{0, \dots , d - 1 \}
$$
$$
x \in \{0, 1 \}
$$
$$
\sigma \in \{0, 1 \}
$$
Suppose the Stage 2 OP of the NSP can be written as:
$$
x _ {2} ^ {*} = \underset {x} {\arg \min } - P ^ {\top} x + (\gamma \circ (5 - P) ^ {2}) ^ {\top} \sigma
$$
$$
\mathrm {s . t .} G _ {1} x \geq H
$$
$$
A x = b
$$
$$
G _ {2} x \geq - 1
$$
$$
\sigma - x \geq - x _ {1} ^ {*}
$$
$$
x, \sigma \in \{0, 1 \}
$$
Then the standard form of the Stage 2 OP is:
$$
x _ {2} ^ {\prime} = \underset {x ^ {\prime}} {\arg \min } c ^ {\top} x ^ {\prime}
$$
$$
\mathrm {s . t .} A ^ {\prime} x ^ {\prime} = b
$$
$$
G x \geq h
$$
$$
x ^ {\prime} \in \{0, 1 \}
$$
$$
c = \left[ \begin{array}{c c} - P & \gamma \circ (5 - P) ^ {2} \end{array} \right] \in \mathbb {R} ^ {2 d}, \quad x ^ {\prime} = [ x \quad \sigma ] \in \mathbb {R} ^ {2 d}
$$
$$
G = \left[ \begin{array}{c c} G _ {1} & 0 \\ G _ {2} & 0 \\ - I & I \end{array} \right] \in \mathbb {R} ^ {(t + n k - n + d) \times 2 d}, \quad h = \left[ \begin{array}{c} H \\ - 1 \\ - x _ {1} ^ {*} \end{array} \right] \in \mathbb {R} ^ {t + n k - n + d}
$$
$$
A ^ {\prime} = \left[ \begin{array}{l l} A & 0 \end{array} \right] \in \mathbb {R} ^ {n k \times 2 d}
$$
and  $b\in \mathbb{R}^{nk}$  is an all-ones vector.
It is clear that  $x_2^*$  is in the objective and  $x_1^*$  is in  $h$  of the constraints. Applying Lemma B.3, we can compute an approximate gradient of the  $\frac{\partial x_2^*}{\partial x_1^*}$  term.
D Hyperparameters for the Experiments
The methods of  $k$ -NN, RF, NN, and IntOpt-C as well as 2S have hyperparameters, which we tune via cross-validation: for  $k$ -NN, we try  $k \in \{1,3,5\}$ ; for RF, we try different numbers of trees in the forest \{10,50,100\}; for NN, IntOpt-C, and 2S, we treat the learning rate, epochs and weight decay as hyperparameters.
Tables 7, 8, and 9 show the final hyperparameter choices for the three problems: 1) an alloy production problem, 2) the classic 0-1 knapsack problem, and 3) a nurse roster scheduling problem.
Table 7: Hyperparameters of the experiments on the alloy production problem.
Model	Hyperparameters
Proposed	optimizer: optim.Adam; learning rate: 5 × 10-7; μ = 10-3; epochs=20
k-NN	k=5
RF	n_estimator=100
NN	optimizer: optim.Adam; learning rate: 10-3; epochs=20