finish all analysis

This commit is contained in:
2026-04-20 00:36:28 +09:00
parent 009bf59ff0
commit 31219c4618
26 changed files with 1130 additions and 483 deletions
+6 -8
View File
@@ -6,7 +6,7 @@ class DijkstraStats:
# self.decrease_key_calls = 0
# self.add_calls = 0
def heap_dijkstra(nodes, adj, heap, start, end):
def heap_dijkstra(nodes, adj, heap, start):
INF = float('inf')
dist = [INF] * nodes
visited = [False] * nodes
@@ -17,7 +17,7 @@ def heap_dijkstra(nodes, adj, heap, start, end):
for v in range(nodes):
heap.add(v, dist[v])
# stats.add_calls += 1
while True:
res = heap.extract_min()
stats.extract_min_calls += 1
@@ -28,9 +28,6 @@ def heap_dijkstra(nodes, adj, heap, start, end):
if cur_dist == INF:
break
if cur == end:
break
for nxt, d in adj[cur]:
stats.relax_attempts += 1
if visited[nxt]:
@@ -40,7 +37,8 @@ def heap_dijkstra(nodes, adj, heap, start, end):
stats.relax_success += 1
dist[nxt] = new
heap.decrease_key(nxt, new)
visited[cur] = True
return dist[end], stats
# return dist, stats
return stats
+6 -9
View File
@@ -1,25 +1,22 @@
def pure_dijkstra(nodes, adj, start, end):
def pure_dijkstra(nodes, adj, start):
dist = [float('inf')] * nodes
dist[start] = 0
visited = [False] * nodes
cur = start
while True:
if cur == -1:
break
if cur == end:
break
for next, d in adj[cur]:
if not visited[next]:
new = dist[cur] + d
if new < dist[next]:
dist[next] = new
visited[cur] = True
# Finding min node
min_node = -1
min_val = float('inf')
@@ -28,5 +25,5 @@ def pure_dijkstra(nodes, adj, start, end):
min_node = n
min_val = dist[n]
cur = min_node
return dist[end]
return dist
+2
View File
@@ -94,6 +94,8 @@ class FiboHeap:
def extract_min(self):
# 1. Find min node
min_node = self.min
if min_node is None:
return None
self.n -= 1
# 2. Make min node's child into individual tree