online-section1-new
個人讀書筆記,歡迎大家批評指正、交流
An Introduction to Online Computation
Authors Komm, Dennis
文章目錄
- 1 Introduction
- 1.1 Offline Algorithms
- 1.2 Online Algorithms and Paging
- Online Problem
- Online Algorithms
- Competitive Ratio
- Theorem 1.2,1.3
- Paging
- pageingproblempageing\; problempageingproblem
- 1.3 An Upper Bound for Paging
- k?k-k?Phase Partition
- Theorem 1.4 Fifo is strictly k-competitive for paging
- 1.4 A Lower Bound for Paging:k-compititive
- Theorem 1.5 No online algorithm for paging is better than k-compititive?
- Theorem 1.6 LIFO is not competitive for paging
- Theorem 1.7 LFU(使用頻率最低) is not competitive for paging
- 1.5 Marking Algorithms
- Theorem 1.8. Every marking algorithm is strictly kkk-competitive for paging
- Theorem 1.9. LRU is a marking algorithm
- 1.6 Refined Competitive Analysis
- lookahead
- No online algorithm with lookahead ?\ell? for paging is better than kkk competitive.
- resource augmentation
- (h,k)-paging problem
- Every marking algorithm is k/(k-h+1)-competitive for (h,k)-paging
- Every marking algorithm is k/(k-h+1)-competitive for (h,k)-paging
1 Introduction
Online computation, that is, algorithms that work on problem instances which they do not know from the start, but that get revealed piece by piece. These algorithms are called online algorithms, and they are commonly analyzed using so-called competitive analysis, which compares their solution to an optimal one.
在線計算,也就是在問題實例上工作的算法,這些問題實例他們從一開始并不知道,但逐漸顯露出來。這些算法被稱為在線算法,通常使用所謂的競爭分析來分析它們,將它們的解與最優(yōu)解進行比較。
1.1 Offline Algorithms
停機問題,P,NP,NPC,NP-hard,優(yōu)化問題的定義
近似算法:
對于最大化問題:
? gain(OPT(I))≤r?gain(gain(I))gain(OPT(I))\le r\cdot gain(gain(I))gain(OPT(I))≤r?gain(gain(I)),
? $\frac {gain(OPT(I)) } { gain(ALG(I))} \le r $
對于最小化問題:
? cost(ALG(I))≤r?cost(ALG(I))cost(ALG(I))\le r\cdot cost(ALG(I))cost(ALG(I))≤r?cost(ALG(I)),
? $\frac {cost(ALG(I)) } { cost(OPT(I))}\le r $
背包問題
1.2 Online Algorithms and Paging
Online Problem
? problem:Π\PiΠ
? instances:I\mathcal{I}I
? solutions:O\mathcal{O}O
? instance: I∈II\in\mathcal{I}I∈I is a sequence of requestsrequestsrequests I=(x1,x2,...,xn)I=(x_1,x_2,...,x_n)I=(x1?,x2?,...,xn?)
? output: $O\in\mathcal{O} $is a sequence of answersanswersanswers O=(y1,y2,...,yn)O=(y_1,y_2,...,y_n)O=(y1?,y2?,...,yn?)
? n∈N+n\in\mathbb{N^+}n∈N+,i.e. all instances and solutions are finite
? onlineminimizationproblemonline \; minimization \; problemonlineminimizationproblem:
? cost(I,OPT(I))=mincost(I,O)∣O∈sol(I)cost(I,OPT(I))=min{cost(I,O)|O\in sol(I)}cost(I,OPT(I))=mincost(I,O)∣O∈sol(I)
? onlinemaximizationproblemonline \; maximization \; problemonlinemaximizationproblem:
? gain(I,OPT(I))=maxgain(I,O)∣O∈sol(I)gain(I,OPT(I))=max{gain(I,O)|O\in sol(I)}gain(I,OPT(I))=maxgain(I,O)∣O∈sol(I)
Online Algorithms
? Online problem : Π\PiΠ
? An instance of Π\PiΠ: I=(x1,x2,...,xn)I=(x_1,x_2,...,x_n)I=(x1?,x2?,...,xn?)
? An onlinealgorithmonline \; algorithmonlinealgorithm ALG for Π\PiΠ computes the output ALG(I)=(y1,y2,...,yn)ALG(I)=(y_1,y_2,...,y_n)ALG(I)=(y1?,y2?,...,yn?), where yiy_iyi? only depends on x1,x2,...,xix_1,x_2,...,x_ix1?,x2?,...,xi?,and y1,y2,...,yi?1y_1,y_2,...,y_{i-1}y1?,y2?,...,yi?1?, $ALG(I) $is a feasible solution for III,that is , ALG(I)∈sol(I)ALG(I) \in sol(I)ALG(I)∈sol(I).
Competitive Ratio
? Online problem : Π\PiΠ
? Online algorithm : ALGALGALG
? For c≥1c \ge 1c≥1,ALGALGALG is c?competitivec-competitivec?competitive for Π\PiΠ if there is a non-negative constant α\alphaα such that, for every instance I∈II \in \mathcal{I}I∈I,
? for an online maximization problem,
? gain(OPT(I))≤r?gain(gain(I))+αgain(OPT(I))\le r\cdot gain(gain(I))+\alphagain(OPT(I))≤r?gain(gain(I))+α,
? for an online minimization problem,
? cost(ALG(I))≤r?cost(ALG(I))+αcost(ALG(I))\le r\cdot cost(ALG(I))+\alphacost(ALG(I))≤r?cost(ALG(I))+α,
if α=0\alpha=0α=0, we call ALGstrictlyc?competitiveALG \;strictly\; c-competitiveALGstrictlyc?competitive ,ALGALGALG is called if it is strictly 1-competitive.
cALGc_{ALG}cALG?
stronglycALG?competitivestrongly \;c_{ALG}-competitivestronglycALG??competitive
近似比和競爭比考慮的都是當(dāng)前算法的worst?caseworst-caseworst?case
competitiveanalysiscompetitive\;analysiscompetitiveanalysis
As with the approximation ratio, the competitive ratio is not necessarily constant, but may be a function of the input length nnn .We use the following terminology. 競爭比不一定是一個常數(shù),可能是與輸入長度n有關(guān)的函數(shù)
notcompetitivenot\; competitivenotcompetitive :如果在線算法不具有與輸入長度無關(guān)的競爭比的上界???
即,算法的上界,應(yīng)該與輸入長度無關(guān),這樣才能是competitive的
α\alphaα這個常數(shù)是必不可少的
Theorem 1.2,1.3
? 對于最小化/最大化問題,there is no online algorithm that is "better than c?competitvec-competitvec?competitve"
Paging
phasesphasesphases:consist of a number of consecutive(連續(xù)的) time steps.
c是任何分頁在線算法競爭比的下界
pageingproblempageing\; problempageingproblem
? minimization
? In memory: p1,...,pmp_1,...,p_mp1?,...,pm?
? Instance: I=(x1,x2,...,xn)I=(x_1,x_2,...,x_n)I=(x1?,x2?,...,xn?), such that xi∈{p1,...,pm}x_i\in \{p_1,...,p_m\}xi?∈{p1?,...,pm?}
? xix_ixi?is requested in time Step TiT_iTi?,
ALGALGALG for paging maintains a cache memory of size kkk with k<mk < mk<m .
time step TiT_iTi?,cache 中存的東西:Bi={pj1,pj2,...,pjk}B_i=\{p_{j1},p_{j2},...,p_{jk}\}Bi?={pj1?,pj2?,...,pjk?}
B0={p1,p2,...,pk}B_0=\{p_{1},p_{2},...,p_{k}\}B0?={p1?,p2?,...,pk?}
如果TiT_iTi?請求的page在Bi?1B_{i-1}Bi?1?中,命中,cost=0,如果不在,選一個yiy_iyi?置換出去,ALGALGALG outputs yi=pjy_i=p_jyi?=pj?
cost(ALG(I)ALG(I)ALG(I))=|{i∣yi≠0i|y_i\ne0i∣yi??=0}|,下標(biāo)是集合的大小?
the goal is to minimize this number.
demandpagingalgorithmsdemand \;paging \;algorithmsdemandpagingalgorithms:每次只替換出一頁,請求分頁算法
Strategies:FIFO,LIFO,LFU(使用頻率最低),LRU,FWF(flush when full),LFD(離線算法,remove 之后最晚被請求的)
1.3 An Upper Bound for Paging
這里是在算上界,也就是說,求cost(ALG(I))cost(ALG(I))cost(ALG(I))max,和cost(OPT(I))cost(OPT(I))cost(OPT(I))min
先介紹些東西,以便于證明上界。
在上一節(jié)中,我們定義了一個在線算法是競爭的,如果它的競爭比c是與輸入長度相關(guān)的一個常數(shù)。
在分頁問題中,c與k,m相關(guān)?
k?k-k?Phase Partition
k步劃分,針對輸入,而不針對算法
instance:I=(x1,x2,...,xn)I=(x_1,x_2,...,x_n)I=(x1?,x2?,...,xn?)
A 𝑘-phase partition of 𝐼 assigns the requests from 𝐼 to consecutive disjoint phases 𝑃1, 𝑃2, . . . , 𝑃𝑁 such that
段P1P_1P1?開始于第一個不在最初緩存的被請求的頁面。P1P_1P1?包含I的最大長度子序列,最多包含k個不同的頁面
對于第k個還是第k+1個的說明:
不是說探測到第k個不同的頁面就結(jié)束了,萬一之后的還都是與之前重復(fù)的呢?所以是遇到第k+1個不同的頁面之前
P2P_2P2?~PNP_NPN?是III的最大子序列,從Pi?1P_{i-1}Pi?1?開始,最多是k個不同的頁面
Pi+1P_{i+1}Pi+1?中的第一個請求頁面,不同于PiP_{i}Pi?中的所有頁面
觀察在右移之后的Pi′P_i^{'}Pi′?,與Pi′P_i^{'}Pi′?開始之前請求的最后一個頁面相比,有k個不同的頁面,
Theorem 1.4 Fifo is strictly k-competitive for paging
對于Pi,(1≤i≤N)P_i,(1\le i\le N)Pi?,(1≤i≤N),最多引起kkk次page fault
設(shè)ppp是PiP_iPi?中第一個引起fault的頁面,所以要把ppp緩存進cache,此時cache中,在ppp前面還有k-1個與p不同的頁面,所以在之后的k-1次置換中,ppp一直都在cache中,而在PiP_iPi?中,除了ppp也就還剩下k-1個不同的頁面,所以during PiP_iPi?,沒有能夠引起兩次fault的頁面,因此,對于Pi,(1≤i≤N)P_i,(1\le i\le N)Pi?,(1≤i≤N),最多也就引起kkk次page fault
對于NNN個PPP,最多引起N?kN \cdot kN?k次fault
OPT(I)OPT(I)OPT(I)has to make at least one page fault for every phase.
考慮example1.3
input:
cache的初始狀態(tài):(p1,p2,p3,p4,p5)(p_1,p_2,p_3,p_4,p_5)(p1?,p2?,p3?,p4?,p5?)
然后用phase表示一下:
再移動一下,以便于分析,
考慮一般情況,首先,xix_ixi?是第一個引起fault的(就是從P1P_1P1?移動到P1′P_1^{'}P1′?的時候移出去的,P1P_1P1?的定義就是以第一個fault開頭的)
對于$P_i^{’},1\le i\le N-1 ,,,P_{i-1}{’}$中最后一個頁面$p{’},在,在,在P_i{’}$開始之前,$p{’}一定在cache中,但是一定在cache中,但是一定在cache中,但是P_i{’}$中還有與$p{’}不同的k個頁面呢,就算cache中其余k?1個位置存的都是不同的k個頁面呢,就算cache中其余k-1個位置存的都是不同的k個頁面呢,就算cache中其余k?1個位置存的都是P_i^{’}中所需要的頁面,那至少也要fault一次了,因此,中 所需要的頁面,那至少也要fault一次了,因此,中所需要的頁面,那至少也要fault一次了,因此,P_i^{’},1\le i\le N-1 ,每個1次,一共就是,每個1次,一共就是,每個1次,一共就是N-1次,再加上次,再加上次,再加上x_i,一共就是,一共就是,一共就是N$次。
PNP_NPN?是一定不產(chǎn)生fault,還是說是為了計算at least給舍去了?,我覺得是給舍去了
綜合1.和2.,計算得到
cost(ALG(I))cost(OPT(I))=N?kN=k\frac {cost(ALG(I))} {cost(OPT(I))}=\frac{N \cdot k}{N}=kcost(OPT(I))cost(ALG(I))?=NN?k?=k
//這里是在算上界,也就是說,求cost(ALG(I))cost(ALG(I))cost(ALG(I))max,和cost(OPT(I))cost(OPT(I))cost(OPT(I))min????
1.4 A Lower Bound for Paging:k-compititive
這里是在算下界,也就是說,求cost(ALG(I))cost(ALG(I))cost(ALG(I))min,和cost(OPT(I))cost(OPT(I))cost(OPT(I))max?
有沒有比FIFO,FWF,LRU更好的在線算法呢?沒了
在考慮worst?caseworst-caseworst?case的情況下,至少也是OPTOPTOPT的kkk倍
adversary(對手,敵人) V.S. ALGALGALG
adversary想讓cost(ALG(I))cost(ALG(I))cost(ALG(I))越大越好,這樣競爭比也就更大了
我們考慮一個請求分頁問題(每次只置換一個,滿了才置換)
Theorem 1.5 No online algorithm for paging is better than k-compititive?
adversary(對手)構(gòu)造的實例,總是知道ALG想替換出什么,然后ALG就總是fault,
OPT就選擇成LFD,是一個離線算法,總是能替換出之后不需要的page
分段,然后分析
cost(ALG(I))=n=c?kcost(ALG(I))=n=c\cdot kcost(ALG(I))=n=c?k
cost(OPT(I))≤ccost(OPT(I))\le ccost(OPT(I))≤c?
cost(ALG(I))cost(OPT(I))≥k\frac{cost(ALG(I))}{cost(OPT(I))}\ge kcost(OPT(I))cost(ALG(I))?≥k?
cost(ALG(I))=n=c?kcost(ALG(I))=n=c\cdot kcost(ALG(I))=n=c?k
如果cost(OPT(I))cost(OPT(I))cost(OPT(I))是常數(shù),那么競爭比就是n了,那就not competitive(如果隨著n的增長而增長,根據(jù)[定理1.2](#Theorem 1.2,1.3),可知沒有比k更小的競爭比)
如果競爭比是常數(shù),就是competitive,如果競爭比隨著n按比例變化,就是not competitive
Theorem 1.6 LIFO is not competitive for paging
memory的大小是mmm,即一共有mmm個頁面
cache的大小是kkk,即一種只能在緩存中存kkk個頁面
cache中初始化為
{p1,p2,...,pk}\{p_1,p_2,...,p_k\} {p1?,p2?,...,pk?}
To this end,為此構(gòu)造實例,實例長度為n
{pk+1,pi,pk+1,pi,pk+1,pi,pk+1,pi,...}\{p_{k+1},p_i,p_{k+1},p_i,p_{k+1},p_i,p_{k+1},p_i,...\} {pk+1?,pi?,pk+1?,pi?,pk+1?,pi?,pk+1?,pi?,...}
cost(LIFO(I))=ncost(LIFO(I))=ncost(LIFO(I))=n
cost(OPT(I))=1cost(OPT(I))=1cost(OPT(I))=1
Theorem 1.7 LFU(使用頻率最低) is not competitive for paging
就也是構(gòu)造一個實例,然后來證明這是not competitive的
1.5 Marking Algorithms
This class of algorithms plays an important role in the context(環(huán)境) of randomized computation for paging.
Marking Algorithm:
開始處理請求之前,所有的都標(biāo)記
分段工作,標(biāo)記已經(jīng)被請求過的pages,只替換沒被標(biāo)記過的
如果全都標(biāo)記過了,還發(fā)生了一次page fault,結(jié)束當(dāng)前phase,
取消所有標(biāo)記,開始新的phase
concept,概念
Theorem 1.8. Every marking algorithm is strictly kkk-competitive for paging
Theorem 1.9. LRU is a marking algorithm
To prove the claim means to show that Lru never removes a page that is
currently marked by some marking algorithm.
For a contradiction,矛盾
反證法
PiP_iPi?中只能至多有kkk個不同的page,因為是 k?phasek-phasek?phase partition
證明出現(xiàn)矛盾:PiP_iPi?出現(xiàn)k+1個page
https://riptutorial.com/algorithm/example/25916/paging–online-caching-
FWF is also a marking algorithm
LFU and LIFO is no marking algorithm,and not competitive
FIFO is no marking algorithm,but strictly k-competitive
1.6 Refined Competitive Analysis
Refined,細致的,精確的
lookahead
with lookahead ?\ell?,ALG?ALG_\ellALG?? sees the current request together with the subsequent ?\ell? requests
adversary對手依舊是知道ALG?ALG_\ellALG?? 的工作流程,也知道?\ell?,
such that,如此…以致于
No online algorithm with lookahead ?\ell? for paging is better than kkk competitive.
找下界,盡量讓ALG?ALG_\ellALG??少發(fā)生page fault
give an instance III
(pk+1,pk+1,?,pk+1??requests,pi,pi,?,pi??requests,?)(p_{k+1},\begin{matrix} \underbrace {p_{k+1},\cdots,p_{k+1}}\\ \ell \;requests \end{matrix}, p_i,\begin{matrix}\underbrace {p_{i},\cdots ,p_{i}}\\ \ell \;requests \end{matrix},\cdots) (pk+1?,pk+1?,?,pk+1???requests?,pi?,pi?,?,pi???requests?,?)
ALG?ALG_\ellALG??只能知道前面?\ell?個,按照上述instance,ALG?ALG_\ellALG??每?+1\ell+1?+1個page,fault一次,所以cost(ALG?)=n??1cost(ALG_\ell)=\frac{n}{\ell-1}cost(ALG??)=??1n?
OPTOPTOPT的話,求的是opt的最壞情況。causes at most one page fault every k(?+1)k(\ell+1)k(?+1) time steps.cost(OPT)=nk(??1)cost(OPT)=\frac{n}{k(\ell-1)}cost(OPT)=k(??1)n?
cost(ALG?(I))cost(OPT(I))=n??1nk(??1)=k\frac {cost(ALG_\ell(I))} {cost(OPT(I))}=\frac{\frac{n}{\ell-1}}{\frac{n}{k(\ell-1)}}=k cost(OPT(I))cost(ALG??(I))?=k(??1)n???1n??=k
resource augmentation
online algorithm v.s. adversary
(h,k)-paging problem
OPTOPTOPT is only allowed to use a size of h≤kh \le kh≤k for the same input.
Every marking algorithm is k/(k-h+1)-competitive for (h,k)-paging
本章最重要的就是那個
kkk-phase partition
cost(ALG)=k?Ncost(ALG)=k\cdot Ncost(ALG)=k?N
cost(OPT)=(k?(h?1))?(N?1)+1cost(OPT)=(k-(h-1))\cdot (N-1)+1cost(OPT)=(k?(h?1))?(N?1)+1
最后不一定是加一,可以忽略不記,主要是要明確,在(h,k)-paging中,0<α≤k0<\alpha \le k0<α≤k
competitiveratio=kk?h+1competitive \;ratio =\frac{k}{k-h+1} competitiveratio=k?h+1k?
k?N≤kk?h+1?((k?(h?1))?(N?1)+1)+αk \cdot N\le \frac{k}{k-h+1}\cdot((k-(h-1))\cdot (N-1)+1)+\alpha k?N≤k?h+1k??((k?(h?1))?(N?1)+1)+α
of h≤kh \le kh≤k for the same input.
Every marking algorithm is k/(k-h+1)-competitive for (h,k)-paging
本章最重要的就是那個
kkk-phase partition
cost(ALG)=k?Ncost(ALG)=k\cdot Ncost(ALG)=k?N
cost(OPT)=(k?(h?1))?(N?1)+1cost(OPT)=(k-(h-1))\cdot (N-1)+1cost(OPT)=(k?(h?1))?(N?1)+1
最后不一定是加一,可以忽略不記,主要是要明確,在(h,k)-paging中,0<α≤k0<\alpha \le k0<α≤k
competitiveratio=kk?h+1competitive \;ratio =\frac{k}{k-h+1} competitiveratio=k?h+1k?
k?N≤kk?h+1?((k?(h?1))?(N?1)+1)+αk \cdot N\le \frac{k}{k-h+1}\cdot((k-(h-1))\cdot (N-1)+1)+\alpha k?N≤k?h+1k??((k?(h?1))?(N?1)+1)+α
總結(jié)
以上是生活随笔為你收集整理的online-section1-new的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Lu求解含积分的复杂非线性方程(组)
- 下一篇: 原来PWM这么简单!通过锯齿波作为载波和