Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ Authors@R: c(
person("Robin", "Lovelace", role = "ctb"),
person("Andrew", "Smith", role = "ctb"),
person("Malcolm", "Morgan", role = "ctb"),
person("Andrea", "Gilardi", role="ctb", comment = c(ORCID = "0000-0002-9424-7439")),
person("Eduardo", "Leoni", role="ctb", comment = c(ORCID = "0000-0003-0955-5232")),
person("Andrea", "Gilardi", role = "ctb",
comment = c(ORCID = "0000-0002-9424-7439")),
person("Eduardo", "Leoni", role = "ctb",
comment = c(ORCID = "0000-0003-0955-5232")),
person("Shane", "Saunders", role = "cph",
comment = "Original author of included code for priority heaps"),
person("Stanislaw", "Adaszewski", role = "cph",
comment = "author of include concaveman-cpp code")
comment = "author of include concaveman-cpp code"),
person("Harry", "Roberts", , "ts22hr@leeds.ac.uk", role = "ctb",
comment = c(ORCID = "0009-0005-5443-0684"))
)
Description: Distances on dual-weighted directed graphs using
priority-queue shortest paths (Padgham (2019) <doi:10.32866/6945>).
Expand Down Expand Up @@ -63,5 +67,5 @@ Encoding: UTF-8
LazyData: true
NeedsCompilation: yes
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
SystemRequirements: GNU make
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- Add `pairwise` parameter to `dodgr_times()`; thanks to @leoniedu (#314)
- Fix bug with categorical distances that neglected edges through compound junctions (#305)
- Fix bug in duplicating bi-directional edges in weighted sc-class graphs
- Added support for strong components in `dodgr_components()` (#322)
- Added Harry Roberts as a contributor

---

Expand Down
41 changes: 36 additions & 5 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ rcpp_merge_cols <- function (graph) {
#' in \code{sample_one_vertex}
#'
#' @param edge_map edge_map
#' @return std::vector of 2 elements: [0] with value of largest connected
#' @return std::vector of 2 elements: [0] with value of largest connected
#' component; [1] with random index to one edge that is part of that component.
#' @noRd
NULL
Expand Down Expand Up @@ -263,7 +263,35 @@ NULL
#' identify_graph_components
#'
#' Identify initial graph components for each **vertex**
#' Identification for edges is subsequently perrformed with
#' Identification for edges is subsequently performed with
#' \code{rcpp_get_component_vector}.
#'
#' @param v unordered_map <vertex_id_t, vertex_t>
#' @param com component map from each vertex to component numbers
#' @noRd
NULL

#' strong_connect
#'
#' Helper function for applying Tarjan's algroithm to identify
#' strong components recursively
#'
#' @param vt id of vertex currently being evaluated
#' @param v unordered_map <vertex_id_t, vertex_t>
#' @param com component map from each vertex to component numbers
#' @param index_map map from each vertex to index number
#' @param lowlink_map map from each vertex to lowlink number
#' @param on_stack set of all vertices currently on stack
#' @param s stack used to execute algorithm
#' @param index used to execute algoritm
#' @param compnum the current component number
#' @noRd
NULL

#' identify_graph_strong_components
#'
#' Identify initial graph strong components for each **vertex**
#' Identification for edges is subsequently performed with
#' \code{rcpp_get_component_vector}.
#'
#' @param v unordered_map <vertex_id_t, vertex_t>
Expand All @@ -278,11 +306,14 @@ NULL
#' @param graph graph to be processed; stripped down and standardised to five
#' columns
#'
#' @param strong A Boolean flag to indicate whether components should be strong,
#' i.e. its vertices connected bidirectionally. Defaults to FALSE.
#'
#' @return Two vectors: one of edge IDs and one of corresponding component
#' numbers
#' @noRd
rcpp_get_component_vector <- function (graph) {
.Call (`_dodgr_rcpp_get_component_vector`, graph)
rcpp_get_component_vector <- function (graph, strong = FALSE) {
.Call (`_dodgr_rcpp_get_component_vector`, graph, strong)
}

#' rcpp_unique_rownames
Expand Down Expand Up @@ -484,4 +515,4 @@ rcpp_sf_as_network <- function (sf_lines, pr) {
#' @noRd
rcpp_route_times <- function (graph, left_side, turn_penalty) {
.Call (`_dodgr_rcpp_route_times`, graph, left_side, turn_penalty)
}
}
18 changes: 11 additions & 7 deletions R/graph-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,16 @@ dodgr_vertices_internal <- function (graph) {
#' column to `data.frame`.
#'
#' @param graph A `data.frame` of edges
#' @param strong A Boolean flag to indicate whether components should be strong,
#' i.e. its vertices connected bidirectionally. Defaults to FALSE.
#' @return Equivalent graph with additional `component` column,
#' sequentially numbered from 1 = largest component.
#' @family modification
#' @export
#' @examples
#' graph <- weight_streetnet (hampi)
#' graph <- dodgr_components (graph)
dodgr_components <- function (graph) {
dodgr_components <- function (graph, strong = FALSE) {

graph <- tbl_to_df (graph)

Expand All @@ -329,15 +331,17 @@ dodgr_components <- function (graph) {
if (is.na (gr_cols$edge_id)) {
graph2$edge_id <- seq_len (nrow (graph2))
}
cns <- rcpp_get_component_vector (graph2)

cns <- rcpp_get_component_vector (graph2,strong)
indx <- match (graph2$edge_id, cns$edge_id)
component <- cns$edge_component [indx]

# Handle where component numbers contain gaps using frequencies
# Then re-number in order to decreasing component size:
graph$component <- match (
component,
order (table (component), decreasing = TRUE)
)
freqs <- table (component)
sorted_components <- names (freqs) [order (freqs, decreasing = TRUE)]
graph$component <- match (as.character (component), sorted_components)

}

return (graph)
Expand Down
23 changes: 12 additions & 11 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
"identifier": "dodgr",
"description": "Distances on dual-weighted directed graphs using priority-queue shortest paths (Padgham (2019) <doi:10.32866/6945>). Weighted directed graphs have weights from A to B which may differ from those from B to A. Dual-weighted directed graphs have two sets of such weights. A canonical example is a street network to be used for routing in which routes are calculated by weighting distances according to the type of way and mode of transport, yet lengths of routes must be calculated from direct distances.",
"name": "dodgr: Distances on Directed Graphs",
"relatedLink": [
"https://UrbanAnalyst.github.io/dodgr/",
"https://CRAN.R-project.org/package=dodgr"
],
"relatedLink": ["https://UrbanAnalyst.github.io/dodgr/", "https://CRAN.R-project.org/package=dodgr"],
"codeRepository": "https://github.com/UrbanAnalyst/dodgr",
"issueTracker": "https://github.com/UrbanAnalyst/dodgr/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.4.3.015",
"version": "0.4.3.15",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
"url": "https://r-project.org"
},
"runtimePlatform": "R version 4.5.1 (2025-06-13)",
"runtimePlatform": "R version 4.5.1 (2025-06-13 ucrt)",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
Expand Down Expand Up @@ -69,6 +66,13 @@
"givenName": "Eduardo",
"familyName": "Leoni",
"@id": "https://orcid.org/0000-0003-0955-5232"
},
{
"@type": "Person",
"givenName": "Harry",
"familyName": "Roberts",
"email": "ts22hr@leeds.ac.uk",
"@id": "https://orcid.org/0009-0005-5443-0684"
}
],
"copyrightHolder": [
Expand Down Expand Up @@ -362,7 +366,7 @@
},
"SystemRequirements": "GNU make"
},
"fileSize": "37019.613KB",
"fileSize": "72585.397KB",
"citation": [
{
"@type": "ScholarlyArticle",
Expand All @@ -381,10 +385,7 @@
"@type": "PublicationIssue",
"datePublished": "2019",
"isPartOf": {
"@type": [
"PublicationVolume",
"Periodical"
],
"@type": ["PublicationVolume", "Periodical"],
"name": "Transport Findings"
}
}
Expand Down
5 changes: 4 additions & 1 deletion man/dodgr_components.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,14 @@ BEGIN_RCPP
END_RCPP
}
// rcpp_get_component_vector
Rcpp::List rcpp_get_component_vector(const Rcpp::DataFrame& graph);
RcppExport SEXP _dodgr_rcpp_get_component_vector(SEXP graphSEXP) {
Rcpp::List rcpp_get_component_vector(const Rcpp::DataFrame& graph, bool strong);
RcppExport SEXP _dodgr_rcpp_get_component_vector(SEXP graphSEXP, SEXP strongSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const Rcpp::DataFrame& >::type graph(graphSEXP);
rcpp_result_gen = Rcpp::wrap(rcpp_get_component_vector(graph));
Rcpp::traits::input_parameter< bool >::type strong(strongSEXP);
rcpp_result_gen = Rcpp::wrap(rcpp_get_component_vector(graph, strong));
return rcpp_result_gen;
END_RCPP
}
Expand Down Expand Up @@ -441,7 +442,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_dodgr_rcpp_contract_graph", (DL_FUNC) &_dodgr_rcpp_contract_graph, 2},
{"_dodgr_rcpp_merge_cols", (DL_FUNC) &_dodgr_rcpp_merge_cols, 1},
{"_dodgr_rcpp_sample_graph", (DL_FUNC) &_dodgr_rcpp_sample_graph, 2},
{"_dodgr_rcpp_get_component_vector", (DL_FUNC) &_dodgr_rcpp_get_component_vector, 1},
{"_dodgr_rcpp_get_component_vector", (DL_FUNC) &_dodgr_rcpp_get_component_vector, 2},
{"_dodgr_rcpp_unique_rownames", (DL_FUNC) &_dodgr_rcpp_unique_rownames, 3},
{"_dodgr_rcpp_points_index_par", (DL_FUNC) &_dodgr_rcpp_points_index_par, 2},
{"_dodgr_rcpp_points_to_edges_par", (DL_FUNC) &_dodgr_rcpp_points_to_edges_par, 2},
Expand Down
Binary file added src/dodgr.dll
Binary file not shown.
Loading