-
Notifications
You must be signed in to change notification settings - Fork 86
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 #1652 from kuzudb/all-shortest-path
Add all shortest path
- Loading branch information
Showing
29 changed files
with
1,787 additions
and
1,686 deletions.
There are no files selected for viewing
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
68 changes: 68 additions & 0 deletions
68
src/include/processor/operator/recursive_extend/all_shortest_path_state.h
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,68 @@ | ||
#pragma once | ||
|
||
#include "bfs_state.h" | ||
|
||
namespace kuzu { | ||
namespace processor { | ||
|
||
template<bool TRACK_PATH> | ||
class AllShortestPathState : public BaseBFSState { | ||
public: | ||
AllShortestPathState(uint8_t upperBound, TargetDstNodes* targetDstNodes) | ||
: BaseBFSState{upperBound, targetDstNodes}, minDistance{0}, numVisitedDstNodes{0} {} | ||
|
||
inline bool isComplete() final { | ||
return isCurrentFrontierEmpty() || isUpperBoundReached() || | ||
isAllDstReachedWithMinDistance(); | ||
} | ||
|
||
inline void resetState() final { | ||
BaseBFSState::resetState(); | ||
minDistance = 0; | ||
numVisitedDstNodes = 0; | ||
visitedNodeToDistance.clear(); | ||
} | ||
|
||
inline void markSrc(common::nodeID_t nodeID) override { | ||
visitedNodeToDistance.insert({nodeID, 0}); | ||
if (targetDstNodes->contains(nodeID)) { | ||
numVisitedDstNodes++; | ||
} | ||
currentFrontier->addNodeWithMultiplicity(nodeID, 1); | ||
} | ||
|
||
void markVisited(common::nodeID_t boundNodeID, common::nodeID_t nbrNodeID, | ||
common::relID_t relID, uint64_t multiplicity) final { | ||
if (!visitedNodeToDistance.contains(nbrNodeID)) { | ||
visitedNodeToDistance.insert({nbrNodeID, currentLevel}); | ||
if (targetDstNodes->contains(nbrNodeID)) { | ||
minDistance = currentLevel; | ||
numVisitedDstNodes++; | ||
} | ||
if constexpr (TRACK_PATH) { | ||
nextFrontier->addEdge(boundNodeID, nbrNodeID, relID); | ||
} else { | ||
nextFrontier->addNodeWithMultiplicity(nbrNodeID, multiplicity); | ||
} | ||
} else if (currentLevel <= visitedNodeToDistance.at(nbrNodeID)) { | ||
if constexpr (TRACK_PATH) { | ||
nextFrontier->addEdge(boundNodeID, nbrNodeID, relID); | ||
} else { | ||
nextFrontier->addNodeWithMultiplicity(nbrNodeID, multiplicity); | ||
} | ||
} | ||
} | ||
|
||
private: | ||
inline bool isAllDstReachedWithMinDistance() const { | ||
return numVisitedDstNodes == targetDstNodes->getNumNodes() && currentLevel > minDistance; | ||
} | ||
|
||
private: | ||
uint32_t minDistance; // Min distance to add dst nodes that have been reached. | ||
uint64_t numVisitedDstNodes; | ||
frontier::node_id_map_t<uint32_t> visitedNodeToDistance; | ||
}; | ||
|
||
} // namespace processor | ||
} // namespace kuzu |
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
38 changes: 38 additions & 0 deletions
38
src/include/processor/operator/recursive_extend/scan_frontier.h
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,38 @@ | ||
#pragma once | ||
|
||
#include "processor/operator/physical_operator.h" | ||
|
||
namespace kuzu { | ||
namespace processor { | ||
|
||
class ScanFrontier : public PhysicalOperator { | ||
public: | ||
ScanFrontier(DataPos nodeIDVectorPos, uint32_t id, const std::string& paramsString) | ||
: PhysicalOperator{PhysicalOperatorType::SCAN_NODE_ID, id, paramsString}, | ||
nodeIDVectorPos{nodeIDVectorPos} {} | ||
|
||
inline bool isSource() const override { return true; } | ||
|
||
inline void initLocalStateInternal(ResultSet* resultSet_, ExecutionContext* context) override { | ||
nodeIDVector = resultSet->getValueVector(nodeIDVectorPos); | ||
} | ||
|
||
bool getNextTuplesInternal(kuzu::processor::ExecutionContext* context) override; | ||
|
||
inline void setNodeID(common::nodeID_t nodeID) { | ||
nodeIDVector->setValue<common::nodeID_t>(0, nodeID); | ||
hasExecuted = false; | ||
} | ||
|
||
std::unique_ptr<PhysicalOperator> clone() override { | ||
return std::make_unique<ScanFrontier>(nodeIDVectorPos, id, paramsString); | ||
} | ||
|
||
private: | ||
DataPos nodeIDVectorPos; | ||
std::shared_ptr<common::ValueVector> nodeIDVector; | ||
bool hasExecuted; | ||
}; | ||
|
||
} // namespace processor | ||
} // namespace kuzu |
34 changes: 0 additions & 34 deletions
34
src/include/processor/operator/recursive_extend/shortest_path_recursive_join.h
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.