R/greedy.R

Defines functions greedy

Documented in greedy

#' Greedy one-to-one matching of pairs
#' 
#' @param x id's of lhs of pairs
#' @param y id's of rhs of pairs
#' @param weight weight of pair
#' 
#' @details 
#' Pairs with the highest weight are selected as long a neither the lhs as the
#' rhs are already selected in a pair with a higher weight. 
#' 
#' 
#' @useDynLib reclin
#' @import Rcpp
#' @importFrom Rcpp evalCpp
greedy <- function(x, y, weight) {
  stopifnot(length(x) == length(y))
  stopifnot(length(x) == length(weight))
  o <- order(weight, decreasing = TRUE)
  x <- x[o]
  y <- y[o]
  s <- greedy_rcpp(x, y)
  s[o] <- s
  s
}

Try the reclin package in your browser

Any scripts or data that you put into this service are public.

reclin documentation built on Nov. 23, 2021, 9:09 a.m.