- 2
- 0
- 约2.82千字
- 约 34页
- 2017-05-05 发布于湖北
- 举报
DijkstrasAlgorithmforSingle-SourceShortestPathProblem
Dijkstra’s Algorithm for Single-Source Shortest Path Problem;Outline;Point-to-point Shortest Path Problem;Point-to-point Shortest Path Problem;Dijkstra’s Idea;;To extract path;To get minimal spanning tree;Example Application;Movement Rules;Movement rules;Read problem again.;Designing a Java implementation;Edge representation;Simple special case;for (int x = 0; x V; x++) {
switch (x % n) {
case 0:
if (x-n = 0) neighbor[x][0] = x-n; // N
if (x+n V) neighbor[x][1] = x+n; // S
break;
case 1:
if ((x-n = 0) (x % n n-1))
neighbor[x][0] = x-n+1; // NE
if ((x+n N) (x % n 0))
neighbor[x][1] = x+n-1; // SW
...etc.
}};Alternatives;How to represent settled?;How to represent distances?;How to represent Q?;ComparatorInteger shortestDistance = new ComparatorInteger() { public int compare(Integer L, Integer R) { if (d[L] d[R]) return 1; if (d[L] d[R]) return -1; if (L R) return 1; if (L R) return -1; return 0; } };
PriorityQueueInteger q =
new PriorityQueueInteger(N, shortestDistance); ;A literal coding
of abstract
algorithm;
// while (Q ≠ ?) {
while (! q.isEmpty) {
// choose x ? Q to minimize d(x);
Q = Q – {x};
x = q.poll();
if (x==dest) break;
// settled = settled U {x};
settled[x] = true;
// for each unsettled neighbor y of x {
for (int i = 0; i 2; i++) {
y = neighbor[x][i];
if ((i != -1) ! settled[y]) {
// if (d(y)d(x) + len(x,y)) {
if (d[y]d[x] + 1){
// d(y) = d(x)+ len(x,y);
d[y] = d[x]+1;
// back(y) = x;
back[y] = x;
}}}};Q details;
while (! q.isEmpty) {
x = q.poll();
if (x==dest) break;
settled[x] = true;
for (int i = 0; i 2; i++) {
y = neighbor[x][i];
if ((i != -1) ! settled[y]) {
if (d[y]d[x] + 1){
d[y] = d[x]+1;
back[y] = x;
您可能关注的文档
- ModélisationUML.ppt
- Mod3–AssortmentPlanningbyPriceandMonth.ppt
- EfficientApproximateSearchonStringCollectionsPartII.ppt
- IPSecurityandKeyEstablishment.ppt
- ImplementingtheLeadSafeHousingRulein.ppt
- MicropaymentsRevisited.ppt
- Integers.ppt
- Reconnect'04UsingPICO.ppt
- Mechanismsofsensitization,diseasedevelopmentand.ppt
- Applications-SAS.ppt
- 浙江省温州市2024-2025学年七年级上学期语文期末考查卷.docx
- 精品解析:北京市建华实验学校2024-2025学年七年级下学期期中英语试题(原卷版).docx
- 精品解析:北京市通州区2024-2025学年七年级下学期期末考试英语试卷(原卷版).docx
- 精品解析:北京市回民学校2024-2025学年九年级上学期期中语文试题(解析版).docx
- 精品解析:北京市海淀区2025-2026学年九年级上学期期末语文试题(解析版).docx
- 精品解析:北京市东城区汇文中学2025-2026学年八年级上学期期中语文试题(原卷版).docx
- 精品解析:北京市回民学校2024-2025学年九年级上学期期中语文试题(原卷版).docx
- 精品解析:2024-2025学年广东省广州市从化区街口镇中心小学人教版五年级上册期中测试数学试卷(解析版).docx
- 精品解析:北京市通州区2024-2025学年七年级下学期期末考试英语试卷(解析版).docx
- 精品解析:北京市建华实验学校2024-2025学年七年级下学期期中英语试题(解析版).docx
原创力文档

文档评论(0)