Package rsppfp. November 20, 2018

Similar documents
Package cattonum. R topics documented: May 2, Type Package Version Title Encode Categorical Features

Package fastdummies. January 8, 2018

Package robotstxt. November 12, 2017

Package bisect. April 16, 2018

Package canvasxpress

Package validara. October 19, 2017

Package ECctmc. May 1, 2018

Package messaging. May 27, 2018

Package SEMrushR. November 3, 2018

Package docxtools. July 6, 2018

Package geojsonsf. R topics documented: January 11, Type Package Title GeoJSON to Simple Feature Converter Version 1.3.

Package facerec. May 14, 2018

Package kdtools. April 26, 2018

Package wrswor. R topics documented: February 2, Type Package

Package postgistools

Package ggimage. R topics documented: November 1, Title Use Image in 'ggplot2' Version 0.0.7

Package qualmap. R topics documented: September 12, Type Package

Package WordR. September 7, 2017

Package splithalf. March 17, 2018

Package widyr. August 14, 2017

Package semver. January 6, 2017

Package knitrprogressbar

Package snakecase. R topics documented: March 25, Version Date Title Convert Strings into any Case

Package gggenes. R topics documented: November 7, Title Draw Gene Arrow Maps in 'ggplot2' Version 0.3.2

Package reval. May 26, 2015

Package dkanr. July 12, 2018

Package statsdk. September 30, 2017

Package barcoder. October 26, 2018

Package jpmesh. December 4, 2017

Package calpassapi. August 25, 2018

Package NFP. November 21, 2016

Package vinereg. August 10, 2018

Package sfdct. August 29, 2017

Package censusr. R topics documented: June 14, Type Package Title Collect Data from the Census API Version 0.0.

Package ggimage. R topics documented: December 5, Title Use Image in 'ggplot2' Version 0.1.0

Package embed. November 19, 2018

Package datasets.load

Package postal. July 27, 2018

Package liftr. R topics documented: May 14, Type Package

Package omu. August 2, 2018

Package preprosim. July 26, 2016

Package gtrendsr. October 19, 2017

Package fitbitscraper

Package comparedf. February 11, 2019

Package rgho. R topics documented: January 18, 2017

Package keyholder. May 19, 2018

Package rbgm. May 18, 2018

Package repec. August 31, 2018

Package queuecomputer

Package bigreadr. R topics documented: August 13, Version Date Title Read Large Text Files

Package datapasta. January 24, 2018

Package climber. R topics documented:

Package vip. June 15, 2018

Package fastqcr. April 11, 2017

Package clipr. June 23, 2018

Package gifti. February 1, 2018

Package mdftracks. February 6, 2017

Package FSelectorRcpp

Package projector. February 27, 2018

Package spark. July 21, 2017

Package gtrendsr. August 4, 2018

Package crossword.r. January 19, 2018

Package TrafficBDE. March 1, 2018

Package SNPediaR. April 9, 2019

Package ruler. February 23, 2018

Package utilsipea. November 13, 2017

Package auctestr. November 13, 2017

Package readxl. April 18, 2017

Package editdata. October 7, 2017

Package farver. November 20, 2018

Package tidytransit. March 4, 2019

Package rzeit2. January 7, 2019

Package catenary. May 4, 2018

Package condusco. November 8, 2017

Package balance. October 12, 2018

Package loggit. April 9, 2018

Package glue. March 12, 2019

Package rprojroot. January 3, Title Finding Files in Project Subdirectories Version 1.3-2

Package tibble. August 22, 2017

Package skynet. December 12, 2018

Package mapsapi. March 12, 2018

Package customlayout

Package pcr. November 20, 2017

Package pdfsearch. July 10, 2018

Package profvis. R topics documented:

Package dbx. July 5, 2018

Package data.world. April 5, 2018

Package strat. November 23, 2016

Package opencage. January 16, 2018

Package driftr. June 14, 2018

Package pwrab. R topics documented: June 6, Type Package Title Power Analysis for AB Testing Version 0.1.0

Package graphframes. June 21, 2018

Package githubinstall

Package fingertipsr. May 25, Type Package Version Title Fingertips Data for Public Health

Package stapler. November 27, 2017

Package spelling. December 18, 2017

Package guardianapi. February 3, 2019

Package redlistr. May 11, 2018

Package wdman. January 23, 2017

Package UNF. June 13, 2017

Transcription:

Package rsppfp November 20, 2018 Title R's Shortest Path Problem with Forbidden Subpaths Version 1.0.3 Maintainer Melina Vidoni <melinavidoni@santafe-conicet.gov.ar> An implementation of functionalities to transform directed graphs that are bound to a set of known forbidden paths. There are several transformations, following the rules provided by Villeneuve and Desaulniers (2005) <doi: 10.1016/j.ejor.2004.01.032>, and Hsu et al. (2009) <doi: 10.1007/978-3- 642-03095-6_60>. The resulting graph is generated in a data-frame format. See rsppfp website for more information, documentation an examples. Depends R (>= 3.4.0) Imports dplyr, foreach, doparallel, igraph, tidyr, stringr License GPL-3 Encoding UTF-8 LazyData true RoxygenNote 6.1.0 Suggests knitr, rmarkdown, testthat, covr, ggplot2 VignetteBuilder knitr URL https://github.com/melvidoni/rsppfp BugReports https://github.com/melvidoni/rsppfp/issues NeedsCompilation no Author Melina Vidoni [aut, cre] (<https://orcid.org/0000-0002-4099-1430>), Aldo Vecchietti [aut] Repository CRAN Date/Publication 2018-11-20 15:50:03 UTC 1

2 direct_graph R topics documented: direct_graph......................................... 2 get_all_nodes........................................ 3 get_shortest_path...................................... 4 modify_graph_hsu..................................... 5 modify_graph_vd...................................... 7 parse_vpath......................................... 8 rsppfp............................................ 9 Index 10 direct_graph Undirected Graph Translator The SPPFP transformation functions only work with digraphs -i.e. directed graphs. Because in a digraph arcs can only be traveled in one direction, from the origin node to the destination arc, if undirected graphs are used as-is, the resultng G* will not be accurate. Therefore, this functions translates an undirected graph to a digraph by duplicating each arc and swapping the duplicate s from and to nodes. direct_graph(graph, cores = 1L) graph cores An undirected graph written as a data frame, in which each rows represent an arc. The columns must be named from and to, and can be of any data type. Each row can have additional attributes, and no cells can be NULL or NA. This algorithm can be run using R s parallel processing functions. This variable represents the number of processing cores you want to assign for the transformation. The default value is one single core. It is suggested to not assign all of your available cores to the function. A new graph, with the same columns and data types of the original graph. This new graph is twice as big as the original, as new arcs are added to represent that each arc can be traveled in both directions. See Also Other Parsers: get_all_nodes, parse_vpath

get_all_nodes 3 # Obtain the graph from any way graph <- data.frame(from = c("s", "s", "s", "u", "u", "w", "w", "x", "x", "v", "v", "y", "y"), to = c("u", "w", "x", "w", "v", "v", "y", "w", "y", "y", "t", "t", "u"), cost = c(1l, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), graph # Translate it digraph <- direct_graph(graph) digraph get_all_nodes Parser for G* nodes. A original node N_i can appear on a transformed G* as different nodes. This is the result of the creation of nodes in the transformation processes. Therefore, it is possible that the original node N does not exists on G*, or that multiple N_i* exist. Hence, as all new nodes are generated using a specific structure for the name -compiling all previous nodes names, split by pipe-, this function allows searching for all the N_i* nodes that are equivalente to N_i. This can be used to find shortest paths to all of them. get_all_nodes(g, originalnode) g originalnode A graph in data frame format, translated using one of the available functions. The name of the original node from G, that needs to be searched within G*. It is preferable to use a character format, but this can also be of any simple type. No lists or vectors are allowed. A new vector of character type, whose elements are all the N_i* equivalent to the original N node. This also includes the original node. See Also Other Parsers: direct_graph, parse_vpath

4 get_shortest_path # Given a specific gstar graph: gstar <- data.frame(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), gstar # Obtain all the nodes equivalent to N_i = "v" get_all_nodes(gstar, "v") get_shortest_path igraph Shortest Path 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 "f e r" is actually indicating that "r" has been reached after traveling through the nodes "f" and "e". get_shortest_path(g, origin, dest, weightcolname) g origin dest 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 weight. 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. 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.

modify_graph_hsu 5 weightcolname The name of the weight column used in the dataframe. If the column does not exist, a name _must_ be provided so that a new weight column is generated. The shortest path from origin node to dest node, calculated in G*, to include the forbidden paths. It uses igraph s functionalities. # Given a specific gstar graph: gstar <- data.frame(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), gstar # Obtain the shortest path get_shortest_path(gstar, "s", "v", "weight") modify_graph_hsu Hsu et al. (2009) Algorithm It is an implementation of Hsu et al. algorithm to transform a digraph and a known set of forbidden paths, into a new graph that does not allow any forbidden path as part of its solutions. modify_graph_hsu(g, f, cores = 1L) g f The digraph to be transformed, written as a data frame where each row represents a directed arc. The columns must be named from and to, and can be of any data type. On each row no cells can be NULL or NA. The set of forbidden paths, written as a data frame. Each row represents a path as a sequence of nodes. Each row may be of different size, filling the empty cells with NA. All nodes involved must be part of g, and no forbidden path can be of size 2. This is because the latter is thought as an arc that should not exist in the first place.

6 modify_graph_hsu cores This algorithm can be run using R s parallel processing functions. This variable represents the number of processing cores you want to assign for the transformation. The default value is one single core. It is suggested to not assign all of your available cores to the function. Details This version of the algorithm produce smaller graphs, with less new nodes and arcs. A new graph, generated following Hsu s backward construction, in which no path includes one of the forbidden subpaths. The graph is returned in a data frame format, where each row represents a directed arc, with or without additional attributes (if corresponds). However, regardless of the data type of the original graph, nodes on the new graph are of type character. The new nodes names are generated by incrementally concatenating the nodes on a forbidden path, but split by a pipe character ( ). See Also https://doi.org/10.1007/978-3-642-03095-6_60 Other Graph Transformation: modify_graph_vd # Obtain a graph and its forbidden subpaths graph <- data.frame(from = c("c", "c", "u", "u", "t", "a", "a", "r", "e", "e", "e", "p", "i", "i", "n", "o"), to = c("u", "p", "e", "t", "a", "r", "i", "u", "r", "i", "p", "n", "n", "o", "o", "m"), fpaths <- data.frame(x1 = c("u", "p", "a", "a"), X2 = c("t", "n", "i", "r"), X3 = c("a", "o", "n", "u"), X4 = c("r", "m", "o", NA), X5 = c("u", NA, NA, NA), # Show the input graph fpaths # Call the function and store the result gstar <- modify_graph_hsu(graph, fpaths) gstar

modify_graph_vd 7 modify_graph_vd Villeneuve and Desaulniers (2005) Algorithm It is an implementation of Villeneuve and Desaulniers algorithm to transform a digraph and a known set of forbidden paths, into a new graph that does not allow any forbidden path as part of its solutions. This algorithm should only be used when there is certainty that no forbidden path is a sub-path (or contains a sub-path) of another forbidden path. modify_graph_vd(g, f, cores = 1L) g f cores The digraph to be transformed, written as a data frame where each row represents a directed arc. The first two columns must be named from and to, and can be of any data type. No cells can be NULL or NA. The set of forbidden paths, written as a data frame. Each row represents a path as a sequence of nodes. Each row may be of different size, filling the empty cells with NA. All nodes involved must be part of g, and no forbidden path can be of size 2. This is because the latter is thought as an arc that should not exist in the first place. Also, no forbidden path can be sub-path (or contain a sub-path) of another forbidden path. The columns names are not relevant. This algorithm can be run using R s parallel processing functions. This variable represents the number of processing cores you want to assign for the transformation. The default value is one single core. It is suggested to not assign all of your available cores to the function. A new graph, generated following Villeneuve s prodcedure, in which no path includes one of the forbidden subpaths. The graph is returned in a data frame format, where each row represents a directed arc. However, regardless of the data type of the original graph, nodes on the new graph are of type character. The new nodes names are generated by incrementally concatenating the nodes on a forbidden path, but split by a pipe character ( ). The new graph includes all of the additional attributes that the original graph had. See Also https://doi.org/10.1016/j.ejor.2004.01.032 Other Graph Transformation: modify_graph_hsu

8 parse_vpath # Obtain a graph and its forbidden subpaths graph <- data.frame(from = c("s", "s", "s", "u", "u", "w", "w", "x", "x", "v", "v", "y", "y"), to = c("u", "w", "x", "w", "v", "v", "y", "w", "y", "y", "t", "t", "u"), cost = c(1l, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), fpaths <- data.frame(v1 = c("s", "u"), V2 = c("u", "v"), V3 = c("v", "y"), V4 = c("t", "u"), # Show the values graph fpaths # Call the function and store the result modify_graph_vd(graph, fpaths) parse_vpath Parser for G* nodes paths. Translates a sequence of nodes from a G* graph, generated with any of the available transformations, to a sequence of nodes in terms of the original G. parse_vpath(vpath) vpath A vector of character type, representing a path as a sequence of nodes. The nodes are supposed to belong to an original graph G, but be written in terms of G*. A new vector of character type, representing the same path as vpath but with the nodes names translated to the original graph G s names. See Also Other Parsers: direct_graph, get_all_nodes

rsppfp 9 # Obtain the vpath from any way, an algorithm or random walk. # Call the parsing function translated_vpath <- parse_vpath( c("s u", "s u v", "u v y", "t") ) # Print the result translated_vpath rsppfp Package: rsppfp Details Transformation algorithms to translate the SPPFP (Shortest Path Problem with Forbidden Paths) to a traditional shortest-path problem that includes the forbidden paths. The SPPFP is a variant of the traditional shortest path problem, in which no solution can include any path listed on a known set of forbidden paths. The current approach to solve this is to translate the existing graph, and its set of forbidden paths, to a graph in which no path will include any forbidden sequence. This package provides straightforward parallel processing capabilities, as well as translation functions to use the algorithms on undirected graphs. It is highly compatible with other network research packages, as it only uses native R data types.

Index direct_graph, 2, 3, 8 get_all_nodes, 2, 3, 8 get_shortest_path, 4 modify_graph_hsu, 5, 7 modify_graph_vd, 6, 7 parse_vpath, 2, 3, 8 rsppfp, 9 rsppfp-package (rsppfp), 9 10