-
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.
Website prepared and final changes to the package.
- Loading branch information
melinavidoni
committed
May 29, 2018
1 parent
6a9e072
commit 1824baf
Showing
25 changed files
with
861 additions
and
134 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
exportPattern("^[^\\.]") | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(direct_graph) | ||
export(get_all_nodes) | ||
export(get_shortest_path) | ||
export(modify_graph_hsu) | ||
export(modify_graph_vd) | ||
export(parse_vpath) | ||
importFrom(foreach,"%dopar%") | ||
importFrom(magrittr,"%>%") | ||
importFrom(igraph,E) | ||
importFrom(igraph,graph_from_data_frame) | ||
importFrom(igraph,shortest_paths) | ||
importFrom(magrittr,"%>%") |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#' @export | ||
#' @title iGraph Shortest Path | ||
#' | ||
#' @description A original node N_i can appear on a transformed gStar as different N_i* equivalent nodes. Therefore, | ||
#' this becomes a limitation when searching for a shortest path inside gStar. As a result: all N_i* need to be | ||
#' considered as possible destination nodes when looking for the shortest path. This function is a wrapper for this | ||
#' behavior, providing a straightforward implementation using iGraph capabilities. However, it aims to provide | ||
#' guidance on how to build a similar algorithm for different path-finding algorithms. | ||
#' | ||
#' It is important to mention that new nodes are only considered as destination nodes, and they are not search | ||
#' for origin nodes. This is because N* nodes can only be reached after traveling through gStar nodes. For example, | ||
#' a node \code{"f|e|r"} is actually indicating that \code{"r"} has been reached after traveling through the nodes | ||
#' \code{"f"} and \code{"e"}. | ||
#' | ||
#' @family iGraph Integration | ||
#' | ||
#' @param g A gStar digraph in data frame format, translated using one of the available functions. The weight or cost attribute | ||
#' of each arc of the graph must be stored in a specific column named \code{weight}. | ||
#' @param origin The name of the starting node from G for the path. It must be written as it appears in G, and it is | ||
#' preferable to use a character format, but this can also be of any simple type. No lists or vectors are allowed. | ||
#' @param dest The name of the destination node from G for the path. It must be written as it appears in G, and it is | ||
#' preferable to use a character format, but this can also be of any simple type. No lists or vectors are allowed. | ||
#' | ||
#' @return The shortest path from \code{origin} node to \code{dest} node, calculated in G*, to include the forbidden paths. | ||
#' It uses iGraph's functionalities. | ||
#' | ||
#' @importFrom igraph graph_from_data_frame | ||
#' @importFrom igraph shortest_paths | ||
#' @importFrom igraph E | ||
#' | ||
#' @examples | ||
#' # Given a specific gStar graph: | ||
#' gStar <- structure(list(from = c("u|v", "s|u|v", "s|u", "s", "s", "u", "w", "w", "x", "x", | ||
#' "v", "v", "y", "y", "s", "s|u", "u", "u|v"), | ||
#' to = c("t", "u|v|y", "w", "w", "x", "w", "v", "y", "w", "y", "y", "t", | ||
#' "t", "u", "s|u", "s|u|v", "u|v", "u|v|y"), | ||
#' weight = c(12L, 3L, 5L, 9L, 7L, 5L, 11L, 10L, 1L, 2L, 3L, 12L, 13L, 0L, 8L, 4L, 4L, 3L)), | ||
#' class = "data.frame", row.names = c(NA, -18L), .Names = c("from", "to", "weight")) | ||
#' gStar | ||
#' | ||
#' # Obtain the shortest path | ||
#' get_shortest_path(gStar, "s", "v") | ||
#' | ||
#' | ||
get_shortest_path <- function(g, origin, dest) { | ||
# Convert the graph | ||
g.i <- graph_from_data_frame(g) | ||
|
||
# Get all the shortest paths to each node | ||
sp <- shortest_paths(g.i, from = origin, to = get_all_nodes(gStar, dest), weights = E(g.i)$weight, output = "both") | ||
|
||
# Return the shortest path | ||
sp$vpath[which.min( lapply(sp$epath, function(y) | ||
ifelse(length(y) != 0, sum(E(g.i)$weight[ y[[1]] ]), 999999999)) )] [[1]] | ||
} |
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
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
Oops, something went wrong.