Skip to content

Commit

Permalink
Add 'remove.duplicate.edges' function
Browse files Browse the repository at this point in the history
Add a function that takes a network as input and simply removes all
edges that are exact duplicates of each other.

Works towards se-sic#138.

Signed-off-by: Maximilian Löffler <[email protected]>
  • Loading branch information
maxloeffler authored and Leo-Send committed Nov 13, 2024
1 parent ac9abe7 commit 4566fd9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions util-networks.R
Original file line number Diff line number Diff line change
Expand Up @@ -1993,6 +1993,26 @@ delete.isolates = function(network) {
return(network.no.isolates)
}

#' Remove duplicate edges from the given network.
#'
#' Keep exactly one edge from all equivalence classes of edges over identity.
#' This function retains all set network, vertex, and edge attributes.
#'
#' @param network the given network
#'
#' @return the simplified network
remove.duplicate.edges = function(network) {

logging::logdebug("remove.duplicate.edges: starting.")

## remove all duplicates
edges = igraph::as_data_frame(network, "edges")
network = igraph::delete_edges(network, which(duplicated(edges)))

logging::logdebug("remove.duplicate.edges: finished.")
return(network)
}


## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Multi-network views -----------------------------------------------------
Expand Down

0 comments on commit 4566fd9

Please sign in to comment.