Last active
August 6, 2018 14:13
-
-
Save huberflores/3f0388ebff9786988f8c to your computer and use it in GitHub Desktop.
Linear programming in R - basic example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
#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