The colored knapsack problem: structural properties and exact algorithms
We introduce and study a novel generalization of the classical Knapsack Problem (KP), called the Colored Knapsack Problem (CKP). In this problem, the items are partitioned into classes of colors and the packed items need to be ordered such that no consecutive items are of the same color. We establish that the problem is weakly NP-hard and propose two exact dynamic programming algorithms with time complexities of $\mathcal{O}(bn^4)$ and $\mathcal{O}(b^2n^3)$, respectively. To enhance practical performance, we derive various dominance and fathoming rules for both approaches. From a theoretical perspective, we analyze the linear programming relaxation of the natural CKP formulation, proving that an optimal solution exists with at most two fractional items. We also show that the relaxation can be solved in $\mathcal{O}(n)$ time, matching the complexity of the classical KP. Finally, we establish a comprehensive benchmark of CKP instances, derived from the Colored Bin Packing Problem. Extensive computational experiments demonstrate that the proposed dynamic programming algorithms significantly outperform state-of-the-art MIP solvers on most of these instances.
💡 Research Summary
The paper introduces and thoroughly investigates the Colored Knapsack Problem (CKP), a novel extension of the classic 0‑1 Knapsack Problem (KP) that incorporates a color‑based adjacency constraint. In CKP each item i has a profit p_i, weight w_i, and a color κ_i belonging to a set of m colors. A feasible solution must not only respect the capacity bound Σ w_i x_i ≤ b but also admit an ordering of the selected items in which no two consecutive items share the same color. This requirement is captured by a family of linear inequalities: for every color c, the number of selected items of color c cannot exceed the number of selected items of all other colors plus one. The authors formalize this with an integer linear programming (ILP) model (ILP‑CKP) that augments the classic KP formulation with the “color constraints”.
Theoretical contributions begin with a complexity analysis. By observing that CKP reduces to KP when all colors are distinct, the authors confirm that CKP inherits the NP‑hardness of KP; they further prove that CKP is weakly NP‑hard via a reduction from the standard KP. The core of the paper is a detailed study of the linear programming (LP) relaxation of ILP‑CKP. Leveraging the structure of extreme points, they show that any optimal LP solution contains at most two fractional variables (Lemma 1). This mirrors the well‑known property of the KP LP relaxation where at most one variable is fractional. Moreover, they prove (Lemma 2) that if the optimal LP solution of the ordinary KP violates a particular color constraint, then there exists an optimal LP‑CKP solution in which that color becomes “critical” (the corresponding inequality holds at equality). Using this insight, they devise a combinatorial O(n) algorithm that solves the LP relaxation of CKP, matching the linear‑time bound known for the classic KP.
On the exact algorithm side, two dynamic programming (DP) schemes are presented. The first DP processes items one by one and stores states defined by the remaining capacity together with a vector of color‑balance values (the difference between the count of a given color and the count of all other colors). By applying dominance rules (discarding states that are dominated in both capacity and profit) and several fathoming rules (capacity overflow, impossible color balance, and optimistic profit bounds), the state space is dramatically reduced. This approach runs in O(b n⁴) time and uses polynomial space. The second DP adopts a decomposition strategy: it solves, for each color, an inner knapsack sub‑problem that determines the best profit achievable with a given amount of capacity allocated to that color. An outer DP then combines the per‑color results while enforcing the global color‑balance constraints. The inner sub‑problems are solved in O(b n) each, and the outer combination yields an overall complexity of O(b² n³). Both algorithms are exact and guarantee optimality.
To evaluate practical performance, the authors construct a comprehensive benchmark derived from the pricing sub‑problems of the Colored Bin Packing Problem (CBPP). The benchmark contains several hundred instances varying in number of items (n), number of colors (m), and knapsack capacity (b). Computational experiments compare the two DP algorithms against state‑of‑the‑art mixed‑integer programming solvers (Gurobi and CPLEX) applied directly to the ILP‑CKP model. Results show that, on the majority of instances, the DP methods outperform the MIP solvers by factors ranging from 5× to 20× in runtime. The advantage is especially pronounced for instances with many colors and large capacities, where the MIP formulation suffers from symmetry and weak relaxations. The dominance and fathoming rules are shown to prune more than 60 % of DP states on average, leading to modest memory consumption.
The paper concludes by summarizing its contributions: (i) formal definition of CKP and proof of weak NP‑hardness; (ii) structural analysis of the LP relaxation with at most two fractional items and an O(n) solution method; (iii) two exact DP algorithms with polynomial‑time guarantees and practical speed‑up techniques; (iv) an extensive benchmark and empirical evidence that the DP approaches dominate modern MIP solvers. Future research directions include extending the methods to the strongly NP‑hard regime (e.g., when the number of colors grows with input size), exploring graph‑theoretic formulations of the adjacency constraint, and integrating meta‑heuristics for very large‑scale real‑world applications such as content recommendation systems.
Comments & Academic Discussion
Loading comments...
Leave a Comment