In the standard Knapsack problem, the objective is to maximize $\sum c_i x_i$. I encounter a variant where the objective is to minimize $\sum c_i a^{x_i}$ where $a\in(0,1)$ is a constant. I am looking for an algorithm (possibly DP-based) with pseudo-polynomial time complexity to solve this problem. My question is whether this is feasible.
-
$\begingroup$ Is $x_i$ a nonnegative integer variable or a binary variable? $\endgroup$RobPratt– RobPratt2024-12-27 17:17:28 +00:00Commented Dec 27, 2024 at 17:17
-
$\begingroup$ Which ones are variables, which ones are givens, and what are the constraints? $\endgroup$fedja– fedja2024-12-27 20:07:57 +00:00Commented Dec 27, 2024 at 20:07
-
$\begingroup$ $x_i$ is a nonnegative integer. $\endgroup$lchen– lchen2024-12-28 10:14:27 +00:00Commented Dec 28, 2024 at 10:14
-
$\begingroup$ $x_i$ are variables. $c_i$ are given constants. Constraints are standard Knapsack constraints: $\sum a_ix_i\le A$ where $a_i$ and $A$ are constants. $\endgroup$lchen– lchen2024-12-28 10:16:20 +00:00Commented Dec 28, 2024 at 10:16
1 Answer
You want to minimize $\sum_{i=1}^n c_i a^{x_i}$ subject to $\sum_{i=1}^n a_i x_i \le A$ and $x_i \in \mathbb{Z}^+$.
Define value function $$v(k,B) = \min\left\{\sum_{i=1}^k c_i a^{x_i}: \sum_{i=1}^k a_i x_i \le B \land x_i \in \mathbb{Z}^+\right\}$$ so that the original problem is to calculate $v(n,A)$. The usual dynamic programming approach conditions on the value $y$ of $x_k$ to obtain recursion $$v(k,B) = \min_{y\in \{0,\dots,\lfloor B/a_k \rfloor\}} \left\{c_k a^y + v(k-1,B-a_k y) \right\}.$$
Alternatively, you can linearize the problem by introducing binary decision variables $z_{ij}$ to indicate whether $x_i=j$. The problem is then to minimize the linear objective function $$\sum_{i=1}^n c_i \sum_{j=0}^{\lfloor B/a_i \rfloor} a^j z_{ij}$$ subject to linear constraints \begin{align} \sum_{i=1}^n a_i x_i &\le A \\ \sum_{j=0}^{\lfloor B/a_i \rfloor} j z_{ij} &= x_i &&\text{for $i\in\{1,\dots,n\}$} \\ \sum_{j=0}^{\lfloor B/a_i \rfloor} z_{ij} &= 1 &&\text{for $i\in\{1,\dots,n\}$} \end{align} Now call an integer linear programming solver.
-
$\begingroup$ Thank you very much for your insightful solution. $\endgroup$lchen– lchen2024-12-30 01:45:21 +00:00Commented Dec 30, 2024 at 1:45