mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-13 16:17:54 +00:00
Docs: Update benchmark for minimax/minimax-m2.1
This commit is contained in:
34
tests/1_dijkstra/outputs/minimax_minimax-m2.1.js
Normal file
34
tests/1_dijkstra/outputs/minimax_minimax-m2.1.js
Normal file
@@ -0,0 +1,34 @@
|
||||
export async function findShortestPath(graph, start, end) {
|
||||
const { PriorityQueue } = await import("https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.15/+esm");
|
||||
|
||||
const distances = {};
|
||||
const visited = new Set();
|
||||
const queue = new PriorityQueue({ comparator: (a, b) => a.distance - b.distance });
|
||||
|
||||
for (const node in graph) {
|
||||
distances[node] = Infinity;
|
||||
}
|
||||
distances[start] = 0;
|
||||
queue.enqueue({ node: start, distance: 0 });
|
||||
|
||||
while (queue.length > 0) {
|
||||
const { node: current, distance } = queue.dequeue();
|
||||
|
||||
if (current === end) return distance;
|
||||
if (visited.has(current)) continue;
|
||||
visited.add(current);
|
||||
|
||||
for (const [neighbor, weight] of Object.entries(graph[current] || {})) {
|
||||
const newDistance = distance + weight;
|
||||
if (newDistance < distances[neighbor]) {
|
||||
distances[neighbor] = newDistance;
|
||||
queue.enqueue({ node: neighbor, distance: newDistance });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
// Generation time: 4.700s
|
||||
// Result: FAIL
|
||||
Reference in New Issue
Block a user