Skip to content

Commit 95569a0

Browse files
authored
Merge pull request #35 from antvis/0.1.11
fix: gaddi for only one node
2 parents d059bf9 + f10c5d1 commit 95569a0

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

packages/graph/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/algorithm",
3-
"version": "0.1.10",
3+
"version": "0.1.11",
44
"description": "graph algorithm",
55
"keywords": [
66
"graph",

packages/graph/src/bfs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const breadthFirstSearch = (
4343
graphData: GraphData,
4444
startNodeId: string,
4545
originalCallbacks?: IAlgorithmCallbacks,
46+
directed: boolean = true
4647
) => {
4748
const callbacks = initCallbacks(originalCallbacks);
4849
const nodeQueue = new Queue();
@@ -63,7 +64,7 @@ const breadthFirstSearch = (
6364
});
6465

6566
// 将所有邻居添加到队列中以便遍历
66-
getNeighbors(currentNode, edges, 'target').forEach((nextNode) => {
67+
getNeighbors(currentNode, edges, directed ? 'target' : undefined).forEach((nextNode) => {
6768
if (
6869
callbacks.allowTraversal({
6970
previous: previousNode,

packages/graph/src/gaddi.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,11 @@ const GADDI = (
503503
);
504504

505505
// 若未指定 length,自动计算 pattern 半径(最短路径最大值)
506-
if (!length) length = Math.max(...patternSpm[0], 2);
506+
let patternSpmSpread = [];
507+
patternSpm?.forEach(row => {
508+
patternSpmSpread = patternSpmSpread.concat(row);
509+
})
510+
if (!length) length = Math.max(...patternSpmSpread, 2);
507511
if (!k) k = length;
508512

509513
// console.log("params", directed, length, k);
@@ -735,7 +739,7 @@ const GADDI = (
735739

736740
// candidates 经过筛选后,以每个 candidate 为中心,生成 Length-neighbor 的邻居诱导子图
737741
// 并在诱导子图中去除不可能在 Q 上找到匹配的点:在 Q 上不存在的 label,其他 label 到 candidate 的最大最短距离符合 Q、NDS 距离符合 Q
738-
candidates.forEach(candidate => {
742+
candidates?.forEach(candidate => {
739743
const nodeIdx = nodeMap[candidate.id].idx;
740744
const lengthNeighborUnit = findKNeighborUnit(
741745
graphData.nodes,

packages/graph/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export interface IAlgorithm {
5656
graphData: GraphData,
5757
startNodeId: string,
5858
originalCallbacks?: IAlgorithmCallbacks,
59+
directed?: boolean
5960
) => void,
6061
connectedComponent: (graphData: GraphData, directed?: boolean) => NodeConfig[][],
6162
getDegree: (graphData: GraphData) => DegreeType,

0 commit comments

Comments
 (0)