R/change_making.R

Defines functions change_making

Documented in change_making

##
##  c h a n g e _ m a k i n g . R
##


change_making <- function(items, value) {
    stopifnot(is.numeric(items), is.numeric(value))
    if (any(items != floor(items)))
        stop("Argument 'items' must be a vector of integers.")
    if (length(value) != 1 || value != floor(value))
        stop("Argument 'value' must be a single integer.")
    
    n <- length(items)
    obj <- rep(1, n)
    sol <- lp( direction = "min",
               objective.in = obj,
               const.mat = matrix(items, nrow = 1),
               const.dir = "==",
               const.rhs = value,
               all.int = TRUE )

    if (sol$objval == 0) {
        return(list(count = 0, solution = c()))
    } else
        return(list(count = sol$objval, solution = sol$solution))
}

Try the adagio package in your browser

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

adagio documentation built on Oct. 26, 2023, 5:08 p.m.