Optimal Online Algorithms for One-Way Trading and Online Knapsack Problems: A Unified Competitive Analysis
Abstract
We study two canonical online optimization problems under capacity/budget constraints: the fractional one-way trading problem (OTP) and the integral online knapsack problem (OKP) under an infinitesimal assumption. Under the competitive analysis framework, it is well-known that both problems have the same optimal competitive ratio. However, these two problems are investigated by distinct approaches under separate contexts in the literature. There is a gap in understanding the connection between these two problems and the nature of their online algorithm design. This paper provides a unified framework for the online algorithm design, analysis and optimality proof for both problems. We find that the infinitesimal assumption of the OKP is the key that connects the OTP in the analysis of online algorithms and the construction of worst-case instances. With this unified understanding, our framework shows its potential for analyzing other extensions of OKP and OTP in a more systematic manner.
I INTRODUCTION
Online optimization under capacity/budget constraints is a classical and challenging problem. Two well-known examples are the one-way trading problem (OTP) and the online knapsack problem (OKP).
In the OTP, an investor plans to trade a total amount of 1 dollar into yen. The exchange rates arrive online and are bounded, i.e., , and the investor must immediately decide how much to trade at each exchange rate. If dollars are traded at the th exchange rate , is the amount of yen the investor gains. Let denote the total number of exchange rates. The goal is to maximize the amount of yen traded after processing the th exchange rate , while respecting the budget limit . It is well-known that -competitive algorithms can be designed, e.g., the threat-based algorithm in [1] and the CR-Pursuit algorithm in [2].
The 0-1 knapsack problem is a classic problem in computer science, where a decision-maker maximizes the total value of the items selected while the total weight does not exceed the normalized knapsack capacity limit of . In the OKP, the items come one by one. The value and the weight of the th item are only revealed upon its arrival. An online decision is made on whether to accept the item () or not (). There exist no online algorithms with bounded competitive ratios for the OKP in the general setting [3]. However, ()-competitive algorithms can be designed [4, 5, 6] under the bounded value-to-weight ratio assumption (i.e., ) and the infinitesimal assumption that the weight of each item is much smaller than the capacity (i.e., ). The infinitesimal assumption is a technical simplification, but it has been shown to hold in practical applications such as cloud computing systems [6] and is widely accepted in the literature. In this paper, we make the same assumptions.
Both problems have appeared in numerous applications, including portfolio selection, cloud resource allocation, keyword auctions, etc. Thus, considerable attention has been paid to both problems and their many variants. Unbounded prices [7] and interrelated prices [8] have been considered for the OTP recently, and knapsacks with unknown capacity [9] and removable items [10] are interesting generalizations for the OKP. Additionally, different arrival models have been studied, such as stochastic arrivals [11, 12] and random order [13]. In this paper, we make no assumptions on the arrival model.
Motivated by the gaps in the understanding of the nature of challenges in the online algorithm design, we aim to unify the online algorithms for the OTP and the OKP into one algorithmic framework, namely, a threshold-based algorithm, the competitive performance of which mainly depends on the threshold function. We provide a sufficient condition on the threshold function that can ensure a bounded competitive ratio, and design the best possible threshold function based on this sufficient condition. Finally, we derive the lower bound of the competitive ratios of the OTP and the OKP. Although all results match those in the literature, the existing works approach the results by distinct methods and lack a systematic way of designing and analyzing related problems. This paper mainly focuses on the analysis and proofs rather than on the results. Our contributions are two-fold.
-
•
We unify the online algorithms for the OTP and the OKP into a threshold-based algorithm and show that the unified algorithm can achieve the optimal competitive ratios under a unified competitive analysis.
-
•
We provide new proofs for the lower bound of competitive ratios for the OTP and the OKP. The connection between these two problems is founded in the construction of the worst-case instances.
II A UNIFIED ALGORITHM and Our Results
II-A Notations
Since the two problems have originally distinct sets of terms, we unify the notations for the brevity of problem formulation and clarify the different meanings here. Let denote the amount of dollars traded at the th exchange rate for the OTP, while for the OKP, it represents the capacity used after processing the th item . Let denote the exchange rate (i.e., ) in the OTP and the value-to-weight ratio of the th item in the OKP (i.e., ). The following optimization problem characterizes the offline problem of the OTP:
(1) | ||||
The dual problem of (1) is
(2) | ||||
By changing the last constraint of (1) to , the resulting problem serves as an upper bound of the OKP due to the LP relaxation, and its dual is
(3) | ||||
where and s are the dual variables of the corresponding dual programs.
II-B A Unified Algorithm
Both the OTP and the OKP target allocating one budget-constrained resource sequentially. Since the current decision affects the future decisions through the budget constraint, we need an estimation of the value of the remaining resource to facilitate decision-making. We use a threshold function to estimate the value of resources.
Definition 1.
A threshold function estimates the marginal cost of a resource at utilization .
Denote the utilization level after the th arrival by . Given , we can estimate the pseudo-cost of allocating amount of resource by . Our unified algorithm then decides that maximizes the pseudo-revenue . The overall algorithm is summarized in Algorithm 1.
denotes the set of all positive real numbers for the OTP and the set for the OKP, separately. Note that for the OKP, step 1 reduces to , which corresponds to the update equation in [4]. Algorithm 1 can be easily applied in the posted-price setting by its nature.
II-C Main Results
A standard measure for the performance of an online algorithm is the competitive ratio. Under the unified notation, define an arrival instance as for the OTP, and as for the OKP. Denote the objective value achieved by the online algorithm and the offline optimal by and , respectively, given the arrival instance . If , then we say the online algorithm is -competitive. The competitive ratio of Algorithm 1 depends only on the choice of the function . We find the sufficient conditions for for Algorithm 1 to be -competitive in the following theorem.
Theorem 2 (Sufficiency).
Algorithm 1 is -competitive for both the OTP and the OKP if is given by
where is a budget/capacity utilization level that satisfies , and is an increasing function that satisfies
(4) |
In the theorem, is composed of two segments, one constant and the other exponential. Note that the functions used in [4] and [6] satisfy the conditions. However, the basis of the functions is unknown; the authors do not explain the intuition behind the functions nor rigorously characterize the properties of the functions. In contrast, by the following theorem, we can characterize the performance limit over the space of all eligible functions and rigorously show the function that admits the smallest (best) competitive ratio.
Theorem 3.
Given and , the best competitive ratio that can be achieved by Algorithm 1 is , where , and the corresponding is unique.
We show that no other online algorithms can perform better than Algorithm 1 using the following theorem.
Theorem 4.
Given and , is the lowest possible competitive ratio for both the OTP and the OKP.
III COMPETITIVE ANALYSIS
III-A Primal-Dual Competitive Analysis
Given the arrival instance , we denote the primal and dual objective values after processing by and , respectively. For simplicity, we drop the parenthesis and write and hereafter. We briefly introduce the framework by giving the following lemma.
Lemma 1.
An online algorithm is -competitive if it can determine the primal variables and construct dual variables based on the primal variables such that
-
•
(Feasible Solutions) and are feasible solutions of the primal and the dual,
-
•
(Initial Inequality) there exists an index such that ,
-
•
(Incremental Inequalities) for ,
Proof.
The primal feasibility is trivial since any online algorithm must first produce a feasible solution to the problem. It suffices to prove since
where () is due to the dual feasibility, and () is due to the weak duality. Suppose there exists a such that holds for all , then we have Combining this with the initial inequality leads to . We thus complete the proof. ∎
Note that the primal-dual competitive analysis framework that we use is more general than those used in the existing works, in that the initial inequality starts from rather than the original .
III-B Analysis of OTP
Proof of Theorem 2.
(Feasible Solutions) First we show that the primal and dual solutions given by Algorithm 1 are feasible:
(5) |
where . (5) ensures , and ensures . Since , we have . Thus, the primal solutions are feasible. Construct the dual variables as Since is non-decreasing, . Thus, is a feasible solution to the dual.
(Initial Inequality) For the OTP, . When , the primal objective at the end of the th time slot is while the dual objective is
(Incremental Inequalities) Next we show the incremental inequalities for . Note that when , and . In this case, the incremental inequality always holds. Thus, we only need to focus on the case where , when the behavior of the algorithm is controlled by the second segment of , which satisfies for and two boundary conditions and .
The change in the dual objective is given as follows: By the Cauchy mean value theorem, for every segment , there exists a such that
Since , and is increasing, we have Because , we have where the LHS is , and the RHS is . Thus, holds for all .
Therefore, Theorem 2 holds for the OTP. ∎
Theorem 3 characterizes the performance limit of Algorithm 1.
Proof of Theorem 3.
(Best Competitive Ratio) By the differential form of Gronwall’s Inequality [14], if there exists a that satisfies where , it is bounded as follows:
Substituting the first boundary condition , we have If the other boundary condition holds, it implies otherwise , which incurs infeasibility. From the inequality above, we have A necessary condition for to hold is and thus the competitive ratio
( and Its Uniqueness) When takes the smallest possible , the corresponding s satisfy
where and s are given by
(6) |
By Gronwall’s inequality, we have
(7) | ||||
where () is due to . Then we have Combining with the second boundary condition , we have . Substituting this into (7), we have Because as stated in Theorem 2, we have . Therefore, the solution space of (6) is equivalent to the solution space of the following differential inequality with equality boundary conditions:
(8) |
The differential equation counterpart is as follows:
(9) |
The unique solution to (9) is . Suppose is a feasible solution to (8), by Gronwall’s inequality, . Next, we are going to show that the solution of (8) is unique and is exactly .
Suppose for , where . We know that for any , Thus, for , we have
Take the integral of over , we have which can also be expressed as
which shows . Thus, for . In conclusion, the optimal achieving competitive ratio is unique, and
∎
III-C Analysis of OKP
We highlight the differences in the analysis of the OKP. The primal feasibility holds trivially and the dual variables are constructed as follows:
where . When , based on the decision-making rule (Step 1 in the algorithm), we must have . Therefore, . The constraint of the dual problem is
Thus, the dual feasibility holds.
Assume that the online algorithm will accept the first items, and . Also note that . Then we have
Thus, there exists that satisfies the initial inequality.
With regard to the incremental inequalities, we have where is due to the fact and (using the infinitesimal weight assumption). Combining the ODE (4) with the fact that , the incremental inequality holds for . Thus, Theorem 2 holds for the OKP. Note that the proof of Theorem 3 holds generally for the two problems.
IV Lower Bounds
In this section, we show that the lower bound of the OTP and that of the OKP coincide. Denote Algorithm 1 with by . We first present the proofs for the OTP, then call attention to the differences for the OKP case.
IV-A Lower Bounds of OTP
Below we find the family of the worst-case sequences under which incurs a ratio of .
Lemma 2.
Given and , the family of the worst-case sequences of in the OTP are denoted by , where , and the rates satisfy
where s are infinitesimal positive values. The amount traded by at the exchange rate is denoted by , which satisfies
Proof.
The proof of Lemma 2 is in the Appendix. ∎
Proof of Theorem 4.
Let ALG be any online algorithm different from We show that ALG cannot achieve a competitive ratio smaller than by using an adversarial argument.
Let . First present to ALG. If ALG exchanges , then we end the sequence, and on doing so, ALG cannot achieve , because Thus, we can assume that ALG spends an amount , in this case, we continue and present to ALG. In general, if after processing the th exchange rate, the total amount of dollars spent is less than , we immediately end the sequence. Otherwise, we continue to present , etc.
Let . Let , denote the minimum in as , we have
Thus, ALG can gain more by spending exactly the same as at the first exchange rates and by spending at the th exchange rate. Since , ALG cannot guarantee the competitive ratio of . If for all , we have
Since ALG cannot exceed the capacity limit, we have and we also have , therefore, we have For an infinite sequence , the limit exists iff
so we have By the Abel transformation, we have where () is due to the monotonicity of .
Thus, the performance gap between ALG and for this infinite exchange rate sequence is
Therefore, any online algorithm for the OTP cannot achieve a better competitive ratio than . The lowest possible competitive ratio is .
∎
IV-B Lower Bounds of OKP
We show that with a slight modification, are also the worst-case sequences for the OKP.
Consider a family of the value-to-weight ratio sequences indexed by . is composed of a continuum of subsequences, with the ratios in the th subsequence all being , where , which is given in Lemma 2. The length of each subsequence is sufficiently large so that it can fulfill the capacity of the knapsack even if it is presented alone. Note that given , the resource allocation strategy is analogous to the OTP case. The offline optimal solution is to only select from the subsequence with until reaching the capacity limit, whereas will select a value-to-weight ratio as long as it is no less than , where is the current capacity utilization level. Therefore, are the worst-case sequences for the OKP.
With regards to the proof of Theorem 4, one can replace the worst sequence with , present a subsequence instead of an arrival at a time to ALG, and act adversarially in the same way in response to the decisions made by ALG, and the results still hold.
V CONCLUSION
We provide a unified threshold-based algorithm for two well-known online problems, namely, the one-way trading problem and the online knapsack problem. We show the sufficient conditions for the algorithm to have a bounded competitive ratio for both problems via a unified competitive analysis. We reveal the threshold function that can achieve the best (smallest) competitive ratio, show that it matches the lower bounds, and present new proofs for the lower bounds for both problems. This is the first work that introduces the connections between the OTP and the OKP and provides a unified algorithmic framework for both of them, and we believe there is much more to be explored in this direction, i.e., unifying the online algorithm design.
APPENDIX
Proof of Lemma 2.
Denote any strictly-increasing sequence with length by . We can simply focus on the strictly-increasing sequences, because only trades something when the current exchange rate is the new high observed. Any normal sequences can be transformed into a strictly-increasing sequence by keeping the exchange rate higher than all of its predecessors and omitting the rest, and the optimal in hindsight is not affected by this transformation. By (5), we have
Denote the total amount of yen trades for by ALG() and the offline optimal amount by OPT(). We have and
Let . Thus, the competitive ratio for can be expressed as
Because can achieve with by Theorem 3, we know that . Next, we look for that minimize for each . When , , therefore, , and . When ,
The first order derivatives are
We notice that and cannot be zero simultaneously. This means that has no critical points, and the minimum value of on must be on one of the four boundary points. It turns out that reaches minimum when . We need to find a close neighbor to with and whose value does not increase too much. Notice that , increasing to with infinitesimal positive should incur the least inaccuracy, thus, and as . For general ,
The first order derivatives are:
A commonality is that, and cannot be zero at the same time, and reaches minimum when . The increasing sequence closest to the minimum point is , where s are infinitesimal positive values, and we have as Actually, each is the prefix of From these observations, we claim that as long as the exchange rate sequence increases slowly enough from , it is the worst-case sequence for .
To verify the claim, let be , we have
and thus
Since the exchange rate is upper bounded by , by the monotone convergence theorem, we have
and thus . ∎
References
- [1] R. El-Yaniv, A. Fiat, R. M. Karp, and G. Turpin, “Optimal search and one-way trading online algorithms,” Algorithmica, vol. 30, no. 1, pp. 101–139, 2001.
- [2] Q. Lin, H. Yi, J. Pang, M. Chen, A. Wierman, M. Honig, and Y. Xiao, “Competitive online optimization under inventory constraints,” Proceedings of the ACM on Measurement and Analysis of Computing Systems, vol. 3, no. 1, pp. 1–28, 2019.
- [3] M. Babaioff, N. Immorlica, D. Kempe, and R. Kleinberg, “A knapsack secretary problem with applications,” in Approximation, randomization, and combinatorial optimization. Algorithms and techniques. Springer, 2007, pp. 16–28.
- [4] Y. Zhou, D. Chakrabarty, and R. Lukose, “Budget constrained bidding in keyword auctions and online knapsack problems,” in International Workshop on Internet and Network Economics. Springer, 2008, pp. 566–576.
- [5] X. Tan, B. Sun, A. Leon-Garcia, Y. Wu, and D. H. Tsang, “Mechanism design for online resource allocation: A unified approach,” Proc. ACM Meas. Anal. Comput. Syst., vol. 4, no. 2, June 2020. [Online]. Available: https://doi.org/10.1145/3392142
- [6] Z. Zhang, Z. Li, and C. Wu, “Optimal posted prices for online cloud resource allocation,” Proceedings of the ACM on Measurement and Analysis of Computing Systems, vol. 1, no. 1, pp. 1–26, 2017.
- [7] F. Y. Chin, B. Fu, J. Guo, S. Han, J. Hu, M. Jiang, G. Lin, H.-F. Ting, L. Zhang, Y. Zhang, et al., “Competitive algorithms for unbounded one-way trading,” Theoretical Computer Science, vol. 607, pp. 35–48, 2015.
- [8] P. Schroeder, R. Dochow, and G. Schmidt, “Optimal solutions for the online time series search and one-way trading problem with interrelated prices and a profit function,” Computers & Industrial Engineering, vol. 119, pp. 465–471, 2018.
- [9] Y. Disser, M. Klimm, N. Megow, and S. Stiller, “Packing a knapsack of unknown capacity,” SIAM Journal on Discrete Mathematics, vol. 31, no. 3, pp. 1477–1497, 2017.
- [10] X. Han, Y. Kawase, and K. Makino, “Randomized algorithms for removable online knapsack problems,” in Frontiers in Algorithmics and Algorithmic Aspects in Information and Management. Springer, 2013, pp. 60–71.
- [11] L. Tran-Thanh, Y. Xia, T. Qin, and N. R. Jennings, “Efficient algorithms with performance guarantees for the stochastic multiple-choice knapsack problem,” in Twenty-Fourth International Joint Conference on Artificial Intelligence, 2015.
- [12] H. Fujiwara, K. Iwama, and Y. Sekiguchi, “Average-case competitive analyses for one-way trading,” Journal of Combinatorial Optimization, vol. 21, no. 1, pp. 83–107, 2011.
- [13] S. Albers, A. Khan, and L. Ladewig, “Improved online algorithms for knapsack and gap in the random order model,” in Approximation, Randomization, and Combinatorial Optimization. Algorithms and Techniques (APPROX/RANDOM 2019). Schloss Dagstuhl-Leibniz-Zentrum fuer Informatik, 2019.
- [14] D. S. Mitrinovic, J. Pecaric, and A. M. Fink, Inequalities involving functions and their integrals and derivatives. Springer Science & Business Media, 1991, vol. 53.