ngraph.path/a-star/defaultSettings.js
2025-11-14 21:38:30 -08:00

64 lines
1.4 KiB
JavaScript

// We reuse instance of array, but we trie to freeze it as well,
// so that consumers don't modify it. Maybe it's a bad idea.
const NO_PATH = [];
if (typeof Object.freeze === 'function') Object.freeze(NO_PATH);
const defaultSettings = {
// Path search settings
heuristic: blindHeuristic,
distance: constantDistance,
blocked: neverBlocked,
compareFScore: compareFScore,
NO_PATH: NO_PATH,
// heap settings
setHeapIndex: setHeapIndex,
// nba:
setH1: setH1,
setH2: setH2,
compareF1Score: compareF1Score,
compareF2Score: compareF2Score,
};
export default defaultSettings;
function blindHeuristic(/* a, b */) {
// blind heuristic makes this search equal to plain Dijkstra path search.
return 0;
}
function constantDistance(/* a, b */) {
return 1;
}
function neverBlocked(/* a, b, c */) {
return false;
}
function compareFScore(a, b) {
var result = a.fScore - b.fScore;
// TODO: Can I improve speed with smarter ties-breaking?
// I tried distanceToSource, but it didn't seem to have much effect
return result;
}
function setHeapIndex(nodeSearchState, heapIndex) {
nodeSearchState.heapIndex = heapIndex;
}
function compareF1Score(a, b) {
return a.f1 - b.f1;
}
function compareF2Score(a, b) {
return a.f2 - b.f2;
}
function setH1(node, heapIndex) {
node.h1 = heapIndex;
}
function setH2(node, heapIndex) {
node.h2 = heapIndex;
}