in core/src/main/java/com/jetbrains/youtrackdb/internal/core/sql/functions/graph/SQLFunctionAstar.java [360:489]
protected double getHeuristicCost(
final Vertex node, Vertex parent, final Vertex target, CommandContext iContext) {
var hresult = 0.0;
if (paramVertexAxisNames.length == 0) {
return hresult;
} else if (paramVertexAxisNames.length == 1) {
double n = doubleOrDefault(node.getProperty(paramVertexAxisNames[0]), 0.0);
double g = doubleOrDefault(target.getProperty(paramVertexAxisNames[0]), 0.0);
hresult = getSimpleHeuristicCost(n, g, paramDFactor);
} else if (paramVertexAxisNames.length == 2) {
if (parent == null) {
parent = node;
}
double sx = doubleOrDefault(paramSourceVertex.getProperty(paramVertexAxisNames[0]), 0);
double sy = doubleOrDefault(paramSourceVertex.getProperty(paramVertexAxisNames[1]), 0);
double nx = doubleOrDefault(node.getProperty(paramVertexAxisNames[0]), 0);
double ny = doubleOrDefault(node.getProperty(paramVertexAxisNames[1]), 0);
double px = doubleOrDefault(parent.getProperty(paramVertexAxisNames[0]), 0);
double py = doubleOrDefault(parent.getProperty(paramVertexAxisNames[1]), 0);
double gx = doubleOrDefault(target.getProperty(paramVertexAxisNames[0]), 0);
double gy = doubleOrDefault(target.getProperty(paramVertexAxisNames[1]), 0);
switch (paramHeuristicFormula) {
case MANHATAN:
hresult = getManhatanHeuristicCost(nx, ny, gx, gy, paramDFactor);
break;
case MAXAXIS:
hresult = getMaxAxisHeuristicCost(nx, ny, gx, gy, paramDFactor);
break;
case DIAGONAL:
hresult = getDiagonalHeuristicCost(nx, ny, gx, gy, paramDFactor);
break;
case EUCLIDEAN:
hresult = getEuclideanHeuristicCost(nx, ny, gx, gy, paramDFactor);
break;
case EUCLIDEANNOSQR:
hresult = getEuclideanNoSQRHeuristicCost(nx, ny, gx, gy, paramDFactor);
break;
case CUSTOM:
hresult =
getCustomHeuristicCost(
paramCustomHeuristicFormula,
paramVertexAxisNames,
paramSourceVertex,
paramDestinationVertex,
node,
parent,
currentDepth,
paramDFactor,
iContext);
break;
}
if (paramTieBreaker) {
hresult = getTieBreakingHeuristicCost(px, py, sx, sy, gx, gy, hresult);
}
} else {
Map<String, Double> sList = new HashMap<String, Double>();
Map<String, Double> cList = new HashMap<String, Double>();
Map<String, Double> pList = new HashMap<String, Double>();
Map<String, Double> gList = new HashMap<String, Double>();
parent = parent == null ? node : parent;
for (var i = 0; i < paramVertexAxisNames.length; i++) {
var s = doubleOrDefault(paramSourceVertex.getProperty(paramVertexAxisNames[i]), 0);
var c = doubleOrDefault(node.getProperty(paramVertexAxisNames[i]), 0);
var g = doubleOrDefault(target.getProperty(paramVertexAxisNames[i]), 0);
var p = doubleOrDefault(parent.getProperty(paramVertexAxisNames[i]), 0);
if (s != null) {
sList.put(paramVertexAxisNames[i], s);
}
if (c != null) {
cList.put(paramVertexAxisNames[i], s);
}
if (g != null) {
gList.put(paramVertexAxisNames[i], g);
}
if (p != null) {
pList.put(paramVertexAxisNames[i], p);
}
}
switch (paramHeuristicFormula) {
case MANHATAN:
hresult =
getManhatanHeuristicCost(
paramVertexAxisNames, sList, cList, pList, gList, currentDepth, paramDFactor);
break;
case MAXAXIS:
hresult =
getMaxAxisHeuristicCost(
paramVertexAxisNames, sList, cList, pList, gList, currentDepth, paramDFactor);
break;
case DIAGONAL:
hresult =
getDiagonalHeuristicCost(
paramVertexAxisNames, sList, cList, pList, gList, currentDepth, paramDFactor);
break;
case EUCLIDEAN:
hresult =
getEuclideanHeuristicCost(
paramVertexAxisNames, sList, cList, pList, gList, currentDepth, paramDFactor);
break;
case EUCLIDEANNOSQR:
hresult =
getEuclideanNoSQRHeuristicCost(
paramVertexAxisNames, sList, cList, pList, gList, currentDepth, paramDFactor);
break;
case CUSTOM:
hresult =
getCustomHeuristicCost(
paramCustomHeuristicFormula,
paramVertexAxisNames,
paramSourceVertex,
paramDestinationVertex,
node,
parent,
currentDepth,
paramDFactor,
iContext);
break;
}
if (paramTieBreaker) {
hresult =
getTieBreakingHeuristicCost(
paramVertexAxisNames, sList, cList, pList, gList, currentDepth, hresult);
}
}
return hresult;
}