WinterCrops.Rmd
library(ram)
#> Warning: replacing previous import 'DT::dataTableOutput' by
#> 'shiny::dataTableOutput' when loading 'ram'
#> Warning: replacing previous import 'DT::renderDataTable' by
#> 'shiny::renderDataTable' when loading 'ram'
A Mediterranean farm plans to allocate land to 4 winter crops: - Gramineae: Oat, Barley - Legumes: Fava bean, Lupin
# Step 1: Define Resource Constraints (flexible min/max for each crop)
resources <- data.frame(
resource = c("land", "labor","nitrogen"),
availability = c(15, 350, 500),
direction = c("<=", "<=","<=")
)
print(resources)
#> resource availability direction
#> 1 land 15 <=
#> 2 labor 350 <=
#> 3 nitrogen 500 <=
# Step 2: Define Activities
activities <- data.frame(
activity = c("oat", "barley", "lupin", "fava"),
land = c(1, 1, 1, 1),
labor = c(20, 25, 15, 30),
nitrogen = c(80, 100, 0, 30),
objective = c(400, 450, 350, 500)
)
print(activities)
#> activity land labor nitrogen objective
#> 1 oat 1 20 80 400
#> 2 barley 1 25 100 450
#> 3 lupin 1 15 0 350
#> 4 fava 1 30 30 500
# Step 3: Build and Solve the Model
model <- create_ram_model(resources, activities)
solution <- solve_ram(model, direction = "max")
summary_ram(solution)
cat("Maximum gross margin (EUR):", solution$objective_value, "\n")
#> Maximum gross margin (EUR): 6500
plot_ram(solution)