|
From: | Sebastián Kruk Gencarelli |
Subject: | Transladate problem from Octave to R |
Date: | Tue, 2 Aug 2022 15:18:04 +0000 |
Dear glpk-users, In Octave: [z_opt,f_min,errnum,extra]=glpk(c,A,b,vlb,vub,ctype,vartype,sense) How can be transformed to use it in R? If I use it: Rglpk_solve_LP(obj = c, mat = A, dir = c("<=", "<=", "<="), rhs = b) Give me an error: Error in Rglpk_call(obj = obj, mat = mat, dir = dir, rhs = rhs, bounds = bounds, :
Arguments 'mat', 'dir', and/or 'rhs' not conformable. Where: > str(c) num [1:30, 1] 0 0 0 0 0 0 0 0 0 0 ... > str(A) num [1:21, 1:30] 1 0 0 0 0 0 0 0 0 0 ... > str(b) num [1:50, 1] 22 37 37 37 37 37 37 37 37 37 ... > str(vlb) num [1:30, 1] 0 0 0 0 0 0 0 0 0 0 ... > str(vub) num [1:30, 1] 150 150 150 150 150 150 150 150 150 150 ... > str(ctype) chr [1:21] "S" "S" "S" "S" "S" "S" "S" "S" "S" "S" "S" "U" "U" "U" "U" "U" "U" "U" "U" "U" "U" > str(vartype) chr [1:3, 1:10] "C" "I" "C" "C" "I" "C" "C" "I" "C" "C" "I" "C" "C" "I" "C" "C" "I" "C" "C" "I" "C" "C" "I" "C" "C" "I" "C" "C" "I" "C" - attr(*, "dimnames")=List of 2 ..$ : chr [1:3] "varcont" "varint" "varcont" ..$ : NULL > str(sense) num 1 My script in R is: #1) Datos #Período de estudio (días) T = 10 #Demanda diaria dda = 37*matrix(1,T,1) #Capacidad de camión (m3) K=30 #Capacidad de tanque (m3) cap_tqe=40 #Stock inicial (m3) s0=15 #Max cantidad diaria de camiones y_max=5 #Max volumen entrega diaria x_max=K*y_max #2) Modelo sin entrega los domingos #Variables: z=[x; y; s], entega x(t), cant camiones y(t), stock final s(t) c = matrix(rep(c(0,1,0),each = T)) #solo cuestan los viajes vlb = matrix(rep(0,3*T)) vub = matrix(c(x_max*rep(1,T),y_max*rep(1,T), cap_tqe*rep(1,T))) # #Restricciones grupo1: balanceen cada t, s(t)=s(t-1)+x(t)-dda(t) A1=matrix(0,nrow=T,ncol=3*T) A1[,1:T]=diag(1,dim(A1[,1:T])) library(pracma) A1[,(2*T+1):(3*T)]=-diag(1,T,T)+Diag(rep(1,T-1),-1) b1 = dda b1[1] = b1[1]-s0 #Restricciones grupo2: balanceen cada t, s(t)=s(t-1)+x(t)-dda(t) n7=floor(T/7) A2=matrix(0,ncol=3*T,nrow=n7) b2=matrix(0,nrow=3*T,ncol=1) ifelse(rem(col(A2),7)==0,1,0) #Restricciones grupo3: vol entregado menor y cant camiones, x(t)<K*y(t) A3=matrix(0,nrow=T,ncol=3*T) A3[,1:T]=diag(1,T) A3[,(T+1):(2*T)]=diag(-K,T) b3=matrix(0,nrow=T,ncol=1) # A = rbind(A1,A2,A3) b = rbind(b1,b2,b3) #Tipo de variables y restricciones varint=rep("I",T) varcont=rep("C",T) ctype=rep("S",T) vartype=rbind(varcont, varint, varcont) ctype=c(ctype, rep("S",n7)) ctype=c(ctype, rep("U",T)) # sense=1; Thanks in advance! See you! Sebastián. |
[Prev in Thread] | Current Thread | [Next in Thread] |