ram: Resource Allocation Models for Agro-Pastoral Systems
Abstract
Tools to define and solve resource allocation models (RAM) for agro-pastoral systems.
Full text
Package ‘ram’ October 21, 2025 Type Package Title Resource Allocation Models for Agro-Pastoral Systems Version 0.0.0.9001 Description Tools to define and solve resource allocation models (RAM) for agro-pastoral systems. License MIT + file LICENSE Imports dplyr, plotly, shiny (>= 1.5.0), DT, golem, lpSolve, config, bslib, openxlsx Roxygen list(markdown = TRUE) RoxygenNote 7.3.3 Suggests knitr, ggplot2, readxl, rmarkdown, htmltools, testthat, pkgdown Encoding UTF-8 VignetteBuilder knitr Config/testthat/edition 3 Rtopics documented: app_server.......................................... 2 app_ui............................................ 2 create_ram_model...................................... 3 1
2app_ui define_activities....................................... 3 define_resources ...................................... 4 get_extdata ......................................... 4 namespace-overrides .................................... 5 plot_ram........................................... 5 ram_optimize ........................................ 6 run_app ........................................... 7 run_app_builder....................................... 7 run_app_solve........................................ 7 run_scenarios ........................................ 8 sensitivity_ram ....................................... 8 solve_ram.......................................... 9 summary_ram........................................ 9 Index 10 app_server The application server-side Description The application server-side Usage app_server(input, output, session) Arguments input, output, session Internal parameters for shiny. DO NOT REMOVE. app_ui The application User-Interface Description The application User-Interface Usage app_ui(request)
create_ram_model 3 create_ram_model Create a RAM Model Description Combines resources and activities into a RAM model object. Usage create_ram_model(resources, activities) Arguments resources Data frame from define_resources(). activities Data frame from define_activities(). Value List of class ’ram_model’. define_activities Define Activities Description Creates a data frame describing each activity, using resource names for columns. Usage define_activities(activities, activity_requirements_matrix, objective) Arguments activities Character vector of activity names. activity_requirements_matrix Numeric matrix (resources x activities) of resource usage per activity. Row names must be resource names. objective Numeric vector of objective function coefficient per activity (e.g., profit for maximization, cost for minimization). Value Data frame with one row per activity, columns for each resource (named), and an objective column.
4get_extdata define_resources Define Resource Constraints Description Creates a data frame of resource constraints for the RAM model, allowing both upper ("<=``) and lower (">="‘) bounds. Usage define_resources(resources, availability, direction) Arguments resources Character vector of constraint/resource names (e.g., "land", "labor", "protein_min"). availability Numeric vector of right-hand sides (amounts available or required). direction Character vector of constraint directions; each value must be either "<=" or ">=". Value Data frame with columns: resource,availability, and direction. Examples # Upper bounds only define_resources( resources = c("land", "labor"), availability = c(100, 200), direction = c("<=", "<=") ) # Mixed upper/lower bounds (min requirement for protein, max for feed) define_resources( resources = c("protein_min", "feed_max"), availability = c(2.5, 10), direction = c(">=", "<=") ) get_extdata Get Path to Extdata File Description Returns the installed path to a file bundled in inst/extdata.
namespace-overrides 5 Usage get_extdata(filename, mustWork = TRUE) Arguments filename Name of file under inst/extdata mustWork Logical; if TRUE throws error if not found Value Full path to the installed extdata file namespace-overrides Namespace Overrides for DT - Shiny Description We want to use DT’s versions of the table-output functions, not shiny’s. This tells R to import all of shiny except those. plot_ram Plot RAM Model Solution (plotly version) Description Visualizes the optimal allocation (activities) as an interactive barplot. Usage plot_ram(solution) Arguments solution List returned by solve_ram().
6ram_optimize ram_optimize Optimize a Resource Allocation Model Description Solves a linear programming model for resource allocation in agro-pastoral systems. Usage ram_optimize(profit, resource_use, availability) Arguments profit Numeric vector. Profit (or objective coefficient) for each activity. resource_use Matrix. Rows = resources, Columns = activities. Each entry gives the use of resource per activity unit. availability Numeric vector. Total available amount for each resource (must match number of rows in resource_use). Value A list with: optimal_activities Named vector of optimal activity levels max_profit Optimal value of the objective function status Status code from lpSolve (0 = success) Examples profit <- c(20, 25) resource_use <- matrix(c(1, 2, 2, 3, 3, 0), nrow = 3, byrow = TRUE) rownames(resource_use) <- c("land", "labor", "feed") colnames(resource_use) <- c("grazing", "haymaking") availability <- c(100, 200, 300) names(availability) <- rownames(resource_use) ram_optimize(profit, resource_use, availability)
run_app 7 run_app Launch the RAM app in specified mode ("solve" or "builder") Description Launch the RAM app in specified mode ("solve" or "builder") Usage run_app(mode = c("solve", "builder"), ...) Arguments mode Character, one of "solve" or "builder" (default: "solve") ... Additional golem options run_app_builder Launch the RAM app in builder mode Description Launch the RAM app in builder mode Usage run_app_builder(...) Arguments ... Additional golem options passed to the app run_app_solve Launch the RAM app in solver mode Description Launch the RAM app in solver mode Usage run_app_solve(...) Arguments ... Additional golem options passed to the app (via get_golem_options())
8sensitivity_ram run_scenarios Run a batch of resource-allocation scenarios Description Run a batch of resource-allocation scenarios Usage run_scenarios(res_def, act_def, scenario_list, direction = "max") Arguments res_def A resources spec as returned by define_resources() act_def An activities spec as returned by define_activities() scenario_list A named list of vectors; each vector are the alternative values for one resource (names must match res_def$resource) direction "max" or "min" Value A data.frame with one row per scenario, the scenario inputs, the achieved objective, and one column per activity giving the optimal level of that activity. sensitivity_ram Sensitivity Analysis for RAM (from solution object) Description Sensitivity Analysis for RAM (from solution object) Usage sensitivity_ram(solution) Arguments solution List returned by solve_ram(). Value Data frame: resource, direction, availability, shadow_price, lower/upper bounds
solve_ram 9 solve_ram Solve a Resource Allocation Model with Mixed Constraints Description Solve a Resource Allocation Model with Mixed Constraints Usage solve_ram(model, direction = "max") Arguments model A ’ram_model’ object as returned by create_ram_model(). direction "max" to maximize the objective, "min" to minimize (default: "max"). Value A list with: optimal_activities Named vector of optimal activity levels objective_value Optimal value of the objective function status Status code from lpSolve (0 = success) summary_ram Summary Table for RAM Model Solution (DT version) Description Returns a DT table summarizing the solution of a solved RAM model. Usage summary_ram(solution) Arguments solution List returned by solve_ram(). Value DT datatable with optimal activity levels and objective value.