using for the 1st time the package install.packages("linprog") #using the package library(linprog) #inserting parameters cvec=c(40,100) bvec=c(20,12) A=matrix(c(2,4,1,3),nrow=2,ncol=2,byrow=T) #solving our problem LP<-solveLP(cvec,bvec,A,maximum=T, const.dir=rep("<=", length(bvec))) #Showing results summary(LP) #print(LP) #increase of A cvec=c(40,100) bvec=c(21,12) A=matrix(c(2,4,1,3),nrow=2,ncol=2,byrow=T) LP1<-solveLP(cvec,bvec,A,maximum=T, const.dir=rep("<=", length(bvec))) #print(LP1) summary(LP1) #shadow price dx1 =7.5-6 dx2 =1.5-2 shadow.price1=40*dx1+100*dx2 shadow.price1 #decreasee of A cvec=c(40,100) bvec= c(19,12) A=matrix(c(2,4,1,3),nrow=2,ncol=2,byrow=T) LP2 =solveLP(cvec,bvec,A,maximum=T, const.dir=rep("<=", length(bvec))) summary(LP2) #shadow price dx1 = 4.5-6 dx2 = 2.5-2 shadow.price2=40*dx1+100*dx2 shadow.price2 #increase of B cvec=c(40,100) bvec=c(20,13) A=matrix(c(2,4,1,3),nrow=2,ncol=2,byrow=T) LP3=solveLP(cvec,bvec,A,maximum=T, const.dir=rep("<=", length(bvec))) summary(LP3) #shadow price dx1 = 4-6 dx2 = 3-2 shadow.price3=40*dx1+100*dx2 shadow.price3 #decrease of B cvec=c(40,100) bvec=c(20,11) A=matrix(c(2,4,1,3),nrow=2,ncol=2,byrow=T) LP4=solveLP(cvec,bvec,A,maximum=T, const.dir=rep("<=", length(bvec))) summary(LP4) #shadow price dx1 = 8-6 dx2 = 1-2 shadow.price4=40*dx1+100*dx2 shadow.price4 #total results results= rbind(c(440,6,2,"","initial LP"),c(450,7.5,1.5,10,"Increase 1st constraint"), c(430,4.5,2.5,-10,"Decrease 1st constraint"),c(460,4,2,20,"Increase 2nd constraint"), c(420,8,1,-20,"Decrease 2nd constraint")) results Sensitivity=as.data.frame(results) Sensitivity names(Sensitivity) = c("Value of Objective Function", "Quantity of X1","Quantity of X2","shadow price","Change of constraint") Sensitivity #instaalling and using the package install.packages("lpSolve") library(lpSolve) #inserting parameters cvec=c(40,100) ; bvec=c(20,12) A=matrix(c(2,4,1,3),nrow=2,ncol=2,byrow=T) #always insert the direction for each one constraint constr.dir=c("<=","<=") #counting the value of O.F. LP5 = lp("max",cvec, A, constr.dir, bvec,compute.sens=0); LP5 #or lp("max",cvec,A,constr.dir,bvec,compute.sens=0)$objval #successful or no? (0 Επιτυχής εκτέλεση του αλγορίθμου/ 1,2,3,4,5 ΝΟ) lp("max",cvec,A,constr.dir,bvec)$status #showing the quantities of x1,x2 lp("max", cvec, A, constr.dir, bvec)$solution #showing shadow prices lp("max",cvec,A,constr.dir,bvec,compute.sens=1)$duals #changing positions of arguments inside the command lp("max",bvec, A, constr.dir,cvec) lp("max",bvec, A, constr.dir,cvec)$solution lp("max",A,cvec,constr.dir,bvec) lp("max",A,cvec,constr.dir,bvec)$solution #using lpSolve through linprog library(linprog) cvec=c(40,100) ; bvec=c(20,12) A=matrix(c(2,4,1,3),nrow=2,ncol=2,byrow=T) LP6=solveLP(cvec,bvec,A,maximum=T,const.dir=c("<=","<="), lpSolve = T) summary(LP6) #shadow prices LP7 =solveLP(cvec,bvec,A,maximum=T,const.dir=c("<=","<="), lpSolve = T, solve.dual = T) print(LP7)