Skip to content

Instantly share code, notes, and snippets.

@Harshit1694
Created July 10, 2019 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Harshit1694/3cc4a709d9057ba71c7e55c456bf0878 to your computer and use it in GitHub Desktop.
Save Harshit1694/3cc4a709d9057ba71c7e55c456bf0878 to your computer and use it in GitHub Desktop.
install.packages("lpSolve")
library(lpSolve)
#Setting the coefficients of decision variables
objective.in=c(25,20)
#Constraint Matrix
const.mat=matrix(c(20,12,5,5),nrow = 2,byrow = T)
#defining constraints
const_time=540 #in minutes
const_res=2000
#RHS for constraints
const.rhs=c(const_res,const_time)
#Direction for constraints
const.dir=c("<=","<=")
#Finding the optimum solution
opt=lp(direction = "max",objective.in,const.mat,const.dir,const.rhs)
summary(opt)
#Objective values of x and y
opt$solution
#Value of objective function at optimal point
opt$objval
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment