Skip to content

Instantly share code, notes, and snippets.

@retpolanne
Last active October 28, 2018 23:04
Show Gist options
  • Save retpolanne/4dff7af6596bd180820607f3efa9d9da to your computer and use it in GitHub Desktop.
Save retpolanne/4dff7af6596bd180820607f3efa9d9da to your computer and use it in GitHub Desktop.
Solver de programação linear para aulas da Fatec
# To run, execute Rscript linearprogramming.R
# based on https://rpubs.com/abhaypadda/linear-optimization-example
library(lpSolve)
# Objective
objective.in <- c(0.06, 0.08)
# Constraint matrix with 3 rows
const.mat <- matrix(c(8, 6, 1, 2, 1, 2), nrow=3, byrow=TRUE)
# Constraints for each row
constraint_r1 <- (48)
constraint_r2 <- (12)
constraint_r3 <- (20)
const.rhs <- c(constraint_r1, constraint_r2, constraint_r3)
# Direction of each constraint
const.dir <- c(">=", ">=", "<=")
# The optimum solution, that can either have min or max direction
optimum <- lp(direction="min", objective.in, const.mat, const.dir, const.rhs)
optimum$solution
optimum$objval
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment