Skip to content

Instantly share code, notes, and snippets.

@huberflores
Last active August 6, 2018 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save huberflores/3f0388ebff9786988f8c to your computer and use it in GitHub Desktop.
Save huberflores/3f0388ebff9786988f8c to your computer and use it in GitHub Desktop.
Linear programming in R - basic example
#
#author Huber Flores
#
library(lpSolveAPI)
library(ggplot2)
library(reshape)
library(gridExtra)
#To be extended to provide these variables dinamically into the model
cloud<-data.frame(servertype=c('t1','t2','t3'), servercapacity=c(10,8,12), costserver=c(0.5,0.75,1.25))
qoeload <- data.frame(qoegroups=c('a1','a2','a3'), qoeusers=c(5,10,15))
#make.lp(constraints, decision variables)
lpmodel<-make.lp(0,3)
set.objfn(lpmodel, c(0.5,0.75,1.25))
add.constraint(lpmodel, c(10, 0, 0), ">=", 50)
add.constraint(lpmodel, c(0, 8, 0), ">=", 25)
add.constraint(lpmodel, c(0,0,12), ">=", 100)
RowNames <- (cloud$servertype)
ColNames <- (qoeload$qoegroups)
dimnames(lpmodel) <- list(RowNames, ColNames)
solve(lpmodel)
get.objective(lpmodel)
get.variables(lpmodel)
get.constraints(lpmodel)
write.lp(lpmodel,'model.lp',type='lp')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment