#using for the 1st time the package install.packages("linprog") #using the package library(linprog) #inserting parameters #profit parameters from objective function cvec=c(40,100) ##quantity parameters from the st (right side) bvec=c(20,12) #matrix for decision variable coefficients from the constraints in the order they appear A=matrix(c(2,4,1,3),nrow=2,ncol=2,byrow=T) #Can solve this with geogebra #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) #before i had this values for the machines bvec=c(20,12) 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 #if i want to compare the objective function values from before and now (+1H of MA) summary((LP1)) #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 #create the corresponding table for the variables above Sensitivity=as.data.frame(results) Sensitivity #R allows for full customization, here we can rename the columns so that it is more #clear what the values we see in the table are. So for V1 I have a column with #objective function values names(Sensitivity) = c("Value of Objective Function", "Quantity of X1","Quantity of X2","shadow price","Change of constraint") Sensitivity #installing 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 #lower limit of variation of the coefficients of the objective function using lpsolve lp("max",cvec,A,constr.dir,bvec,compute.sens=1)$sens.coef.from #upper limit of variation of the coefficients of the objective function using lpsolve lp("max",cvec,A,constr.dir,bvec,compute.sens=1)$sens.coef.to #changing positions of arguments inside the command #this is the old lp("max", cvec, A, constr.dir, bvec) the right vector 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)