From 38277cb755e544b457e02ba11c53799301098c53 Mon Sep 17 00:00:00 2001 From: see24 Date: Wed, 13 Mar 2024 15:38:39 -0400 Subject: [PATCH] speed up by removing unnecessary %in% --- R/shortestPaths.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/shortestPaths.R b/R/shortestPaths.R index accdd2e..6be96da 100644 --- a/R/shortestPaths.R +++ b/R/shortestPaths.R @@ -45,7 +45,7 @@ shortestPaths<- function(sim){ # updates the cost(weight) associated with the edge that became a road igraph::edge_attr(sim$g, - index = igraph::E(sim$g)[igraph::E(sim$g) %in% paths.e], + index = igraph::E(sim$g)[paths.e], name = "weight") <- 0.00001 rm(paths.e) @@ -71,8 +71,10 @@ iterativeShortestPaths<- function(sim){ path <- unlist(path) # update the cost(weight) associated with the edge that became a road + path_edge_ind <- igraph::E(sim$g)[path[grepl("epath", names(path))]] + igraph::edge_attr(sim$g, - index = igraph::E(sim$g)[igraph::E(sim$g) %in% path[grepl("epath", names(path))]], + index = path_edge_ind, name = "weight") <- 0.00001 # get vertices