#Tengo 4 cargas, todas pueden ser distribuidas en delantero , central o trasero. #XiD : toneladas de la carga i en el delantero #XiC: toneladas de la carga i en el central #XiR: toneladas de la carga i en el trasero #i=1,2,3,4 #Objetivo = maximizar ganancias #MAX 320X1D+320X1C+320X1T+ 400X2D+400X2C+400X2T+360X3D+360X3C+360X3T+290X4D+290X4C+290X4T obj<-c(320,320,320,400,400,400,360,360,360,290,290,290) #Capacidad de carga en compartimientos D,C,T #1)X1D+X2D+X3D+X4D<12 #2)X1C+X2C+X3C+X4C<18 #3)X1T+X2T+X3T+X4T<10 #Capacidad de cargas i #4)X1D+X1C+X1T<20 #5)X2D+X2C+X2T<16 #6)X3D+X3C+X3T<25 #7)X4D+X4C+X4T<13 #Relación volumen con capacidad #8)500X1D+700X2D+600X3D+400X4D<7000 #9)500X1C+700X2C+600X3C+400X4C<9000 #10)500X1T+700X2T+600X3T+400X4T<5000 # "proporción de la capacidad en cada compartimiento" #11) XD/12 - XC/18=0 #12) XD/12-XC/10=0 #11)0.0833X1D+0.0833X2D+0.0833X3D+0.0833X4D-0.05556X1C-0.05556X2C-0.05556X3C-0.05556X4C=0 #12)0.0833X1D+0.0833X2D+0.0833X3D+0.0833X4D-0.1X1T-0.1X2T-0.1X3-0.1X4T=0 #Matriz de restricciones 13x12 A<-matrix(ncol=12,nrow=13) A[1,]<-c(1,0,0,1,0,0,1,0,0,1,0,0) A[2,]<-c(0,1,0,0,1,0,0,1,0,0,1,0) A[3,]<-c(0,0,1,0,0,1,0,0,1,0,0,1) A[4,]<-c(1,1,1,0,0,0,0,0,0,0,0,0) A[5,]<-c(0,0,0,1,1,1,0,0,0,0,0,0) A[6,]<-c(0,0,0,0,0,0,1,1,1,0,0,0) A[7,]<-c(0,0,0,0,0,0,0,0,0,1,1,1) A[8,]<-c(500,0,0,700,0,0,600,0,0,400,0,0) A[9,]<-c(0,500,0,0,700,0,0,600,0,0,400,0) A[10,]<-c(0,0,500,0,0,700,0,0,600,0,0,400) A[11,]<-c(0.7,-0.3,-0.3,0.7,-0.3,-0.3,0.7,-0.3,-0.3,0.7,-0.3,-0.3) A[12,]<-c(-0.45,0.55,-0.45,-0.45,0.55,-0.45,-0.45,0.55,-0.45,-0.45,0.55,-0.45) A[13,]<-c(-0.25,-0.25,0.75,-0.25,-0.25,0.75,-0.25,-0.25,0.75,-0.25,-0.25,0.75) print(A) #Vector de direcciones dir<-c("<","<","<","<","<","<","<","<","<","<","=","=","=") #Vectores de valores de la derecha rhs<-c(12,18,10,20,16,25,13,7000,9000,5000,0,0,0) #LpSolve library(lpSolve) SOLUCION<-lp(direction = "max",objective.in = obj,const.mat = A,const.dir = dir,const.rhs = rhs) print(SOLUCION) Cargas<-SOLUCION$solution print(Cargas) #Analisis de soluciones #GANANCIA TOTAL= 13 330 #X1D=0 #X1C=14.67 #X1T=0 #X2D=7.33 #X2C=0 #X2T=3.33 #X3D=0 #X3C=1.67 #X3T=0 #X4D=4.67 #X4C=1.67 #X4T=6.67 #X1=14.67 / X2=10.67 / X3=1.67 / x4=13 #XD=12 / XC=18 / XT=10