-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8682 from IoannisPanagiotas/dijkstra-with-mutiple…
…-targets One-to-many dijkstra
- Loading branch information
Showing
24 changed files
with
582 additions
and
56 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
algo/src/main/java/org/neo4j/gds/paths/SourceTargetsShortestPathBaseConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.gds.paths; | ||
|
||
import org.immutables.value.Value; | ||
import org.neo4j.gds.annotation.Configuration; | ||
import org.neo4j.gds.config.OptionalTargetNodeConfig; | ||
import org.neo4j.gds.config.TargetNodesConfig; | ||
|
||
import java.util.List; | ||
|
||
public interface SourceTargetsShortestPathBaseConfig extends | ||
OptionalTargetNodeConfig, | ||
TargetNodesConfig, | ||
ShortestPathBaseConfig { | ||
|
||
@Configuration.Ignore | ||
default List<Long> targetsList() { | ||
var targetNode = targetNode(); | ||
var targetNodes = targetNodes(); | ||
|
||
if (targetNodes.isEmpty() && targetNode.isPresent()) { | ||
return List.of(targetNode.get()); | ||
} | ||
return targetNodes; | ||
} | ||
|
||
@Value.Check | ||
default void validate() { | ||
if (!targetNodes().isEmpty() && targetNode().isPresent()) { | ||
throw new IllegalArgumentException( | ||
"The `targets` and `target` parameters cannot be both specified at the same time"); | ||
} | ||
if (targetsList().isEmpty() && targetNode().isEmpty()) { | ||
throw new IllegalArgumentException( | ||
"One of `targets` or `target` parameters must be specified"); | ||
} | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
algo/src/main/java/org/neo4j/gds/paths/dijkstra/AllTargets.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.gds.paths.dijkstra; | ||
|
||
class AllTargets implements Targets { | ||
|
||
@Override | ||
public TraversalState apply(long nodeId) { | ||
return TraversalState.EMIT_AND_CONTINUE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
algo/src/main/java/org/neo4j/gds/paths/dijkstra/ManyTargets.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.gds.paths.dijkstra; | ||
|
||
import com.carrotsearch.hppc.BitSet; | ||
|
||
import java.util.List; | ||
|
||
class ManyTargets implements Targets{ | ||
|
||
private final BitSet bitSet; | ||
private int targetCount; | ||
public ManyTargets(List<Long> targetNodesList){ | ||
|
||
long maxNodeId = 0; | ||
for (var targetNode : targetNodesList){ | ||
maxNodeId = Math.max(targetNode, maxNodeId); | ||
} | ||
bitSet = new BitSet(maxNodeId + 1); | ||
|
||
targetNodesList.forEach(bitSet::set); | ||
targetCount = targetNodesList.size(); | ||
} | ||
@Override | ||
public TraversalState apply(long nodeId) { | ||
if (bitSet.get(nodeId)){ | ||
targetCount--; | ||
return (targetCount==0) ? | ||
TraversalState.EMIT_AND_STOP | ||
: TraversalState.EMIT_AND_CONTINUE; | ||
} | ||
return TraversalState.CONTINUE; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
algo/src/main/java/org/neo4j/gds/paths/dijkstra/SingleTarget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.gds.paths.dijkstra; | ||
|
||
import static org.neo4j.gds.paths.dijkstra.TraversalState.CONTINUE; | ||
import static org.neo4j.gds.paths.dijkstra.TraversalState.EMIT_AND_STOP; | ||
|
||
public class SingleTarget implements Targets { | ||
|
||
private final long targetNode; | ||
|
||
public SingleTarget(long targetNode) { | ||
this.targetNode = targetNode; | ||
} | ||
|
||
@Override | ||
public TraversalState apply(long nodeId) { | ||
return (nodeId == targetNode) ? EMIT_AND_STOP : CONTINUE; | ||
} | ||
} |
Oops, something went wrong.