-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
30 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,36 @@ | ||
function neighbors(graph, vtx) | ||
neighbors = findnz(graph[vtx, :])[2] | ||
neighbors = findnz(graph[vtx, :])[1] | ||
return neighbors | ||
end | ||
|
||
function edges(graph) | ||
return findnz(graph) | ||
is, js, ids = findnz(graph) | ||
|
||
# Filter list | ||
pos_ids = ids .>= 0.0 | ||
is_pos = is[pos_ids] | ||
js_pos = js[pos_ids] | ||
ids_pos = ids[pos_ids] | ||
|
||
# Order list | ||
order_dict = Dict(v => i for (i, v) in enumerate(ids_pos)) | ||
|
||
ids_sort = sortperm(ids_pos, by=x -> order_dict[x]) | ||
is_sort = is_pos[ids_sort] | ||
js_sort = js_pos[ids_sort] | ||
return zip(is_sort, js_sort) | ||
end | ||
|
||
function create_graph(edges, pts) | ||
n_pts = length(pts) | ||
graph = spzeros(Int, n_pts, n_pts) | ||
for edge in edges | ||
graph[edge[1], edge[2]] = 1 | ||
graph[edge[2], edge[1]] = 1 | ||
for (i, edge) in enumerate(edges) | ||
graph[edge[1], edge[2]] = i | ||
graph[edge[2], edge[1]] = -i | ||
end | ||
return graph | ||
end | ||
|
||
function edge_index(adj_matrix, i, j) | ||
row_indices, col_indices, _ = findnz(adj_matrix) | ||
for idx in 1:length(row_indices) | ||
if row_indices[idx] == i && col_indices[idx] == j | ||
return idx # Position of the edge in the sparse storage | ||
end | ||
end | ||
return nothing # Edge not found | ||
function edge_index(edge, graph) | ||
return abs(graph[edge[1], edge[2]]) | ||
end |
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