文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > 高等教育 > 理学 > Dijkstra’s algorithm with Fibonacci heaps An executable description
侵权投诉

Dijkstra’s algorithm with Fibonacci heaps An executable description

Abstract. We construct a readable, compact and efficient implementation of Dijkstra’s shortest path algorithm and Fibonacci heaps using Constraint Handling Rules (CHR), which is increasingly used as a high-level rule-based general-purpose programming lang

Relabelingworksasfollows:wedonothingiftheneighborisalreadyscanned.IftheneighbornodeNisnotscanned,itiseitherunlabeledorlabeled.Usingthedecroperation,NgetsalabelifitisunlabeledandgetsanewlabelifthecandidatelabelLissmallerthantheoriginal.scanned@distance(N,_)\relabel(N,_)<=>true.

not_scanned@relabel(N,L)<=>decr_or_ins(N,L).

ThefullprogramtextisgiveninFigure1.

3.2Fibonacciheaps

WeuseFibonacciheapstoimplementthepriorityqueueneededinDijkstra’salgorithm.Theitemsandtheirkeysarestoredasnodesinacollectionofheap-orderedtrees.Aheap-orderedtreeisarootedtreewherethekeyofanynodeisnolessthanthekeyofitsparent.Thenumberofchildrenofanodeiscalleditsrank.Nodescanbeeithermarkedorunmarked.Rootnodesarenevermarked.

AnodecontainingtheitemIwithkeyKisstoredasanitem(I,K,R,P,M)constraint,whereRisitsrankandPistheitemofitsparent(or0ifitisaroot).ThelastargumentMisuifthenodeisunmarkedandmifitismarked.Theminimum-keypairisstoredasamin/2constraint:keep_min@min(_,A)\min(_,B)<=>A=<B|true.

Insert.InsertinganewitemIwithkeyKisdonebyaddinganunmarkedisolatedrootnodeandupdatingtheminimum:

insert@insert(I,K)<=>item(I,K,0,0,u),min(I,K).

Extract-min.Extractingtheminimumnodeisdoneasfollows.Firstwe ndandremovetheminconstraint(ifthereisnone,theheapisemptyandwefail)andthecorrespondingitem.Thenweconvertthechildrenoftheminimumnodetoroots,whichisdonebythech2rtconstraint.Finallywe ndthenewminimum(donebythefindminconstraint)andreturnthe(old)minimumitem.extr@extract_min(X,Y),min(I,K),item(I,_,_,_,_)

<=>ch2rt(I),findmin,X=I,Y=K.

extr_none@extract_min(_,_)<=>fail.

c2r@ch2rt(I)\item(C,K,R,I,_)<=>item(C,K,R,0,u).

c2r_done@ch2rt(I)<=>true.

To ndthenewminimum,itsu cestosearchtherootnodes:

findmin@findmin,item(I,K,_,0,_)==>min(I,K).

foundmin@findmin<=>true.

WewanttomakesurethatthenumberofrootsisO(logn).Thefollowingrulelinkstreeswhoserootshavethesamerank,reducingthenumberofroots:

same_rank@item(I1,K1,R,0,_),item(I2,K2,R,0,_)<=>K1=<K2|

R1isR+1,item(I2,K2,R,I1,u),item(I1,K1,R1,0,u).

Decrease-key.Thedecrease-keyoperationremovestheoriginalitemconstraintandcallsdecr/5ifthenewkeyissmaller(andfailsotherwise).

decr@decr(I,K),item(I,O,R,P,M)<=>K<O|decr(I,K,R,P,M).

decr_nok@decr(I,K)<=>fail.

上一页第3页

你可能喜欢

热门文档

相关文档

  • fibonacci heaps

    Dijkstra’s algorithm wi... 16页 免费 Dijkstra... Meeting 11 October 4, 2005 Fibonacci Heaps The...cost applied to an initially empty Fibonacci heap...

  • Are Fibonacci heaps optimal

    Dijkstra’s algorithm wi... 10页 免费 Rangan. Relaxed fibonacc... 暂无...[5] invented an implementation of the priority queue called Fibonacci heaps....

  • Are Fibonacci heaps optimal

    Dijkstra’s algorithm wi... 10页 免费 Rangan. Relaxed fibonacc... 暂无...[5] invented an implementation of the priority queue called Fibonacci heaps....

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email