ram
Package
This repository provides:
ram
for Resource Allocation Modeling using linear programming.You can install the development version directly from GitHub:
# install.packages("remotes")
remotes::install_github("https://github.com/PAS-AGRO-PAS/ram")
Once installed, load the package:
library(ram)
The Shiny app provides a GUI to:
Download CSV templates for resources & activities
Upload your own data or edit in‐place
Add / Remove rows dynamically
Solve the LP (maximize or minimize)
View optimal activity levels, resource usage, objective value, plots & sensitivity
Launch it with:
# From within R or RStudio:
ram::run_app()
A browser window will open at http://127.0.0.1:xxxx/.
For a worked example (the Mediterranean Mixed Farm), see the package vignette:
vignette("WinterCropsAreaBounds", package = "ram")
This illustrates:
Defining flexible resource constraints
Building the activity matrix
Solving the LP and interpreting results
Performing sensitivity analysis on shadow prices
Below is a minimal example of programmatic use:
library(ram)
# 1) Define resources
res <- define_resources(
resources = c(
"land","labor","nitrogen",
"oat_min","oat_max",
"barley_min","barley_max",
"lupin_min","lupin_max",
"fava_min","fava_max",
"pasture_min","pasture_max"
),
availability = c(
15, 350, 500, # totals
2, 8, # oat
1, 6, # barley
2, 5, # lupin
1, 3, # fava
2, 4 # pasture
),
direction = c(
"<=", "<=", "<=", # totals
">=", "<=", # oat
">=", "<=", # barley
">=", "<=", # lupin
">=", "<=", # fava
">=", "<=" # pasture
)
)
# 2) Define activities matrix
# after you've done `res <- define_resources(…)`
tech <- rbind(
land = c( 1, 1, 1, 1, 1),
labor = c( 20, 25, 15, 30, 10),
nitrogen = c( 80,100, 0, 30, 0),
oat_min = c( 1, 0, 0, 0, 0),
oat_max = c( 1, 0, 0, 0, 0),
barley_min = c( 0, 1, 0, 0, 0),
barley_max = c( 0, 1, 0, 0, 0),
lupin_min = c( 0, 0, 1, 0, 0),
lupin_max = c( 0, 0, 1, 0, 0),
fava_min = c( 0, 0, 0, 1, 0),
fava_max = c( 0, 0, 0, 1, 0),
pasture_min = c( 0, 0, 0, 0, 1),
pasture_max = c( 0, 0, 0, 0, 1)
)
colnames(tech) <- c("oat","barley","lupin","fava","pasture")
# profit margins per hectare
obj <- c(oat=400, barley=450, lupin=350, fava=500, pasture=360)
acts <- define_activities(
activities = colnames(tech),
activity_requirements_matrix = tech,
objective = c(oat=400, barley=450, lupin=350, fava=500, pasture=360)
)
# 3) Build & solve
model <- create_ram_model(res, acts)
solution <- solve_ram(model, direction = "max")
# 4) Inspect results
print(solution$optimal_activities)
print(solution$objective_value)
print(sensitivity_ram(solution))
plot_ram(solution)