Skip to main content
Log in

Learning-augmented algorithms for online subset sum

  • Published:
Journal of Global Optimization Aims and scope Submit manuscript

Abstract

As one of Karp’s 21 NP-complete problems, the subset sum problem, as well as its generalization, has been well studied. Among the rich literature, there is little work on the online version, where items arrive over list and irrevocable decisions on packing them or not must be made immediately. Under the online setting, no deterministic algorithms are competitive, while for randomized algorithms the best competitive ratio is 1/2. It is thus of great interest to improve the performance bounds for both deterministic and randomized algorithms, assuming predicted information is available in the learning-augmented model. Along this line, we revisit online subset sum by showing that, with learnable predictions, there exist learning-augmented algorithms to break through the worst-case bounds on competitive ratio. The theoretical results are also experimentally verified, where we come up with a new idea in designing experiments. Namely, we design neural networks to serve as adversaries, verifying the robustness of online algorithms. Under this framework, several networks are trained to select adversarial instances and the results show that our algorithms are competitive and robust.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Fig. 1
Fig. 2
Fig. 3

Similar content being viewed by others

Availability of data and material:

All data sets used in the paper are public and can be downloaded through the links provided by the paper.

Code Availability

All codes are available at the github link given in the paper.

Notes

  1. All experiments are conducted on a machine running Ubuntu 18.04 with an i7-7800X CPU, a RTX 2080Ti GPU and 48 GB memory. Code is available at https://github.com/Chenyang-1995/Online-Subset-Sum

  2. More experimental details are deferred to Appendix 1.

References

  1. Anand, K., Ge, R., Panigrahi, D.: Customizing ML predictions for online algorithms. In: Proceedings of the 37th International Conference on Machine Learning, ICML 2020, 13-18 July 2020, Virtual Event, Proceedings of Machine Learning Research, vol. 119, pp. 303–313. PMLR (2020). http://proceedings.mlr.press/v119/anand20a.html

  2. Antoniadis, A., Coester, C., Eliás, M., Polak, A., Simon, B.: Online metric algorithms with untrusted predictions. In: Proceedings of the 37th International Conference on Machine Learning, ICML 2020, 13-18 July 2020, Virtual Event, Proceedings of Machine Learning Research, vol. 119, pp. 345–355. PMLR (2020). http://proceedings.mlr.press/v119/antoniadis20a.html

  3. Antoniadis, A., Gouleakis, T., Kleer, P., Kolev, P.: Secretary and online matching problems with machine learned advice. In: Advances in Neural Information Processing Systems 33: Annual Conference on Neural Information Processing Systems 2020, NeurIPS 2020, December 6-12, 2020, virtual (2020). https://proceedings.neurips.cc/paper/2020/hash/5a378f8490c8d6af8647a753812f6e31-Abstract.html

  4. Bamas, É., Maggiori, A., Rohwedder, L., Svensson, O.: Learning augmented energy minimization via speed scaling. In: H. Larochelle, M. Ranzato, R. Hadsell, M. Balcan, H. Lin (eds.) Advances in Neural Information Processing Systems 33: Annual Conference on Neural Information Processing Systems 2020, NeurIPS 2020, December 6-12, 2020, virtual (2020). https://proceedings.neurips.cc/paper/2020/hash/af94ed0d6f5acc95f97170e3685f16c0-Abstract.html

  5. Bamas, É., Maggiori, A., Svensson, O.: The primal-dual method for learning augmented algorithms. In: Advances in Neural Information Processing Systems 33: Annual Conference on Neural Information Processing Systems 2020, NeurIPS 2020, December 6-12, 2020, virtual (2020). https://proceedings.neurips.cc/paper/2020/hash/e834cb114d33f729dbc9c7fb0c6bb607-Abstract.html

  6. Bhaskara, A., Cutkosky, A., Kumar, R., Purohit, M.: Online learning with imperfect hints. In: Proceedings of the 37th International Conference on Machine Learning, ICML 2020, 13-18 July 2020, Virtual Event, Proceedings of Machine Learning Research, vol. 119, pp. 822–831. PMLR (2020). http://proceedings.mlr.press/v119/bhaskara20a.html

  7. Dey, R., Salem, F.M.: Gate-variants of gated recurrent unit (GRU) neural networks. In: IEEE 60th International Midwest Symposium on Circuits and Systems, MWSCAS 2017, Boston, MA, USA, August 6-9, 2017, pp. 1597–1600 (2017). https://doi.org/10.1109/MWSCAS.2017.8053243

  8. Diao, R., Liu, Y., Dai, Y.: A new fully polynomial time approximation scheme for the interval subset sum problem. J. Glob. Optim. 68(4), 749–775 (2017). https://doi.org/10.1007/s10898-017-0514-0

    Article  MathSciNet  MATH  Google Scholar 

  9. Garey, M.R., Johnson, D.S.: Computers and intractability: A guide to the theory of NP-completeness. Freeman, W. H (1979)

    MATH  Google Scholar 

  10. Gollapudi, S., Panigrahi, D.: Online algorithms for rent-or-buy with expert advice. In: Proceedings of the 36th International Conference on Machine Learning, ICML 2019, 9-15 June 2019, Long Beach, California, USA, Proceedings of Machine Learning Research, vol. 97, pp. 2319–2327. PMLR (2019). http://proceedings.mlr.press/v97/gollapudi19a.html

  11. Gupta, R., Roughgarden, T.: A PAC approach to application-specific algorithm selection. SIAM J. Comput. 46(3), 992–1017 (2017). https://doi.org/10.1137/15M1050276

    Article  MathSciNet  MATH  Google Scholar 

  12. Han, X., Kawase, Y., Makino, K.: Randomized algorithms for online knapsack problems. Theor. Comput. Sci. 562, 395–405 (2015). https://doi.org/10.1016/j.tcs.2014.10.017

    Article  MathSciNet  MATH  Google Scholar 

  13. Ibarra, O.H., Kim, C.E.: Fast approximation algorithms for the knapsack and sum of subset problems. J. ACM 22(4), 463–468 (1975). https://doi.org/10.1145/321906.321909

    Article  MathSciNet  MATH  Google Scholar 

  14. Jiang, Z., Panigrahi, D., Sun, K.: Online algorithms for weighted paging with predictions. In: 47th International Colloquium on Automata, Languages, and Programming, ICALP 2020, July 8-11, 2020, Saarbrücken, Germany (Virtual Conference), LIPIcs, vol. 168, pp. 69:1–69:18. Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2020). https://doi.org/10.4230/LIPIcs.ICALP.2020.69

  15. Kellerer, H., Mansini, R., Pferschy, U., Speranza, M.G.: An efficient fully polynomial approximation scheme for the subset-sum problem. J. Comput. Syst. Sci. 66(2), 349–370 (2003). https://doi.org/10.1016/S0022-0000(03)00006-0

    Article  MathSciNet  MATH  Google Scholar 

  16. Kellerer, H., Pferschy, U.: A new fully polynomial time approximation scheme for the knapsack problem. J. Comb. Optim. 3(1), 59–71 (1999). https://doi.org/10.1023/A:1009813105532

    Article  MathSciNet  MATH  Google Scholar 

  17. Kothari, A., Suri, S., Zhou, Y.: Interval subset sum and uniform-price auction clearing. In: L. Wang (ed.) Computing and Combinatorics, 11th Annual International Conference, COCOON 2005, Kunming, China, August 16-29, 2005, Proceedings, Lecture Notes in Computer Science, vol. 3595, pp. 608–620. Springer (2005). https://doi.org/10.1007/11533719_62

  18. Lattanzi, S., Lavastida, T., Moseley, B., Vassilvitskii, S.: Online scheduling via learned weights. In: Proceedings of the 2020 ACM-SIAM Symposium on Discrete Algorithms, SODA 2020, Salt Lake City, UT, USA, January 5-8, 2020, pp. 1859–1877. SIAM (2020). https://doi.org/10.1137/1.9781611975994.114

  19. Lavastida, T., Moseley, B., Ravi, R., Xu, C.: Learnable and instance-robust predictions for online matching, flows and load balancing. In: P. Mutzel, R. Pagh, G. Herman (eds.) 29th Annual European Symposium on Algorithms, ESA 2021, September 6-8, 2021, Lisbon, Portugal (Virtual Conference), LIPIcs, vol. 204, pp. 59:1–59:17. Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2021). https://doi.org/10.4230/LIPIcs.ESA.2021.59

  20. Lykouris, T., Vassilvitskii, S.: Competitive caching with machine learned advice. In: Proceedings of the 35th International Conference on Machine Learning, ICML 2018, Stockholmsmässan, Stockholm, Sweden, July 10-15, 2018, Proceedings of Machine Learning Research, vol. 80, pp. 3302–3311. PMLR (2018). http://proceedings.mlr.press/v80/lykouris18a.html

  21. Ma, W., Simchi-Levi, D., Zhao, J.: A competitive analysis of online knapsack problems with unit density. SSRN Electronic Journal (2019)

  22. Magazine, M.J., Oguz, O.: A fully polynomial approximation algorithm for the 0–1 knapsack problem. Eur. J. Oper. Res. 8(3), 270–273 (1981)

    Article  MathSciNet  MATH  Google Scholar 

  23. Pisinger, D.: Linear time algorithms for knapsack problems with bounded weights. J. Algorithm 33(1), 1–14 (1999). https://doi.org/10.1006/jagm.1999.1034

    Article  MathSciNet  MATH  Google Scholar 

  24. Purohit, M., Svitkina, Z., Kumar, R.: Improving online algorithms via ML predictions. In: Advances in Neural Information Processing Systems 31: Annual Conference on Neural Information Processing Systems 2018, NeurIPS 2018, December 3-8, 2018, Montréal, Canada, pp. 9684–9693 (2018). http://papers.nips.cc/paper/8174-improving-online-algorithms-via-ml-predictions

  25. Rohatgi, D.: Near-optimal bounds for online caching with machine learned advice. In: Proceedings of the 2020 ACM-SIAM Symposium on Discrete Algorithms, SODA 2020, Salt Lake City, UT, USA, January 5-8, 2020, pp. 1834–1845. SIAM (2020). https://doi.org/10.1137/1.9781611975994.112

  26. Wei, A.: Better and simpler learning-augmented online caching. In: Approximation, Randomization, and Combinatorial Optimization. Algorithms and Techniques, APPROX/RANDOM 2020, August 17-19, 2020, Virtual Conference, LIPIcs, vol. 176, pp. 60:1–60:17. Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2020). https://doi.org/10.4230/LIPIcs.APPROX/RANDOM.2020.60

  27. Yao, A.C.: Probabilistic computations: Toward a unified measure of complexity (extended abstract). In: 18th Annual Symposium on Foundations of Computer Science, Providence, Rhode Island, USA, 31 October - 1 November 1977, pp. 222–227. IEEE Computer Society (1977). https://doi.org/10.1109/SFCS.1977.24

Download references

Acknowledgements

We would like to thank the two anonymous reviewers for their carefully reading and insightful comments, which greatly help improve the presentation of this paper. The work is supported in part by Science and Technology Innovation 2030 - “The Next Generation of Artificial Intelligence” Major Project No.2018AAA0100902, China, and NSFC (12131003).

Funding

Supported in part by Science and Technology Innovation 2030 - “The Next Generation of Artificial Intelligence” Major Project No.2018AAA0100902, China, and NSFC (12131003).

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Guochuan Zhang.

Ethics declarations

Conflicts of interest:

The authors have no conflicts of interest to declare that are relevant to the content of this article.

Additional information

Publisher's Note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Appendices

A The learnability of predictions

In this section, we show that our predictions are efficiently learnable by proving the following theorem.

Theorem 8

Assume that each online subset sum instance I is sampled from an unknown distribution \(\mathcal {I}\) and each item size belongs to a finite set \(\mathcal {F}\). For each proposed algorithm, any \(\epsilon >0\) and \(\delta \in (0,1)\), there exists a learning algorithm which \((\epsilon ,\delta )\)-learns the prediction from \(O\left( \frac{1}{\epsilon ^2}\left( \log (|\mathcal {F}|) \right) + \ln \left( \frac{1}{\delta }\right) \right) \) training instances.

We start by introducing several definitions used here.

Definition 1

[11] Assume each instance \(\mathcal {I}\) is sampled from a distribution \(\mathcal {D}\). For an augmenting Algorithm A, let \(s^*\) be the prediction with maximum \(\mathrm {E}_{\mathcal {I}\sim \mathcal {D}}(A(\mathcal {I},s^*))\), where \(A(\mathcal {I},s^*)\) is the objective value of Algorithm A with prediction \(s^*\) on instance \(\mathcal {I}\). A learning Algorithm L \((\epsilon ,\delta )\)-learns the prediction from m samples if for any distribution \(\mathcal {D}\), with probability at least \(1-\delta \) over m samples \(\mathcal {I}_1,...,\mathcal {I}_m \sim \mathcal {D}\), L outputs a prediction \(\hat{s}\) such that

$$\begin{aligned} |\mathrm {E}_{\mathcal {I}\sim \mathcal {D}}(A(\mathcal {I},\hat{s}))-\mathrm {E}_{\mathcal {I}\sim \mathcal {D}}(A(\mathcal {I},s^*))| \le \epsilon .\end{aligned}$$

Definition 2

[11] Let \(\mathcal {H}\) denote a set of real-valued functions defined on the set X. A finite subset \(S = {x_1,...,x_m}\subseteq X\) is (pseudo-)shattered by \(\mathcal {H}\) if there exist real-valued witnesses \(r_1,...,r_m\) such that for each of the \(2^m\) subsets T of S, there exists a function \(h\in \mathcal {H}\) such that \(h(x_i)>r_i\) if and only if \(i\in T\) (for \(i=1,2,..m\)). The pseudo-dimension \(d_{\mathcal {H}}\) of \(\mathcal {H}\) is the cardinality of the largest subset shattered by \(\mathcal {H}\).

From the definition of pseudo-dimension, we have the following observation.

Observation 1

If \(\mathcal {H}\) is a finite set, its pseudo-dimension \(d_{\mathcal {H}}\) is at most \(\log (|\mathcal {H}|)\).

Proof

Consider a subset \(S\subseteq X\). If \(\mathcal {H}\) shatters it, there exists a unique function \(h\in \mathcal {H}\) corresponding to each subset \(T\subseteq S\). Thus, if \(|\mathcal {H}| < 2^{|S|}\), \(\mathcal {H}\) cannot shatter S because there is no bijection between \(\mathcal {H}\) and the power set of S. In other words, if S is shattered by \(\mathcal {H}\), we have \(|S| \le \log (|\mathcal {H}|)\). Certainly, the cardinality of the largest subset shattered by \(\mathcal {H}\) is also at most \(\log (|\mathcal {H}|)\), completing this proof. \(\square \)

Definition 3

[11] Given a finite set of training instances \(\{\mathcal {I}_1,...,\mathcal {I}_m\}\), say an algorithm is an empirical risk minimization (ERM) algorithm of an augmenting algorithm A, if it always returns a prediction \(\hat{s}\) with minimum \(\sum _{j=1}^{m}A(\mathcal {I}_j,\hat{s})\), where \(A(\mathcal {I}_j,\hat{s})\) is the objective value of Algorithm A with prediction \(\hat{s}\) on instance \(\mathcal {I}_j\).

Rishi Gupta and Tim Roughgarden [11] give a theorem connecting the above three definitions. Putting that theorem into our augmenting algorithm context, we have

Theorem 9

[11] If any prediction \(\hat{s}\) belongs to a finite set \(\mathcal {H}\) and the objective value of the problem (e.g. subset sum) ranges in [0, H], for an augmenting algorithm, its any ERM algorithm \((\epsilon ,\delta )\)-learns the optimal prediction from \(O\left( \left( \frac{H}{\epsilon }\right) ^2\left( d_{\mathcal {H}} + \ln \left( \frac{1}{\delta }\right) \right) \right) \) training instances given any \(\epsilon > 0\) and \(\delta \in (0,1)\).

Proof of Theorem 8

For the online subset sum problem, its objective value is at most 1 since we assume that size of knapsack is 1. If any item size is in a finite set \(\mathcal {F}\), the largest item size (in an optimal solution) also belongs to \(\mathcal {F}\), meaning that any prediction \(\hat{s}\in \mathcal {F}\). According to Observation 1, the pseudo-dimension of \(\mathcal {F}\) is at most \(\log (|\mathcal {F}|)\). Thus, applying Theorem 9 to our model completes the proof directly and the claimed learning algorithm is an ERM algorithm, which is directly picking \(\hat{s}\in \mathcal {F}\) with the best average performance in the training instances. \(\square \)

B Worst-case bounds for learning-augmented algorithms

We construct a set of subset sum instances and a probability distribution, and show that the expected ratio of any deterministic algorithm will not be better than a certain value. According to Yao’s principle [27], this value is a worst-case bound for any (randomized) algorithms. Finally, we connect this value to predictions and prediction errors. We see that if the largest item size is predicted, no learning-augmented algorithm has a competitive ratio better than \(1/2+\epsilon \) for any \(\epsilon \) even when \(\eta =0\); if we predict the largest item size in an optimal solution and the prediction error is larger than 0, the competitive ratio of any learning-augmented algorithm is at most \(1/2+\epsilon -\eta \) (Theorem 5).

Inspired by the instance given in [12], we construct a distribution of n input sequences as follows, where \(n=\frac{1}{\epsilon }\). The i-th input sequence is

$$\begin{aligned}\frac{1}{2}+\delta , \frac{1}{2}+\frac{\delta }{2},... \frac{1}{2}+\frac{\delta }{i},\frac{1}{2}-\frac{\delta }{i},\end{aligned}$$

where \(\delta =\epsilon /4\). Obviously, its optimal objective value is 1 by packing the last two items \(\frac{1}{2}+\frac{\delta }{i} \) and \(\frac{1}{2}-\frac{\delta }{i}\). We claim the following lemma.

Lemma 1

If each item sequence is given with probability 1/n, the competitive ratio of any online deterministic algorithm is at most \(\frac{1}{2} + \epsilon - \frac{1}{n}\sum _{i=1}^{n}\frac{\delta }{i}.\)

Proof

The technique in this proof is similar to that in [12]. Say A is a deterministic algorithm, meaning that A has a deterministic policy to deal with large items with size \(>1/2\). Due to the capacity constraint, A has to accept at most one of these large items and reject all the others. If A rejects all items with size \(>1/2\), its competitive ratio is definitely less than \(1/2\le \frac{1}{2}+\epsilon -\eta \). If A chooses a large item to accept, say this item is \(\frac{1}{2} + \frac{\delta }{j}\). Because A is deterministic, it should always reject other large items.

For the input sequence j, A reaches on the optimal solution. For each input sequence \(i<j\), the objective value is at most \(\frac{1}{2}-\frac{\delta }{i}\) since A rejects all large items in these sequence. For each input sequence \(i>j\), the competitive ratio is always \(\frac{1}{2} + \frac{\delta }{j}\). Thus, we have

$$\begin{aligned} \begin{aligned} \frac{E(A)}{\mathrm {OPT}}&= \frac{1}{n}\left( \sum _{i=1}^{j-1} \left( \frac{1}{2} -\frac{\delta }{i}) + 1+\sum _{i=j+1}^{n}( \frac{1}{2} + \frac{\delta }{j}\right) \right) \\&\le \frac{1}{n}\left( \frac{1}{2}(j-1) -\sum _{i=1}^{j-1} \frac{\delta }{i} + (1+ \delta -\frac{\delta }{j})\right. \\&\left. \quad +\sum _{i=j+1}^{n}( \frac{1}{2} +2\delta - \frac{\delta }{i})\right) \\&\le \frac{1}{n}(\frac{1}{2}n + \frac{1}{2}+ 2\delta (n-j+1)) - \frac{1}{n}\sum _{i=1}^{n}\frac{\delta }{i} \\&\le \frac{1}{2} + \frac{1}{n}(\frac{1}{2} +2\delta n)- \frac{1}{n}\sum _{i=1}^{n}\frac{\delta }{i} \\&= \frac{1}{2} + \frac{1}{n}(\frac{1}{2} +2 (\frac{\epsilon }{4}) (\frac{1}{\epsilon }) )- \frac{1}{n}\sum _{i=1}^{n}\frac{\delta }{i} \\&= \frac{1}{2} + \epsilon - \frac{1}{n}\sum _{i=1}^{n}\frac{\delta }{i} . \end{aligned} \end{aligned}$$

\(\square \)

Predicting the largest item. Let the prediction of any constructed instance be \(\frac{1}{2}+\delta \). Clearly, even if given such a prediction for each instance, \(E(A)/\mathrm {OPT}\) is still at most \(1/2+\epsilon \) for any deterministic algorithm A. For the error-free case, we see that knowing the accurate largest item size cannot help to bypass the bound 1/2.

Predicting the largest item in an optimal solution. Let the prediction of any constructed instance be 1/2. Similarly, the bound \(\frac{1}{2} + \epsilon - \frac{1}{n}\sum _{i=1}^{n}\frac{\delta }{i}\) still holds. We can compute the expected prediction error \(E(\eta )=\frac{1}{n}\sum _{i=1}^{n}\frac{\delta }{i}\). Thus, \(E(A) \le 1/2+\epsilon -E(\eta )\) for any deterministic algorithm A. This implies that no learning-augmented algorithm has a competitive ratio better than \(1/2+\epsilon -\eta \) and completes the proof of Theorem 5.

C Training details

This section presents training details of the experiments. An adversary network is a one-layer GRU network with hidden size 32. The input batch size of this network is 5. Each adversary is trained for 50000 epochs by Adam optimizer. The learning rate is 0.001.

Additionally, we use two tricks when sampling instances. One is that when the adversary outputs \(s_i\) in step i, replace \(s_i\) by a random number with probability p, helping avoid local optima. We initialize p by 0.04 and decrease it linearly to 0 as the number of training epoch grows. The other trick is that we always let the last instance of one batch be the instance with highest reward so far, in order to guide the network to a right direction. Without this trick, the adversary will encounter gradients vanishing frequently during its training.

Rights and permissions

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Xu, C., Zhang, G. Learning-augmented algorithms for online subset sum. J Glob Optim 87, 989–1008 (2023). https://doi.org/10.1007/s10898-022-01156-w

Download citation

  • Received:

  • Accepted:

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s10898-022-01156-w

Keywords

Mathematics Subject Classification

Navigation