-
Notifications
You must be signed in to change notification settings - Fork 9
Create induced subgraph from edge list #37
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
Changes from 1 commit
86feac3
6daee73
6f5b1ad
20a12a0
7478062
0d2e8e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -144,3 +144,28 @@ function induced_subgraph(g::T, vlist::AbstractVector{U}) where T <: AbstractSim | |
| newg.weights = new_weights | ||
| return newg, Vector{E}(vlist) | ||
| end | ||
|
|
||
| function induced_subgraph(g::T, elist::AbstractVector{U}) where T <: AbstractSimpleWeightedGraph where U <: AbstractEdge | ||
| allunique(elist) || throw(ArgumentError("Edges in subgraph list must be unique")) | ||
| E = eltype(g) | ||
| W = edgetype(g) | ||
| vertexSet = Set{E}() | ||
gdalle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| for e in elist | ||
| if has_edge(g, e) | ||
| push!(vertexSet, src(e), dst(e)) | ||
| else | ||
| @warn "Skipping the edge $(e), since it does not exist in the graph!" | ||
| end | ||
| end | ||
| vertexList = collect(vertexSet) | ||
gdalle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| new_weights = g.weights[vertexList, vertexList] | ||
|
|
||
| newg = zero(g) | ||
gdalle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| newg.weights = new_weights | ||
| for e in edges(newg) | ||
| if e ∉ elist | ||
| newg.weights[dst(e), src(e)] = 0 | ||
|
||
| end | ||
| end | ||
| return newg, Vector{W}(collect(edges(newg))) | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.