R/funcionauxiliar.R

Defines functions funcionauxiliar

Documented in funcionauxiliar

funcionauxiliar <-
function(permute,costes){
n<-max(permute)
if (is.vector(permute)==T){
phi<-c()
for (i in 1:n){
cj<-0;aux<-0
pred<-sort(permute[1:which(permute==i)-1],decreasing=F)
if (length(pred)==0) pred<-0
aux<-sort(union(pred,i),decreasing=F)
suma=0;suma1=0
for (k in 1:length(aux)){suma<-suma+aux[k]*10^(length(aux)-k)}
for (k in 1:length(pred)){suma1<-suma1+pred[k]*10^(length(pred)-k)}
cj<-cj+costes[which(costes[,n+1]==suma),n+2]-costes[which(costes[,n+1]==suma1),n+2]
phi[i]<-cj/2
}
}
if(is.vector(permute)==F){
phi<-c()
for (i in 1:n){
cj<-0
for (j in 1:nrow(permute)){
aux<-0
pred<-sort(permute[j,1:which(permute[j,]==i)-1],decreasing=F)
if (length(pred)==0) pred<-0
aux<-sort(union(pred,i),decreasing=F)
suma=0;suma1=0
for (k in 1:length(aux)){suma<-suma+aux[k]*10^(length(aux)-k)}
for (k in 1:length(pred)){suma1<-suma1+pred[k]*10^(length(pred)-k)}
cj<-cj+costes[which(costes[,n+1]==suma),n+2]-costes[which(costes[,n+1]==suma1),n+2]
}
phi[i]<-cj/(2*nrow(permute))
}
}
return(phi)}

Try the InventorymodelPackage package in your browser

Any scripts or data that you put into this service are public.

InventorymodelPackage documentation built on May 29, 2017, 9:39 p.m.