1 Introduction

In many real-world optimization problems, more than one decision-maker is involved. Often, decisions are taken in a hierarchical order: the first actor takes a decision that determines the feasible set and objective function of the second actor, whose decision in turn may influence the objective value of the first actor. Formally, such problems may be modeled as bilevel optimization problems, where the problem solved by the first actor is called the upper level problem and the one of the second actor the lower level problem. When such bilevel problems are considered from a game-theoretic perspective, the two decision-makers are often called leader and follower, a terminology we use throughout this paper. Typical applications of bilevel optimization arise when the general rules of a system (e.g., an energy market or a transport system) are determined by one actor (e.g., some regulatory commission or some large logistics company), while the other actors (e.g., energy producers or subcontractors) try to optimize their own objectives within the rules of the system. For general introductions to bilevel optimization, we refer to [5, 7, 8].

Bilevel optimization problems often turn out to be NP-hard. This is the case, in general, even when all constraints and objective functions are linear [11]. A notable exception is the bilevel continuous knapsack problem [8]: here, the leader controls the capacity of the knapsack, while the follower chooses a feasible packing maximizing his own profit. The leader’s aim is to optimize an objective function that is linear in the chosen capacity and in the follower’s chosen solution. However, the leader’s item values may differ from the follower’s item values. This problem can be solved efficiently by first sorting the items according to the follower’s profits and then enumerating the capacities corresponding to the total size of each prefix in this ordering; see Sect. 2.1 for more details. Applications of the bilevel knapsack problem considered here arise in, e.g., revenue management [1].

In practice, however, it is very likely that the leader does not know the follower’s subproblem exactly. It is thus natural to combine bilevel optimization with optimization under uncertainty. To the best of our knowledge, uncertain bilevel optimization problems were first considered in [15]. Recently, Burtscheidt and Claus [4] investigated stochastic bilevel linear optimization problems, dealing in particular with structural properties of such problems. A thorough review of literature on stochastic bilevel linear optimization can be found in [12].

Regarding the bilevel continuous knapsack problem under uncertainty, the robust optimization approach has been investigated in depth in [2]. It is assumed that the vector of follower’s item values is unknown to the leader. This implies that the follower’s order of preference for the items is now uncertain. However, according to the robust optimization paradigm, the leader knows a so-called uncertainty set containing all possible (or likely) realizations of this vector. The aim is to find a capacity leading to an optimal worst-case objective value over all these realizations. Among other things, it is shown that the resulting problem is still tractable under discrete or interval uncertainty—the latter case being nontrivial here, while it turns out to be NP-hard for budgeted uncertainty (which is sometimes called Gamma uncertainty) and for ellipsoidal uncertainty, among others. Complexity questions for general robust bilevel optimization problems have been settled in [3].

In the following, we consider the stochastic bilevel continuous knapsack problem. The follower’s item values are still unknown to the leader, but now given by probability distributions. Instead of the worst case, we are interested in optimizing the expected value. The problem can be written as:

where b denotes the capacity determined by the leader and \(x\in [0,1]^n\) are the optimization variables of the follower. As \(\mathbf {c}\) is a random vector in the stochastic setting, the same is true for the follower’s optimum solution \(x^\mathbf {c}\) and the leader’s objective value \(d^\top x^\mathbf {c}-\delta b\). In the latter, the vector d contains the leader’s item values and \(\delta \) denotes the cost for each unit of capacity provided by the leader. The leader’s aim is now to optimize the expected objective value. For the sake of simplicity, we do not distinguish between the optimistic and the pessimistic view (which are the two standard ways to handle ambiguous follower’s optimal solutions) in this formulation. In Sect. 2.2, we argue why we may assume uniqueness of the follower’s optimal solution almost surely in the stochastic setting. Therefore, the results presented in this paper hold in both the optimistic and the pessimistic setting.

1.1 Outline and Overview of Results

After discussing the deterministic problem version and introducing notation and basic results in Sect. 2, we start investigating the computational complexity of the stochastic optimization problem (SP), which of course depends strongly on the underlying probability distribution of \(\mathbf {c}\). Under the assumption that all possible realizations of the follower’s objective vector are given explicitly as part of the input, together with their probabilities, we observe that the stochastic problem can be solved efficiently; see Sect. 3. Using standard methods, this result could be used to design a sample average approximation scheme for arbitrary distributions.

Our main results apply to the case of independently distributed item values. In the most basic setting, each item value is distributed uniformly on either a finite set or an interval. In contrast to the setting of Sect. 3, in the discrete case, the input here contains the finite sets for all items, but not each of the (exponentially many) possible realizations explicitly. Even in this basic setting of independently and uniformly distributed item values, we show that the stochastic problem turns out to be #P-hard; see Sect. 4.1. It is thus unlikely that an efficient algorithm exists for solving the problem exactly. In fact, even the computation of the objective value resulting from a given capacity choice is #P-hard in these cases, and the same is true for finding a multiplicative approximation for any desired factor. However, all results only show weak #P-hardness. In fact, we also devise a pseudo-polynomial algorithm for the mentioned cases in Sect. 4.2, running in time linear in the total size of all items.

Finally, in Sect. 5, we consider general distributions with independent item values, given only by oracles for the cumulative distribution functions and the quantile functions. Assuming that these oracles can be queried in constant time, we devise an algorithm for solving (SP) with an arbitrarily small additive error \(\varepsilon >0\). The running time of this algorithm is pseudo-polynomial in the problem data and linear in \(\nicefrac 1{\varepsilon }\). The idea of this approach is to approximate the given distribution by a componentwise discrete distribution and then to apply the main ideas used for the pseudo-polynomial algorithm of Sect. 4.2.

In Sect. 6, we summarize the main results and close the paper with a few remarks and a discussion of related questions.

2 Preliminaries

We start with basic observations concerning the stochastic bilevel continuous knapsack problem. We first have a closer look at the deterministic problem variant in Sect. 2.1. Subsequently, in Sect. 2.2, we introduce notation and list some basic observations concerning the stochastic problem (SP).

2.1 The Underlying Certain Problem

As mentioned in the introduction, the deterministic version of the bilevel continuous knapsack problem can be solved efficiently. This is explained in [8], but for the convenience of the reader and since our algorithms for the stochastic case build on this, we now describe the solution approach in more detail. The deterministic bilevel continuous knapsack problem can be formulated as follows, using the same notation as in the stochastic problem (SP):

The leader’s only variable is \(b \in \mathbb {R}\), which can be considered the knapsack’s capacity. The follower’s variables are \(x \in \mathbb {R}^n\), i.e., the follower fills the knapsack with a subset of the objects, where also fractions are allowed. The item sizes \(a \in \mathbb {R}_{\ge 0}^n\), the follower’s item values \(c \in \mathbb {R}^n\), the capacity bounds \(b^-, b^+ \in \mathbb {R}_{\ge 0}\) as well as the leader’s item values \(d \in \mathbb {R}^n\) and a scalar \(\delta \ge 0\) are given. The latter can be thought of as a price the leader has to pay for providing one unit of knapsack capacity. For the following, we define \(A:=\sum _{i=1}^n a_i\) and assume that \(a>0\) and \(0 \le b^- \le b^+ \le A\). Moreover, since we are mostly interested in complexity results, we assume throughout that \(a\in \mathbb {N}^n\) and \(d\in \mathbb {Z}^n\). Finally, we will use the notation \([k]:=\{1,\dots ,k\}\) for \(k\in \mathbb {N}\) and \([0] := \emptyset \).

As usual in bilevel optimization, we have to be careful in case the follower’s optimal solution is not unique. In this case, the model (P) is not well defined. The standard approach is to distinguish between the optimistic setting, in which the follower always chooses one of his optimal solutions that is best possible for the leader, and the pessimistic setting, where the follower chooses an optimal solution that is worst possible for the leader. The former case is equivalent to considering the follower’s variables x being under the leader’s control as well. However, regarding the results presented in this paper, there are no relevant discrepancies between the two cases. For the sake of simplicity and since we can also make this assumption almost surely in the stochastic setting later on (see Sect. 2.2), we assume in this section that the follower’s profits \(\frac{c_i}{a_i}\), \(i\in [n]\), are pairwise distinct and nonzero, so that his optimal solution is unique for any capacity b.

Indeed, the follower in (P) solves a continuous knapsack problem with fixed capacity b. This can be done, for example, using Dantzig’s algorithm [6]: by first sorting the items, we may assume

$$\begin{aligned} \frac{c_1}{a_1}> \dots> \frac{c_{n'}}{a_{n'}}> 0> \frac{c_{n'+1}}{a_{n'+1}}> \dots > \frac{c_n}{a_n}, \end{aligned}$$
(1)

for some \(n'\in \{0, \dots , n\}\). The idea is then to pack all items with positive profit into the knapsack, in this order, until it is full. More formally, if \(A' :=\sum _{i=1}^{n'}a_i\le b\), all items with positive profit can be taken, so an optimum solution is \(x_i = 1\) for \(i \in [n']\) and \(x_i=0\) else. Otherwise, we consider the critical item

$$\begin{aligned} \textstyle k := \min \left\{ i \in [n'] :\sum _{j = 1}^i a_j > b\right\} , \end{aligned}$$

and an optimum solution is given by

$$\begin{aligned} x_i:={\left\{ \begin{array}{ll}\begin{array}{ll} 1 &{}\quad \text { for }i \in \{1, \dots , k - 1\}\\ \tfrac{1}{a_k}\left( b - \sum _{j = 1}^{k - 1} a_j\right) &{}\quad \text { for }i=k\\ 0 &{}\quad \text { for }i \in \{k+1, \dots , n\}. \end{array}\end{array}\right. } \end{aligned}$$
(2)

We now turn to the leader’s perspective. As only the critical item k, but not the ordering (1) depends on b, the leader can compute the described order of items once and then consider the behavior of the follower’s optimum solution x when b changes. Every \(x_i\) in (2) is a continuous piecewise linear function in b, of the form:

$$\begin{aligned} x_i(b):={\left\{ \begin{array}{ll} 0 &{}\quad \text { for }b \in \big [0, \sum _{j=1}^{i-1} a_j\big ]\\ \tfrac{1}{a_i}\left( b - \sum _{j = 1}^{i - 1} a_j\right) &{}\quad \text { for }b \in \big [\sum _{j=1}^{i-1} a_j, \sum _{j=1}^{i} a_j\big ]\\ 1 &{}\quad \text { for }b \in \big [\sum _{j=1}^{i} a_j, A\big ] \end{array}\right. } \end{aligned}$$
(3)

for \(b \in [0, A]\) and for \(i\in [n']\), and constantly zero for \(i>n'\). The leader’s objective function f is given by the corresponding values \(d^\top x(b)-\delta b\) and thus corresponds to a weighted sum of the functions \(x_i(b)\) for \(i \in [n']\) and \(\delta b\):

$$\begin{aligned} f(b) = {\left\{ \begin{array}{ll} \sum _{j = 1}^{i - 1} d_j + \frac{d_i}{a_i}\left( b - \sum _{j = 1}^{i - 1} a_j\right) -\delta b &{}\quad \text {for }\,b\in [\sum _{j = 1}^{i - 1} a_j,\sum _{j = 1}^{i} a_j],\\ &{}\quad i\in [n']\\ \sum _{j = 1}^{n'} d_j-\delta b &{}\quad \text {for }\,b\in [A',A]. \end{array}\right. } \end{aligned}$$
(4)

Note that this piecewise linear function is well-defined and continuous with vertices in the points \(b = \sum _{j = 1}^i a_j\), \(i\in [n']\), in which the critical item changes from i to \(i + 1\). The leader has to maximize f over the range \([b^-, b^+] \subseteq [0, A]\). As f is piecewise linear, it suffices to evaluate it at the boundary points \(b^-\) and \(b^+\) and at all feasible vertices, i.e., at all points \(b = \sum _{j = 1}^i a_j\) for \(i \in [n']\) such that \(b\in [b^-,b^+]\). By computing f(b) incrementally, Problem (P) can be solved in \(\mathcal {O}(n \log n)\) time, which is the time needed for sorting.

2.2 Basic Definitions and Observations

In the stochastic version of the problem, the vector \(\mathbf {c}\) of follower’s item values is seen as a random variable having a known distribution. The follower’s optimum solution \(x^\mathbf {c}(b)\) and the leader’s objective value \(f^\mathbf {c}(b)=d^\top x^\mathbf {c}(b)-\delta b\) depend on the realization of \(\mathbf {c}\) and hence are also random variables. The leader optimizes the expected value \(\mathbb {E}_\mathbf {c}(f^\mathbf {c}(b))\).

If two different items have the same profit or an item has profit zero, the follower’s optimal solution might be ambiguous. For simplicity, we assume throughout this paper that the profits of two different items almost surely disagree and that the profit of each item is almost surely nonzero, i.e.,

$$\begin{aligned} \mathbb {P}(\mathbf {c}_i/a_i=\mathbf {c}_j/a_j)=0 \quad \text {and} \quad \mathbb {P}(\mathbf {c}_i = 0) = 0 \quad \text {for } i,j \in [n], i\ne j. \end{aligned}$$
(5)

If \(\mathbf {c}\) follows a continuous distribution, i.e., its cumulative distribution function is continuous, this assumption is always satisfied. In case of a discrete distribution with finite support, it can be obtained, if necessary, by a small perturbation of the entries in the support of \(\mathbf {c}\). Using an appropriate perturbation, both the optimistic and the pessimistic setting can be modeled. In particular, we do not need to distinguish between these two settings in the following because under Assumption (5), the follower’s optimal solution is almost surely unique.

For fixed c, we have seen in Sect. 2.1 that \(x^c_i\) for \(i \in [n]\) and \(f^c\) are piecewise linear functions in b. These functions do not depend on c directly, but only on the implied order of the items when the latter are sorted according to the values \(c_i / a_i\). Hence, the expected values

$$\begin{aligned} \hat{x}_i(b)&:= \mathbb {E}_\mathbf {c}(x^\mathbf {c}_i(b)) \text { for } i \in [n] \text { and } \end{aligned}$$
(6)
$$\begin{aligned} {\hat{f}}(b)&:= \mathbb {E}_\mathbf {c}(f^\mathbf {c}(b)) = d^\top \hat{x}(b)-\delta b \end{aligned}$$
(7)

can be seen as expected values with respect to a probability distribution on all permutations of the items \(1, \dots , n\). As the number of permutations is finite, this implies that the functions \(\hat{x}_i\) and \({\hat{f}}\) are finite convex combinations of functions \(x^c_i\) and \(f^c\), respectively, for appropriate values of c. In particular, they are piecewise linear functions again. Since we assume the item sizes a to be integral, the vertices of these functions all lie on integer points \(b \in \{0, \dots , A\}\) because this holds for the functions defined in (3) and (4).

This gives rise to a general algorithmic scheme for solving the stochastic problem (SP): enumerate all permutations \(\pi \) of \([n]\) and compute the corresponding leader’s objective functions \(f^\pi \) as in (4), together with the probabilities \(p_\pi \) that the values \(\mathbf {c}_i / a_i\) are sorted decreasingly when permuted according to \(\pi \). Finally, sum all piecewise linear functions \(p_\pi f^\pi \) to determine the leader’s objective \({\hat{f}}\), and maximize \({\hat{f}}\) over \(b \in [b^-, b^+]\).

We emphasize that, depending on the given probability distribution of \(\mathbf {c}\), it might be nontrivial to compute the probabilities \(p_\pi \) in general. Moreover, due to the exponential number of permutations, this approach does not yield a polynomial time algorithm in general. In fact, we will show that such an efficient algorithm cannot exist for some probability distributions unless P \(=\) NP. However, for distributions with finite support, enumerating all values in the support yields an efficient algorithm, as we show in the next section. Although the above algorithm is not efficient for other distributions, it will be useful for our proofs to know the structure of the follower’s optimum solutions and the leader’s objective function as described above.

Besides the piecewise linear functions defined in (6) and (7), we will also make use of the values

$$\begin{aligned} {\Delta \hat{x}_i(b)}&:= \hat{x}_i(b) - \hat{x}_i(b - 1) \text { for } i \in [n] \text { and } \end{aligned}$$
(8)
$$\begin{aligned} {\hat{f}}'(b)&:= {\hat{f}}(b) - {\hat{f}}(b-1) = d^\top \Delta \hat{x}(b)-\delta \end{aligned}$$
(9)

for \(b \in [A]\). The values \(\Delta \hat{x}_i(b)\) describe the expected amount of item i that will be added when increasing the capacity from \(b-1\) to b. Together with \(\delta \) and the leader’s item values d, they yield the slope \({\hat{f}}'\) of the leader’s objective function. Note that, by integrality of a, the functions \(\hat{x}_i\) and \({\hat{f}}\) are linear on \([b-1,b]\). Whenever we deal with slopes of piecewise linear functions, in a point where the function is nondifferentiable, this refers to the slope of the linear piece directly left of this point, i.e., we always consider left derivatives.

For some probability distributions, it will turn out that not only the optimization in (SP), but also the computation of the values \(\hat{x}_i(b)\) and \(\Delta \hat{x}_i(b)\) is hard in general. However, we will devise pseudo-polynomial time algorithms in these cases that compute all values \(\Delta \hat{x}_i(b)\), from which one can solve (SP) in pseudo-polynomial time as well; see Sect. 4.2.

3 Distributions with Finite Support

Assuming that \(\mathbf {c}\) has a finite support U, i.e., that there exists a finite set U of possible follower’s objectives c which occur with probabilities \(0 < p_c \le 1\), respectively, the leader’s objective is given as a finite sum of the piecewise linear functions \(p_cf^c\), where \(f^c\) is defined as in (4). Note that the definition in (4) depends on the order of the items given by the follower’s preferences, which in turn depends on c.

Similar to the algorithm described in Sect. 2.2, the following algorithm solves Problem (SP) for distributions with finite support: for every \(c \in U\), use the algorithm described in Sect. 2.1 to compute the piecewise linear function \(f^c\) in \(\mathcal {O}(n \log n)\) time, and multiply each function \(f^c\) by the factor \(p_c\). Then, maximize the resulting weighted sum, which is a piecewise linear function again. Note that the sum has \(\mathcal {O}(|U|n)\) linear segments and that it can be computed by sorting the vertices of all functions and traversing them from left to right while keeping track of the sum of the active linear pieces. This is possible in a running time of \(\mathcal {O}(|U| n \log (|U| n))\). Thus, we obtain

Theorem 1

Assume that \(\mathbf {c}\) is distributed on a finite set U and that the input consists of U together with the corresponding probabilities. Then, Problem (SP) can be solved in \(\mathcal {O}(|U| n \log (|U| n))\) time.

The result of Theorem 1 suggests to address the general problem (SP), with an arbitrary underlying distribution of \(\mathbf {c}\), by means of sample average approximation: for a given number \(N\in \mathbb {N}\), first compute N samples \(c^{(1)},\dots ,c^{(N)}\) of the random variable \(\mathbf {c}\). Then, apply the algorithm of Theorem 1 to the uniform distribution over the finite set \(\{c^{(1)},\dots ,c^{(N)}\}\) and let \(\vartheta _N\) be the resulting optimal value (which is a random variable again). Using general results from [16], one can show that \(\vartheta _N\) almost surely converges to the optimal value of (SP) for \(N\rightarrow \infty \), and a similar statement holds for the set of optimal solutions; see [17]. The only assumption needed here is that sampling of \(\mathbf {c}\) is possible.

4 Componentwise Uniform Distributions

In this section, we consider the version of (SP) where the distribution of \(\mathbf {c}\) is uniform on a product of either finite sets or continuous intervals. Equivalently, each component of \(\mathbf {c}\) is drawn independently and according to some (discrete or continuous) uniform distribution. For both the discrete and the continuous case, we will show that (SP) cannot be solved efficiently unless P \(=\) NP. However, we will devise pseudo-polynomial time algorithms with a running time linear in the total item size A. The algorithm for the discrete case solves the problem not only for uniform, but also for arbitrary componentwise distributions with finite support.

Note that the results presented in Sect. 3 are not applicable to the discrete independent case discussed here because the support U, which contains all possible combinations of item values, is exponential in the number of items and hence in the problem input.

4.1 Hardness Results

Our first aim is to show that (SP) is #P-hard in case of componentwise uniform distributions. The class #P contains all counting problems associated with decision problems belonging to NP, or, more formally, all problems that ask for computing the number of accepting paths in a polynomial time nondeterministic Turing machine. Using a natural concept of efficient reduction for counting problems, one can define a counting problem to be #P-hard if every problem in #P can be reduced to it. A polynomial time algorithm for a #P-hard counting problem can only exist if P \(=\) NP. In the following proofs, we will use the #P-hardness of the problem #Knapsack, which asks for the number of feasible solutions of a given binary knapsack instance [9].

In stochastic optimization with continuous distributions, problems often turn out to be #P-hard, and this is often even true for the evaluation of objective functions containing expected values. For an example, see [10], from where we also borrowed some ideas for the following proofs.

Theorem 2

Problem (SP) with a discrete componentwise uniform distribution of \(\mathbf {c}\) is #P-hard.

Proof

We show the result by a reduction from #Knapsack. More precisely, for some given \(a^* \in \mathbb {N}^m\) and \(b^*\in \{0,1,\dots , \sum _{i = 1}^m a_i^*\}\), we will prove that one can compute

$$\begin{aligned} \#\{x \in \{0, 1\}^m :{a^*}^\top x \le b^*\} \end{aligned}$$

in polynomial time if the following instances of (SP) can be solved in polynomial time. In case \(b^* = \sum _{i = 1}^m a_i^*\), this is clear, so from now on, we assume that \(b^* < \sum _{i = 1}^m a_i^*\).

We define a family of instances of (SP), parameterized by \(\tau \in [-1, 1]\): each of the instances has \(n := m + 1\) items, where

$$\begin{aligned} (a_1, \dots , a_m, a_{m + 1}):= & {} (a_1^*, \dots , a_m^*,\textstyle \sum _{i = 1}^m a_i^*) \text { and}\\ (d_1, \dots , d_m, d_{m + 1}):= & {} ((1 +\tau ) \cdot a_1, \dots , (1 + \tau ) \cdot a_m, (-1 + \tau ) \cdot a_{m + 1}). \end{aligned}$$

We set \(\delta := 0\), \(b^- := 0\) and \(b^+ := a_{m + 1} = \sum _{i = 1}^m a_i\), and assume

$$\begin{aligned} (\mathbf {c}_1, \dots , \mathbf {c}_{m + 1}) \sim \mathcal {U}\{\varepsilon , 1\}^{m + 1} \end{aligned}$$

with

$$\begin{aligned} \varepsilon := \tfrac{1}{2 a_{m + 1}}>0. \end{aligned}$$

The proof consists of two main steps. First, we investigate the structure of the leader’s objective functions for the described instances and show that by determining the slope of any of them at \(b = b^*\), up to a certain precision, we can compute

$$\begin{aligned} \#\{x \in \{0, 1\}^m :{a^*}^\top x \le b^*\}. \end{aligned}$$

In the second step, we show how to determine this slope up to the required precision by solving a polynomial number of these instances in a bisection algorithm.

As described in Sect. 2.2, the leader’s objective function can be thought of as a weighted sum of piecewise linear functions corresponding to the permutations induced by different choices of c, with weights being the probabilities of the permutations, respectively. For fixed c, consider the set

$$\begin{aligned} I_c := \left\{ i \in [m] \mid \tfrac{c_i}{a_i} > \tfrac{c_{m + 1}}{a_{m + 1}}\right\} \end{aligned}$$

of items the follower would choose before item \(m + 1\). The corresponding piecewise linear function \(f^c\) first has slope \(1 + \tau \) and then slope \(-1 + \tau \), since \(\frac{d_i}{a_i} = 1 + \tau \) for all \(i \in [m]\), and \(\frac{d_{m + 1}}{a_{m + 1}} = -1 + \tau \). The order of the items in \(I_c\) does not matter to the leader because they all result in the same slope in her objective. The slope changes from \(1 + \tau \) to \(-1 + \tau \) at \(b = \sum _{i \in I_c} a_i\). The slope would change back to \(1 + \tau \) at \(b = \sum _{i \in I_c} a_i + a_{m + 1} \ge b^+\), but this is outside of the range of the leader’s objective.

The actual leader’s objective is now a weighted sum of such functions. For obtaining the weights, we only need to know the probabilities for different sets \(I_\mathbf {c}\), because all c resulting in the same \(I_c\) also result in the same piecewise linear function \(f^c\). The probability distribution is chosen such that \(I_\mathbf {c}= [m]\) occurs with probability \(\tfrac{1}{2} + \tfrac{1}{2^{m + 1}}\), while each other set \(I_\mathbf {c}\subset [m]\) has probability \(\tfrac{1}{2^{m + 1}}\): first, if \(\mathbf {c}_{m + 1} = \varepsilon \), we certainly have \(I_\mathbf {c}= [m]\) because \(\tfrac{\mathbf {c}_i}{a_i} \ge \tfrac{\varepsilon }{a_i} > \tfrac{\varepsilon }{a_{m + 1}}\) holds with probability 1, for all \(i \in [m]\). On the other hand, if \(\mathbf {c}_{m + 1} = 1\), then each item \(i \in [m]\) is contained in \(I_{\mathbf {c}}\) with probability exactly \(\tfrac{1}{2}\). Indeed, \(\mathbf {c}_i = 1\) means \(\tfrac{\mathbf {c}_i}{a_i} = \tfrac{1}{a_i} > \tfrac{1}{a_{m + 1}}\), hence \(i \in I_\mathbf {c}\), whereas \(\mathbf {c}_i = \varepsilon \) means \(\tfrac{\mathbf {c}_i}{a_i} = \tfrac{\varepsilon }{a_i} \le \tfrac{1}{2 a_{m + 1}} < \tfrac{1}{a_{m + 1}}\), hence \(i \notin I_\mathbf {c}\). Thus, the leader’s objective function \({\hat{f}}_\tau \) is given as:

$$\begin{aligned} {\hat{f}}_\tau = \frac{1}{2} f_{[m], \tau } + \frac{1}{2^{m + 1}} \sum _{M \subseteq [m]} f_{M, \tau }, \end{aligned}$$

where \(f_{M, \tau }\) is the function that has slope \(1 + \tau \) for \(b \in [0, \sum _{i \in M} a_i]\) and slope \(-1 + \tau \) afterward. It follows that, for any \(b \in [b^+]\),

$$\begin{aligned} {\hat{f}}_\tau '(b)= & {} \frac{1}{2} (1 + \tau ) + \frac{1}{2^{m + 1}}\Bigg ((-1 + \tau ) \cdot \#\Big \{M \subseteq [m] :\sum _{i \in M} a_i < b\Big \} \nonumber \\&+\, (1 + \tau ) \cdot \#\Big \{M \subseteq [m] :\sum _{i \in M} a_i \ge b\Big \}\Bigg ) \nonumber \\= & {} -\frac{1}{2^m}\#\Big \{M \subseteq [m] :\sum _{i \in M} a_i \le b - 1\Big \} + 1 + \tau \nonumber \\= & {} -\frac{1}{2^m}\#\Big \{x \in \{0, 1\}^m :a^\top x \le b - 1\Big \} + 1 + \tau . \end{aligned}$$
(10)

This shows that by computing \({\hat{f}}_\tau '(b^* + 1)\) for any fixed \(\tau \), we can determine the number

$$\begin{aligned} \#\{x \in \{0, 1\}^m :{a^*}^\top x\le b^*\} = 2^m(1 + \tau - {\hat{f}}_\tau '(b^* + 1)). \end{aligned}$$

It is even enough to compute an interval of length less than \(\frac{1}{2^m}\) containing \({\hat{f}}_\tau '(b^* + 1)\) because the number of feasible knapsack solutions is an integer and this gives an interval of length less than 1 in which it must lie. This concludes the first step of our proof.

In the second step, we will describe a bisection algorithm to compute \({\hat{f}}_0'(b^* + 1)\) up to the required precision. We know that \({\hat{f}}_0'(b^* + 1) \in [-1,1]\) as it is a convex combination of values \(-1\) and 1. Starting with \(s_0^- := -1\) and \(s_0^+ := 1\), we iteratively halve the length of the interval \([s_k^-,s_k^+]\) by setting either \(s_{k + 1}^- := s_k^-\) and \(s_{k + 1}^+ := \tfrac{1}{2}(s_k^- + s_k^+)\) or \(s_{k + 1}^- := \tfrac{1}{2}(s_k^- + s_k^+)\) and \(s_{k + 1}^+ := s_k^+\). After \(m + 2\) iterations, we have an interval of length \(\frac{1}{2^{m + 1}}\) containing \({\hat{f}}_0'(b^* + 1)\), which allows to compute \(\#\{x \in \{0, 1\}^m :{a^*}^\top x \le b^*\}\).

It remains to show how to determine whether \({\hat{f}}_0'(b^* + 1)\le \tfrac{1}{2}(s_k^- + s_k^+)\) or \({\hat{f}}_0'(b^* + 1)\ge \tfrac{1}{2}(s_k^- + s_k^+)\), in order to choose the new interval. To this end, we first maximize \(f_\tau \) for \(\tau := -\tfrac{1}{2}(s_k^- + s_k^+)\) over \([b^-, b^+]\). This can be done by solving (SP) for the corresponding instance, which by our assumption is possible in polynomial time. Suppose the maximum is attained at \(b_{k + 1}\). As a weighted sum of concave functions, \({\hat{f}}_\tau \) is concave, and hence, we know that \({\hat{f}}_\tau '(b) \ge 0\) for all \(b < b_{k + 1}\), and \({\hat{f}}_\tau '(b) \le 0\) for all \(b \ge b_{k + 1}\). From (10), one can conclude that \({\hat{f}}_\tau '(b) = {\hat{f}}_0'(b) + \tau \) for all \(\tau \in [-1, 1]\) and all \(b \in [b^+]\). We derive that \({\hat{f}}_0'(b^* + 1) \ge -\tau = \tfrac{1}{2}(s_k^- + s_k^+)\) if \(b^* + 1 < b_{k + 1}\), and \({\hat{f}}_0'(b^* + 1) \le -\tau = \tfrac{1}{2}(s_k^- + s_k^+)\) otherwise. \(\square \)

Theorem 3

Problem (SP) with a continuous componentwise uniform distribution of \(\mathbf {c}\) is #P-hard.

Proof

The result can be shown by a similar proof to the one of Theorem 2: Instead of the discrete distribution used before, the continuous distribution

$$\begin{aligned} (\mathbf {c}_1, \dots , \mathbf {c}_{m}) \sim \mathcal {U} \prod _{i = 1}^{m}\left[ \tfrac{a_i}{2a_{m + 1}}, \tfrac{3a_i}{2a_{m + 1}}\right] \end{aligned}$$

is considered, while fixing \(c_{m + 1} = 1\). The sets \(I_\mathbf {c}\) are defined as before, and it can be shown that each set has probability \(\tfrac{1}{2^m}\): if \(\mathbf {c}_i \in (\frac{2a_i}{2a_{m+1}}, \frac{3a_i}{2a_{m+1}}]\), we have that \(\frac{\mathbf {c}_i}{a_i} > \frac{1}{a_{m+1}}\), hence \(i \in I_\mathbf {c}\), while \(\mathbf {c}_i \in [\frac{a_i}{2a_{m+1}}, \frac{2a_i}{2a_{m+1}})\) implies \(\frac{\mathbf {c}_i}{a_i} < \frac{1}{a_{m+1}}\), so that \(i \notin I_\mathbf {c}\). Both events have probability \(\nicefrac 12\). The rest of the proof is analogous, except for a small change in the computation in (10) due to the slightly different probabilities. \(\square \)

Note that \(c_{m+1}\) is fixed in the proof of Theorem 3. In order to avoid this, one can consider \(\mathbf {c}_{m+1} \sim \mathcal {U} [1 - \varepsilon , 1 + \varepsilon ]\) instead, for sufficiently small \(\varepsilon > 0\).

Theorem 4

Evaluating the objective function of Problem (SP) with a discrete or continuous componentwise uniform distribution of \(\mathbf {c}\) is #P-hard.

Proof

Using the same construction and notation as in the preceding proofs, we have shown that computing \({\hat{f}}'_0(b^* + 1)={\hat{f}}_0(b^*+1)-{\hat{f}}_0(b^*)\) is #P-hard. It follows that also evaluating \({\hat{f}}_0\) is #P-hard. \(\square \)

Note that the proof of Theorem 4, together with (7) and (9), implies that already the computation of the values \(\hat{x}_{i}(b)\) and \(\Delta \hat{x}_i(b)\) for some given \(i \in [n]\) and \(b \in [A]\) can be #P-hard. Moreover, the constructions in the proofs of Theorem 2 and 3 show that all stated hardness results still hold when \(\delta =0\). One can show that, since all follower’s item values in these constructions are positive, the hardness result also holds when assuming \(d\ge 0\) and \(\delta >0\); see [2].

Considering these results, it is a natural question whether (SP) can at least be approximated efficiently. Assuming \(b^-=0\), this question is well defined, since all optimal values are nonnegative then, due to \({\hat{f}}(0)=0\). However, it is easy to derive the following negative result, which excludes the existence of any polynomial time (multiplicative) approximation algorithm, unless P \(=\) NP.

Theorem 5

For Problem (SP) with a discrete or continuous componentwise uniform distribution of \(\mathbf {c}\) and with \(b^-=0\), it is #P-hard to decide whether the optimal value is zero.

Proof

For any given instance of (SP) and any \(K\in \mathbb {R}_{\ge 0}\), we can efficiently construct a new instance of (SP) by adding an item \(n+1\) with leader’s value \(d_{n+1}=-K+\delta \), size \(a_{n+1}=1\), and any distribution of \(\mathbf {c}_{n+1}\) guaranteeing \(\mathbb {P}(\mathbf {c}_{n+1}>\mathbf {c}_{i}/a_i)=1\) for all \(i\in [n]\). Let \({\hat{f}}\) and \({\hat{f}}_K\) denote the objective functions of the original and the extended problem, respectively. By construction, the follower will always choose item \(n+1\) first in the extended instance. Thus, \({\hat{f}}_K(b)=-Kb\le 0\) for \(b\in [0,1]\) and \({\hat{f}}_K(b)={\hat{f}}(b-1)-K\) for \(b\in [1,b^++1]\). In summary, we can polynomially reduce the decision of

$$\begin{aligned} \max _{b\in [0,b^+]}{\hat{f}}(b)\le K \end{aligned}$$
(11)

to the decision of

$$\begin{aligned} \max _{b\in [0,b^++1]}{\hat{f}}_K(b)\le 0. \end{aligned}$$

Since the computation of an optimal solution for the original instance of (SP) can be polynomially reduced to problems of type (11), using a bisection algorithm, the desired result now follows from Theorems 2 and 3. \(\square \)

4.2 Pseudo-Polynomial Time Algorithms

We now present pseudo-polynomial time algorithms for the stochastic bilevel continuous knapsack problem in the #P-hard cases addressed in the previous section. These algorithms are based on a dynamic programming approach. As discussed in Sect. 2.2, the leader’s objective function is piecewise linear with vertices at integral positions \(b\in [A]\), since the item sizes a are assumed to be integral. Therefore, we could solve the problem by evaluating \({\hat{f}}(b)\) for \(\mathcal {O}(A)\) many values of b, and A has polynomial size in the numerical values of the sizes a. The quest for a pseudo-polynomial algorithm thus reduces to the computation of \({\hat{f}}(b)\) for given \(b\in [A]\). However, we have seen in the previous section that also the latter task is #P-hard in general.

Actually, as mentioned, even the computation of \(\Delta \hat{x}_i(b)\) for given \(i \in [n]\) and \(b \in [A]\) can be #P-hard. In the following, we will present algorithms for computing \(\Delta \hat{x}\) in pseudo-polynomial time for the distributions addressed above, i.e., for item values that are componentwise uniformly distributed on a finite set or on a closed interval. From \(\Delta \hat{x}\) one can compute \(\hat{x}\) using formula (8) and with that evaluate \({\hat{f}}\) for all integral capacities using formula (7), which takes pseudo-polynomial time \(\mathcal {O}(nA)\).

In order to compute \(\Delta {\hat{x}}\), we first define the auxiliary function

$$\begin{aligned} g_i(b, I) := \mathbb {P}\left( \mathbf {c}_i> 0\text { and }\sum _{j \in I,\,\mathbf {c}_j/a_j > \mathbf {c}_i/a_i} a_j = b \right) , \end{aligned}$$

for \(i \in [n]\), \(I \subseteq [n] {\setminus } \{i\}\), and \(b \in \mathbb {Z}\), i.e., the probability that item i is profitable and that the total size of all items in I that the follower prefers over item i is exactly b. We then have

$$\begin{aligned} \Delta \hat{x}_i(b) = \frac{1}{a_i} \sum _{r = 1}^{a_i} g_i\left( b-r, {[n]}{\setminus } \{i\}\right) \end{aligned}$$
(12)

for all \(i \in {[n]}\) and \(b\in [A]\). Indeed, for \(r\in [a_i]\), the value \(g_i(b-r, {[n]}{\setminus } \{i\})\) describes the probability that a percentage of exactly \(r/a_i\) of item i is packed when the capacity is b, and hence \((r-1)/{a_i}\) when the capacity is \(b-1\). The sum thus represents the probability that the percentage of item i being packed is increased by \(1/a_i\) when increasing the capacity from \(b-1\) to b. Hence, the right hand side agrees with \(\hat{x}_i(b)-\hat{x}_i(b-1)=\Delta {\hat{x}}_i(b)\).

Note that \(\mathbf {c}_j/a_j > \mathbf {c}_i/a_i\) and \(\mathbf {c}_i > 0\) in the definition of \(g_i(b, I)\) could be replaced equivalently by \(\mathbf {c}_j/a_j \ge \mathbf {c}_i/a_i\) and \(\mathbf {c}_i \ge 0\) by Assumption (5), and the same is true in the following whenever comparing profits of different items.

Determining all probabilities \(g_i(b, {[n]}{\setminus }\{i\})\) would thus allow us to compute \(\Delta \hat{x}\) and hence to solve Problem (SP) in pseudo-polynomial time. To this end, for \(i \in [n]\), \(I \subseteq {[n]} {\setminus } \{i\}\), \(b \in \mathbb {Z}\), and \(\gamma \in \mathbb {R}\), we next define

$$\begin{aligned} h_i(b, I, \gamma ) := \mathbb {P}\left( \sum _{j \in I,\,\mathbf {c}_j/a_j > \gamma /a_i} a_j = b \right) , \end{aligned}$$
(13)

i.e., the probability that the total size of all items in I with profit larger than \(\frac{\gamma }{a_i}\) is exactly b. For the following, let \(\text {supp}^+(\mathbf {c}_i):=\text {supp}(\mathbf {c}_i)\cap \mathbb {R}_{>0}\).

From now on we assume componentwise independent item values. Under this assumption, for item values with finite support, we then have

$$\begin{aligned} g_i(b, I) = \sum _{\gamma \in \text {supp}^+(\mathbf {c}_i)} \mathbb {P}(\mathbf {c}_i = \gamma ) \cdot h_i(b, I, \gamma ), \end{aligned}$$
(14)

while for absolutely continuously distributed item values, we have

$$\begin{aligned} g_i(b, I) = \int _{\text {supp}^+(\mathbf {c}_i)} p_i(\gamma ) \cdot h_i(b, I, \gamma ) \; \mathrm{d} \gamma , \end{aligned}$$
(15)

where \(p_i(\gamma )\) denotes the probability density function of the random variable \(\mathbf {c}_i\). For all \(i\in [n]\) and \(\gamma \in \mathbb {R}\), it is easy to verify that

$$\begin{aligned} h_i(b, \emptyset , \gamma ) = {\left\{ \begin{array}{ll} 1 &{}\quad \text {for } b=0 \\ 0 &{}\quad \text {for } b\ne 0 \end{array}\right. } \end{aligned}$$

and, if \(j\in I\) and \(i\not \in I\),

$$\begin{aligned} h_i(b, I, \gamma )&= \mathbb {P}(\mathbf {c}_j / a_j> \gamma / a_i) \cdot h_i(b-a_j, I {\setminus } \{j\}, \gamma ) \nonumber \\&\quad +\, (1 - \mathbb {P}(\mathbf {c}_j / a_j > \gamma / a_i)) \cdot h_i(b, I {\setminus } \{j\}, \gamma ). \end{aligned}$$
(16)

This recursive formula enables an incremental computation of \(h_i(b, {[n]}{\setminus } \{i\}, \gamma )\) for given \(i \in {[n]}\)\(\gamma \in \mathbb {R}\), and \(b\in \{0,\dots ,A\}\). We emphasize that only \(\mathcal {O}(n)\) many subsets I of [n] need to be considered for this, as, for the recursion (16), it suffices to choose one element j to be removed from I. Using this, we can now develop pseudo-polynomial time algorithms for computing \(\Delta \hat{x}\) in case of independently and uniformly distributed item values, with supports being either finite sets or continuous intervals.

4.2.1 Componentwise Uniform Distributions with Finite Support

In this section, we assume that all item values are independently and discretely distributed with finite support. More specifically, for \(i\in [n]\), the value of item i has \(m_i \in \mathbb {N}\) different realizations \(c_i^1,\dots ,c_i^{m_i}\) with probabilities \(p_i^1,\dots ,p_i^{m_i}\), respectively. Let \(m := \max \{m_1,\dots ,m_n\}\) denote the maximum number of different values any item can take.

Lemma 1

All probabilities \(\mathbb {P}(\mathbf {c}_j/a_j > c_i^k / a_i)\) for \(i, j \in {[n]}\), \(i \ne j\), and \(k\in [m_i]\) can be computed in time \(\mathcal {O}(m^2n^2)\).

Proof

Each such probability can be computed in time \(\mathcal {O}(m)\) as:

$$\begin{aligned} \mathbb {P}(\mathbf {c}_j/a_j> c_i^k / a_i) = \sum _{\ell \in [m_j], \, c_j^\ell /a_j > c_i^k / a_i} p_j^\ell , \end{aligned}$$

and the claim follows. \(\square \)

Lemma 2

Let \(i \in [n]\) and \(\gamma \in \mathbb {R}\). Given the probabilities \(\mathbb {P}(\mathbf {c}_j/a_j > \gamma / a_i)\) for all \(j\in [n]{\setminus }\{i\}\), the probabilities \(h_i(b, {[n]} {\setminus } \{i\}, \gamma )\) for all \(b\in \{0,\dots ,A-a_i\}\) can be computed in time \(\mathcal {O}(nA)\).

Proof

We apply the recursive formula (16) in order to compute the desired probabilities \(h_i(b, {[n]} {\setminus } \{i\}, \gamma )\). More specifically, setting \(I := \emptyset \) and \(b_{max} := 0\) at the beginning, we iterate over all \(j \in {[n]} {\setminus } \{i\}\) in an arbitrary order. For each such j, we first compute

$$\begin{aligned} h_i(b, I \cup \{j\}, \gamma )&= \mathbb {P}(\mathbf {c}_j / a_j> \gamma /a_i) \cdot h_i(b-a_j, I, \gamma )\\&\quad +\, (1 - \mathbb {P}(\mathbf {c}_j / a_j > \gamma /a_i)) \cdot h_i(b, I, \gamma ) \end{aligned}$$

for all \(b\in \{0,\dots ,b_{max}+a_j\}\), with \(h_i(b, I, \gamma ) = 0\) for \(b \not \in \{0,\dots ,b_{max}\}\), and then set \(I := I \cup \{j\}\) and \(b_{max} := b_{max} + a_j\). After the last iteration, we then have computed \(h_i(b, {[n]} {\setminus } \{i\}, \gamma )\) for all \(b\in \{0,\dots ,A-a_i\}\). There are \(\mathcal {O}(n)\) iterations and each iteration can be executed in time \(\mathcal {O}(A)\).\(\square \)

Theorem 6

For item values that are independently distributed on finite sets, Problem (SP) can be solved in time \(\mathcal {O}(m^2n^2 + mn^2A)\).

Proof

By Lemmas 1 and 2, all values \(h_i(b, {[n]} {\setminus } \{i\}, c_i^k)\) for \(i \in {[n]}\), \(k\in [m_i]\), and \(b \in \{0,\dots ,A\}\) can be computed in time \(\mathcal {O}(m^2n^2 + mn^2A)\). Next, all probabilities \(g_i(b, {[n]} {\setminus } \{i\})\) can be computed in time \(\mathcal {O}(mnA)\) according to (14). Finally, all values \(\Delta \hat{x}_i(b)\) for \(i \in {[n]}\) and \(b\in [A]\) can be computed in time \(\mathcal {O}(nA)\) using \(\Delta {\hat{x}}_{i}(1) = \tfrac{1}{a_i} \; g_i\left( 0, {[n]}{\setminus } \{i\}\right) \) and

$$\begin{aligned} \Delta {\hat{x}}_{i}(b) = \Delta {\hat{x}}_{i}(b-1) + \tfrac{1}{a_i} \left( g_i\left( b, {[n]}{\setminus } \{i\}\right) - g_i\left( b-a_i, {[n]}{\setminus } \{i\}\right) \right) \end{aligned}$$

for \(b\in \{2,\dots ,A\}\), which follows from (12). From \(\Delta \hat{x}\) one can compute \(\hat{x}\) in time \(\mathcal {O}(nA)\) using (8) and with that evaluate \({\hat{f}}(b)\) for all \(b\in [A]\) in time \(\mathcal {O}(nA)\) using (7). \(\square \)

In case the number of possible realizations for each component of \(\mathbf {c}\) is bounded by a constant, e.g., when we have \(m=2\) as in the proof of Theorem 2, the running time stated in Theorem 6 simplifies to \(\mathcal {O}(n^2A)\).

4.2.2 Componentwise Continuous Uniform Distributions

In this section, we assume that the value \(\mathbf {c}_i\) of item \(i\in [n]\) is distributed uniformly on the continuous interval \([c_i^-, c_i^+]\) with \(c_i^- < c_i^+\). The key difference to the discrete case discussed in the previous section is that we compute the probabilities \(h_i(b, I, \gamma )\) not for fixed \(\gamma \), but as functions in \(\gamma \). The involved probabilities \(\mathbb {P}(\mathbf {c}_j / a_j > \gamma /a_i)\) are piecewise linear in \(\gamma \). As a result, \(h_i(b, I, \gamma )\) is a piecewise polynomial function in \(\gamma \) and the expected values \(\Delta \hat{x}\) can be computed as integrals over piecewise polynomial functions.

Consider \(V := \{\max \{0,\frac{c_i^-}{a_i}\}, \max \{0,\frac{c_i^+}{a_i}\} \mid i \in {[n]} \}\) and set \(r:=|V|\). Let \(v_1,\dots ,v_r \in V\) with \(v_1< \dots < v_r\) be the ascending enumeration of all elements in V. For \(i, j \in [n]\), \(i \ne j\), and \(\gamma \in \mathbb {R}\), we have

$$\begin{aligned} \mathbb {P}(\mathbf {c}_j / a_j > \gamma / a_i) = {\left\{ \begin{array}{ll} 1 &{}\quad \text {for } \gamma \le \tfrac{a_i}{a_j}c_j^- \\ \frac{c_j^+-\tfrac{a_j}{a_i}\gamma }{c_j^+ - c_j^-} &{}\quad \text {for } \tfrac{a_i}{a_j}c_j^- \le \gamma \le \tfrac{a_i}{a_j}c_j^+ \\ 0 &{}\quad \text {for } \gamma \ge \tfrac{a_i}{a_j}c_j^+. \end{array}\right. } \end{aligned}$$

In particular, \(\mathbb {P}(\mathbf {c}_j / a_j > \gamma /a_i)\), as a function in \(\gamma \), is linear on each interval \([a_i v_k, a_i v_{k+1}]\).

Lemma 3

Let \(i \in {[n]}\) and \(k \in [r-1]\) be given. Then, the coefficients of the polynomials \(h_i(b, {[n]} {\setminus } \{i\}, \gamma )\) on the interval \((a_i v_k, a_i v_{k+1}]\subseteq \text {supp}^+(\mathbf {c}_i)\), for all \(b \in \{0, \dots , A - a_i\}\), can be computed in time \(\mathcal {O}(n^2A)\).

Proof

Similarly to the proof of Lemma 2, we can compute \(h_i(b, {[n]} {\setminus } \{i\}, \gamma )\) by iteratively applying the recursive formula (16). The only difference is that each application of the recursive formula involves two multiplications of a polynomial \(h_i(b, I, \gamma )\) of degree \(\mathcal {O}(n)\) with a linear function and the summation of the resulting polynomials. This can be done in time \(\mathcal {O}(n)\) and the claim follows. \(\square \)

Theorem 7

For item values that are independently and uniformly distributed on continuous intervals, Problem (SP) can be solved in time \(\mathcal {O}(n^4A)\).

Proof

By Lemma 3, the piecewise polynomial functions \(h_i(b, {[n]}{\setminus } \{i\}, \gamma )\) can be computed for all \(i \in {[n]}\), all \(b\in \{0,\dots ,A-a_i\}\), and all of the at most 2n intervals \((a_i v_k, a_i v_{k+1}] \subseteq \text {supp}^+(\mathbf {c}_i)\) in time \(\mathcal {O}(n^4A)\). Using (15), all probabilities \(g_i(b, {[n]}{\setminus } \{i\})\) can be obtained in time \(\mathcal {O}(n^3A)\) by computing \(\mathcal {O}(n)\) integrals over polynomials of degree \(\mathcal {O}(n)\) for each \(i \in [n]\) and \(b \in [A]\). As in Theorem 6, the claim follows. \(\square \)

From the proofs of Lemma 3 and Theorem 7, it follows easily that a pseudo-polynomial algorithm exists for each class of continuous distributions such that the entries \(\mathbf {c}_i\) are independently distributed and such that each \(\mathbf {c}_i\) has a piecewise polynomial density function, assuming that the latter is given explicitly as part of the input. In particular, each entry \(\mathbf {c}_i\) may have a support consisting of a finite union of bounded closed intervals such that \(\mathbf {c}_i\) induces a uniform distribution on each of these intervals.

Moreover, the approach can deal with item values \(\mathbf {c}_i\) that are given as weighted sums of independently and uniformly distributed random variables on continuous intervals, as long as the number of summands is fixed. Indeed, if some given distributions have piecewise polynomial density functions, then the density function of their sum (assuming independence) is again piecewise polynomial, and the number of polynomial pieces is bounded by the product of the numbers of pieces of the original density functions. In particular, this applies to the case where each component independently follows an Irwin–Hall distribution.

4.3 Correlated Distributions

The fact that (SP) can be solved in pseudo-polynomial time for uniform independently distributed item values raises the question of how much the complexity increases when considering correlated item values. This question is only well defined when we restrict ourselves to specific classes of distributions and when we specify how exactly the input is given. As an example, one may consider uniform distributions on general polytopes, instead of boxes as in Theorems 3 and 7. For this case, one can show that no pseudo-polynomial algorithm in the total item size A can exist unless P \(=\) NP, since the problem is already hard for unit sizes. However, the hardness derives from the complexity that can be modeled into the polytope, rather than from the stochastic optimization task itself, and the problem may turn tractable again if the numbers appearing in the description of the polytope are polynomially bounded; see [14] for details.

5 Additive Approximation Scheme for Componentwise Distributions

Building on the results of the previous section, we next devise a fully pseudo-polynomial time additive approximation scheme for Problem (SP) for arbitrary absolutely continuous distributions with independent components \(\mathbf {c}_i\). This approach can be easily adapted to deal with discrete distributions (with finite or infinite support) as well. Recall that the case of finite support was settled by Theorem 6, but the running time of the corresponding algorithm depends on the size of the supports. It may thus be desirable to approximate a discrete distribution by another discrete distribution with a smaller support in order to obtain a faster running time, even if this comes with a small error.

For each \(i\in [n]\), we assume that the distribution of \(\mathbf {c}_i\) is given by an oracle for its cumulative distribution function, defined as:

$$\begin{aligned} F_{\mathbf {c}_i}(\gamma ):=\mathbb {P}(\mathbf {c}_i\le \gamma ), \end{aligned}$$

as well as an oracle for its quantile function

$$\begin{aligned} Q_{\mathbf {c}_i}(p):=\inf \,\{\gamma \in \mathbb {R}\mid p\le F_{\mathbf {c}_i}(\gamma )\}. \end{aligned}$$

For convenience, we set \(F_{\mathbf {c}_i}(\infty )=1\). If \(F_{\mathbf {c}_i}\) is invertible, we have \(Q_{\mathbf {c}_i}=F^{-1}_{\mathbf {c}_i}\).

Starting with some desired additive accuracy \(\varepsilon >0\), we set

$$\begin{aligned} m := \left\lceil \tfrac{1}{\varepsilon }{(n-1) A D} \right\rceil + 1 \end{aligned}$$

with \(D:=\sum _{j=1}^n|d_j|\). The idea is to approximate each \(\mathbf {c}_i\) by a new random variable \({\tilde{\mathbf {c}}}_i\) having a uniform distribution on the finite set \(\{{\tilde{c}}_i^1,\dots ,\tilde{c}_i^m\}\), where

$$\begin{aligned} {\tilde{c}}_i^k:=Q_{\mathbf {c}_i}\left( \tfrac{k-\nicefrac 12}{m}\right) \end{aligned}$$

for \(k\in [m]\); see Fig. 1 for an illustration.

Fig. 1
figure 1

Approximation of \(\mathbf {c}_i\sim \text {Exp}(1)\) by \({\tilde{\mathbf {c}}}_i\), for \(m=5\)

Let \({\tilde{h}}_i(b,I,\gamma )\) be defined as in (13), but for \({\tilde{\mathbf {c}}}_i\) instead of \(\mathbf {c}_i\). Then, for each \(i \in [n]\) and \(b \in \{0, \dots , A-a_i\}\), the probabilities \(\tilde{h}_i(b,I,\gamma )\) form a piecewise constant function in \(\gamma \) with all discontinuities belonging to the set

$$\begin{aligned} J_i:=\left\{ \tfrac{a_i}{a_j}{\tilde{c}}_j^k\mid j\in [n]{\setminus }\{i\},~k\in [m]\right\} . \end{aligned}$$

By Lemma 2, for each fixed \(i \in [n]\) and \(\gamma \in \mathbb {R}\), the values \({\tilde{h}}_i(b,[n]{\setminus }\{i\},\gamma )\) for all \(b \in \{0, \dots , A-a_i\}\) can be computed in time \(\mathcal {O}(nA)\), given the probabilities \(\mathbb {P}({\tilde{\mathbf {c}}}_j/a_j> \gamma /a_i)\) for all \(j\in [n] {\setminus } \{i\}\). Hence, the computation for all points \(\gamma \in J_i\) can be done in time \(\mathcal {O}(mn^2A)\). Each of the probabilities \(\mathbb {P}({\tilde{\mathbf {c}}}_j/a_j> \gamma /a_i)\) can be computed in constant time using the oracle for \(F_{\mathbf {c}_j}\), since \(F_{{\tilde{\mathbf {c}}}_j}(\gamma \tfrac{a_j}{a_i})=1-\mathbb {P}({\tilde{\mathbf {c}}}_j/a_j > \gamma /a_i)\) can be obtained from \(F_{\mathbf {c}_j}(\gamma \tfrac{a_j}{a_i})\) by rounding it to the closest multiple of \(\nicefrac 1m\), rounding up in case of a tie; compare Lemma 4. In summary, the computation of \({\tilde{h}}_i(b,[n]{\setminus }\{i\},\gamma )\) for all \(i\in [n]\), all \(b \in \{0, \dots , A\}\), and all \(\gamma \in J_i\) takes time \(\mathcal {O}(mn^3A)\).

Now let \(j_1,\dots ,j_r\) be the elements of \(J_i\cap \mathbb {R}_{>0}\) in ascending order, and set \(j_0=0\) and \(j_{r+1}=\infty \). Denoting the probability density function of \(\mathbf {c}_i\) by \(p_i\) again, we set

$$\begin{aligned} {\tilde{g}}_i(b, I) := \int _{0}^{\infty } p_i(\gamma ) \cdot \tilde{h}_i(b,I, \gamma ) \; \mathrm{d} \gamma= & {} \sum _{k=0}^r \int _{j_k}^{j_{k+1}} p_i(\gamma ) \cdot {\tilde{h}}_i(b,I,j_k) \;\mathrm{d} \gamma \\= & {} \sum _{k=0}^r {\tilde{h}}_i(b,I,j_k) (F_{\mathbf {c}_i}(j_{k+1})-F_{\mathbf {c}_i}(j_{k})). \end{aligned}$$

Using the oracle for evaluating \(F_{\mathbf {c}_i}\), we can thus compute \({\tilde{g}}_i(b,[n]{\setminus }\{i\})\) for all \(i\in [n]\) and all \(b \in \{0, \dots , A\}\) from the relevant values of \(\tilde{h}_i\) in time \(\mathcal {O}(mn^2A)\). The total time needed to compute the required values \({\tilde{g}}_i(b,[n]{\setminus }\{i\})\) is thus given as \(\mathcal {O}(mn^3A)\). Proceeding exactly as in the proof of Theorem 6, based on the values \(\tilde{g}_i(b,[n]{\setminus }\{i\})\) instead of \(g_i(b,[n]{\setminus }\{i\})\), we can finally compute some \(\tilde{b}\in [b^-,b^+]\) which maximizes the resulting objective function. The entire algorithm runs in pseudo-polynomial time

$$\begin{aligned} \mathcal {O}(mn^3A) = \mathcal {O}(\tfrac{1}{\varepsilon }n^4 A^2 D). \end{aligned}$$

We claim that the computed solution is actually an \(\varepsilon \)-approximate solution for the original problem, in the additive sense. To show this, we first observe that the cumulative distribution functions of \(\mathbf {c}_i\) and \({\tilde{\mathbf {c}}}_i\) have a pointwise difference of at most \(\tfrac{1}{2m}\).

Lemma 4

Let \(i\in [n]\). Then, \(||F_{\mathbf {c}_i}-F_{{\tilde{\mathbf {c}}}_i}||_{\infty }\le \tfrac{1}{2m}\).

Proof

Let \(k\in [m]\). For any \(\beta \ge {\tilde{c}}_i^k\), we derive from the definition of \(Q_{\mathbf {c}_i}\) that there exists \(\gamma \le \beta \) such that \(\tfrac{k-\nicefrac 12}{m}\le F_{\mathbf {c}_i}(\gamma )\), and hence \(\tfrac{k-\nicefrac 12}{m}\le F_{\mathbf {c}_i}(\beta )\) by monotonicity of \(F_{\mathbf {c}_i}\). For any \(\beta <{\tilde{c}}_i^k\), the definition of \(Q_{\mathbf {c}_i}\) directly implies that \(\tfrac{k-\nicefrac 12}{m}> F_{\mathbf {c}_i}(\beta )\). In particular, for \(k \in [m - 1]\) and \(\beta \in [{\tilde{c}}_i^k,{\tilde{c}}_i^{k+1})\), we obtain \(F_{{\tilde{\mathbf {c}}}_i}(\beta )=\tfrac{k}{m}\) and \(F_{\mathbf {c}_i}(\beta )\in [\tfrac{k-\nicefrac 12}{m},\tfrac{k+\nicefrac 12}{m})\), and hence \(|F_{\mathbf {c}_i}(\beta )-F_{{\tilde{\mathbf {c}}}_i}(\beta )|\le \tfrac{1}{2m}\). For \(\beta \in [0,{\tilde{c}}_i^1)\), we have \(F_{{\tilde{\mathbf {c}}}_i}(\beta )=0\) and \(F_{\mathbf {c}_i}(\beta )\le \tfrac{1}{2m}\), while \(\beta \in [\tilde{c}_i^m,\infty )\) implies \(F_{{\tilde{\mathbf {c}}}_i}(\beta )=1\) and \(F_{\mathbf {c}_i}(\beta )\ge \tfrac{m-\nicefrac 12}{m}=1-\tfrac{1}{2m}\). \(\square \)

Lemma 5

Let \(b^*\) be an optimizer of (SP) for the original distribution of \(\mathbf {c}\) and let \({\tilde{b}}\) be computed as described above. Then, \(|{\hat{f}}({\tilde{b}})-{\hat{f}}(b^*)|\le \varepsilon \).

Proof

For \(i\in [n]\)\(I\subseteq [n]{\setminus }\{i\}\), and \(\gamma \in \mathbb {R}\), define

$$\begin{aligned} \delta _i(I,\gamma ) := \max _b|h_i(b,I,\gamma )-{\tilde{h}}_i(b,I,\gamma )|. \end{aligned}$$

Then, using (16) for any \(j\in I\), we obtain

$$\begin{aligned} \delta _i(I,\gamma )= & {} \max _b ~ |(1-F_{\mathbf {c}_j}(\gamma \tfrac{a_j}{a_i}))h_i(b-a_j,I{\setminus }\{j\},\gamma ) +F_{\mathbf {c}_j}(\gamma \tfrac{a_j}{a_i})h_i(b,I{\setminus }\{j\},\gamma )\\&-\, (1-F_{{\tilde{\mathbf {c}}}_j}(\gamma \tfrac{a_j}{a_i}))\tilde{h}_i(b-a_j,I{\setminus }\{j\},\gamma ) -F_{{\tilde{\mathbf {c}}}_j}(\gamma \tfrac{a_j}{a_i})\tilde{h}_i(b,I{\setminus }\{j\},\gamma )|\\= & {} \max _b ~ |(1-F_{{\tilde{\mathbf {c}}}_j}(\gamma \tfrac{a_j}{a_i}))(h_i(b-a_j,I{\setminus }\{j\},\gamma )-\tilde{h}_i(b-a_j,I{\setminus }\{j\},\gamma ))\\&+\, F_{{\tilde{\mathbf {c}}}_j}(\gamma \tfrac{a_j}{a_i})(h_i(b,I{\setminus }\{j\},\gamma )-{\tilde{h}}_i(b,I{\setminus }\{j\},\gamma ))\\&+\, (F_{{\tilde{\mathbf {c}}}_j}(\gamma \tfrac{a_j}{a_i})-F_{\mathbf {c}_j}(\gamma \tfrac{a_j}{a_i})) (h_i(b-a_j,I{\setminus }\{j\},\gamma )-h_i(b,I{\setminus }\{j\},\gamma ))|\\\le & {} \max _b ~ (1-F_{{\tilde{\mathbf {c}}}_j}(\gamma \tfrac{a_j}{a_i}))\cdot |h_i(b-a_j,I{\setminus }\{j\},\gamma )-{\tilde{h}}_i(b-a_j,I{\setminus }\{j\},\gamma )|\\&+\, F_{{\tilde{\mathbf {c}}}_j}(\gamma \tfrac{a_j}{a_i})\cdot |h_i(b,I{\setminus }\{j\},\gamma )-{\tilde{h}}_i(b,I{\setminus }\{j\},\gamma )|\\&+\, \underbrace{|F_{{\tilde{\mathbf {c}}}_j}(\gamma \tfrac{a_j}{a_i})-F_{\mathbf {c}_j}(\gamma \tfrac{a_j}{a_i})|}_{\le \tfrac{1}{2m} (\text {Lemma}~5.1)}\cdot \underbrace{|h_i(b-a_j,I{\setminus }\{j\},\gamma )-h_i(b,I{\setminus }\{j\},\gamma )|}_{\le 1}\\\le & {} \max _b ~ (1-F_{{\tilde{\mathbf {c}}}_j}(\gamma \tfrac{a_j}{a_i}))\cdot \delta _i(I{\setminus }\{j\},\gamma )+F_{{\tilde{\mathbf {c}}}_j}(\gamma \tfrac{a_j}{a_i})\cdot \delta _i(I{\setminus }\{j\},\gamma )+\tfrac{1}{2m}\\= & {} \delta _i(I{\setminus }\{j\},\gamma )+\tfrac{1}{2m}, \end{aligned}$$

which by induction implies \(\delta _i(I,\gamma )\le \tfrac{n-1}{2m}\) for all \(I\subseteq [n]{\setminus }\{i\}\) and all \(\gamma \in \mathbb {R}\). We thus obtain

$$\begin{aligned} |g_i(b,I)-{\tilde{g}}_i(b,I)|&\le \int _{0}^{\infty } p_i(\gamma )|h_i(b,I,\gamma )-\tilde{h}_i(b,I,\gamma )|\; \mathrm{d} \gamma \\&\le \tfrac{n-1}{2m}\int _{0}^{\infty } p_i(\gamma )\; \mathrm{d} \gamma = \tfrac{n-1}{2m} \end{aligned}$$

for all \(i \in [n]\), \(I \subseteq [n] {\setminus } \{i\}\), and \(b \in \{0, \dots , A\}\). It follows from (12) that the resulting additive error in \(\Delta {\hat{x}}_{i}(b)\) is at most \(\tfrac{n-1}{2m}\) and thus the additive error in \({\hat{x}}_i(b)\) is at most \(b\tfrac{n-1}{2m}\) for all \(i\in [n]\) using (8). Finally, the additive error in \({\hat{f}}(b)\), for any b, is bounded by

$$\begin{aligned} \sum _{i=1}^n|d_i|b\tfrac{n-1}{2m}\le \tfrac{(n-1)AD}{2m} \le \tfrac{1}{2}\varepsilon , \end{aligned}$$

which implies the desired result. \(\square \)

It is easy to see that the proof of Lemma 5 also works when all or some components of \(\mathbf {c}\) follow a discrete distribution. For this, it suffices to adapt the definition of \({\tilde{g}}_i\) and the estimation of its error. Altogether, we thus obtain

Theorem 8

Assume that the components of \(\mathbf {c}\) are independently distributed and that the distribution of each component \(\mathbf {c}_i\) is given by oracles for its cumulative distribution function and its quantile function. Then, there exists a fully pseudo-polynomial time additive approximation scheme for (SP).

6 Conclusion

We have settled the complexity status of the stochastic bilevel continuous knapsack problem with uncertain follower’s item values for different types of distributions. In case of a distribution with finite and explicitly given support, the problem is tractable. If the item values are independently and uniformly distributed, the problem is #P-hard in general, both for continuous and discrete distributions, but we devise pseudo-polynomial algorithms for both cases. Finally, we present a fully pseudo-polynomial additive approximation scheme for the case of arbitrary distributions with independent item values.

For the (single-level) binary knapsack problem, it is a classical result that the well-known pseudo-polynomial algorithm can be turned into an FPTAS by a natural rounding approach [13]. Unfortunately, such an approach fails for the pseudo-polynomial algorithm presented in Sect. 4.2. In fact, by Theorem 5, an FPTAS for the stochastic bilevel continuous knapsack problem under the distributions considered in Sect. 4 cannot exist, at least not in the multiplicative sense.

Finally, several interesting variants of the stochastic bilevel continuous knapsack problem arise when replacing the expected value in (SP) by some other risk measure, e.g., by a higher moment or a combination of different moments. This would allow to take also the variance into account, as is common in mean-risk optimization. Also other risk measures such as the conditional value at risk may be considered. For a collection of related results along the lines of Sects. 3 and 4.1, see [17].