-
Notifications
You must be signed in to change notification settings - Fork 10
Implement InducedSubgraphView #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
IanChenUIUC
wants to merge
12
commits into
Ladybug-Memory:main
from
IanChenUIUC:feature/induced-subgraph-view
Closed
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
04221e2
header for inducedsubgraphview
IanChenUIUC 25c22ea
add necesasry overrides to inducedsubgraphview header
IanChenUIUC 3eab0e6
ci: stop workflows for draft PRs
IanChenUIUC 01ef0bb
draft impl of inducedsubgraphview + starting tests
IanChenUIUC a1c3875
inducedsubgraphview tests + impl; degrees, addnodes, removenodes
IanChenUIUC fbae54b
inducedsubgraphview nodeiterators tests
IanChenUIUC 076f36d
inducedsubgraphview nodeiterators
IanChenUIUC 9e1ab68
inducedsubgraph test for all but edge iterators
IanChenUIUC a1598a1
edge iterators
IanChenUIUC 829499d
inducedsubgraphview finish tests
IanChenUIUC 01d9ec1
correctly use virtual funcs
IanChenUIUC 84670d3
inducedsubgraphview performance: parallel iteration and revert virtual
IanChenUIUC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,130 @@ | ||
| /* | ||
| * InducedSubgraphView.hpp | ||
| * | ||
| * Created on: 06.25.2026 | ||
| * Author: Ian Chen (ianchen3@illinois.edu) | ||
| */ | ||
|
|
||
| #ifndef NETWORKIT_GRAPH_INDUCED_SUBGRAPH_VIEW_HPP_ | ||
| #define NETWORKIT_GRAPH_INDUCED_SUBGRAPH_VIEW_HPP_ | ||
|
|
||
| #include <set> | ||
|
|
||
| #include <networkit/graph/GraphR.hpp> | ||
|
|
||
| namespace NetworKit { | ||
|
|
||
| /** | ||
| * @ingroup graph | ||
| * InducedSubgraphView - Zero-copy induced subgraph. | ||
| * | ||
| * This class provides a memory-efficient graph view into a | ||
| * base graph, providing the same interface. | ||
| * Nodes can be added or removed as a batch. | ||
| * | ||
| * A mutable GraphW can be realized. | ||
| * Neighbors are computed on-the-fly. | ||
| */ | ||
| class InducedSubgraphView final : public GraphR { | ||
| const Graph &originalGraph; | ||
| std::set<node> nodeSubset; | ||
|
|
||
| count inducedNumberOfEdges = 0; | ||
| count inducedNumberOfSelfLoops = 0; | ||
| std::vector<count> inducedDegree; | ||
|
|
||
| public: | ||
| /** | ||
| * Construct an induced subgraph view from the original graph and the node subset. | ||
| * @param originalGraph The original CSR graph | ||
| * @param subset The defining nodes of the induced subgraph. | ||
| */ | ||
| InducedSubgraphView(const Graph &originalGraph, std::set<node> subset); | ||
|
|
||
| /** | ||
| * Add nodes to the subset. | ||
| */ | ||
| void AddNodes(const std::set<node> &subset); | ||
|
|
||
| /** | ||
| * Remove nodes from the subset. | ||
| */ | ||
| void RemoveNodes(const std::set<node> &subset); | ||
|
|
||
| /** | ||
| * Construct an explicit mutable subgraph equivalent to this view. | ||
| */ | ||
| GraphW Realize() const; | ||
|
|
||
| /** | ||
| * Copy constructor | ||
| */ | ||
| InducedSubgraphView(const InducedSubgraphView &other) = default; | ||
|
|
||
| /** | ||
| * Move constructor | ||
| */ | ||
| InducedSubgraphView(InducedSubgraphView &&other) noexcept = default; | ||
|
|
||
| /** | ||
| * Copy assignment | ||
| */ | ||
| InducedSubgraphView &operator=(const InducedSubgraphView &other) { | ||
| Graph::operator=(other); | ||
|
IanChenUIUC marked this conversation as resolved.
|
||
| return *this; | ||
| } | ||
|
|
||
| /** | ||
| * Move assignment | ||
| */ | ||
| InducedSubgraphView &operator=(InducedSubgraphView &&other) noexcept { | ||
| Graph::operator=(std::move(other)); | ||
| return *this; | ||
| } | ||
|
|
||
| /** Default destructor */ | ||
| ~InducedSubgraphView() override = default; | ||
|
|
||
| // Override from Graph base | ||
| bool hasNode(node v) const noexcept; | ||
| count numberOfNodes() noexcept; | ||
| count numberOfEdges() noexcept; | ||
| count numberOfSelfLoops() noexcept; | ||
|
|
||
| // Implement pure virtual methods from Graph base class | ||
|
|
||
| count degree(node v) const override; | ||
| count degreeIn(node v) const override; | ||
|
|
||
| /** | ||
| * Return edge weight of edge {@a u,@a v}. Returns 0 if edge does not | ||
| * exist. If weights are provided during construction, returns the actual | ||
| * edge weight; otherwise returns defaultEdgeWeight (1.0). | ||
| * | ||
| * @param u Endpoint of edge. | ||
| * @param v Endpoint of edge. | ||
| * @return Edge weight of edge {@a u,@a v} or 0 if edge does not exist. | ||
| */ | ||
| edgeweight weight(node u, node v) const override; | ||
|
|
||
| edgeid edgeId(node u, node v) const override; | ||
|
|
||
| node getIthNeighbor(Unsafe, node u, index i) const override; | ||
| edgeweight getIthNeighborWeight(node u, index i) const override; | ||
| node getIthNeighbor(node u, index i) const override; | ||
| node getIthInNeighbor(node u, index i) const override; | ||
| std::pair<node, edgeweight> getIthNeighborWithWeight(node u, index i) const override; | ||
| std::pair<node, edgeid> getIthNeighborWithId(node u, index i) const override; | ||
|
|
||
| protected: | ||
| std::vector<node> getNeighborsVector(node u, bool inEdges = false) const override; | ||
| std::pair<std::vector<node>, std::vector<edgeweight>> | ||
| getNeighborsWithWeightsVector(node u, bool inEdges = false) const override; | ||
|
|
||
| index indexInInEdgeArray(node v, node u) const override; | ||
| index indexInOutEdgeArray(node u, node v) const override; | ||
| }; | ||
|
|
||
| } // namespace NetworKit | ||
|
|
||
| #endif // NETWORKIT_GRAPH_INDUCED_SUBGRAPH_VIEW_HPP_ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.