Adaptado do Livro Planejamento de Transportes: Conceitos e Modelos Campos (2013).
library(DT)
library('stringr')
IntervaloDeConvergencia =0.01
multiplicador = 1000
ods = c("A", "B", "C", "D", "E")
VeicHab = matrix(c(2.7,4.1,5.7,6.5,3.9,5.8,7.3,9.4,3.8,6.7,8.3,11.1,4.2,7.1,9.6,12.7),4,4)
datatable(as.data.frame(VeicHab), class = 'cell-border stripe', colnames = c("0", "1", "2", "3ou+"), rownames = c("1", "2", "3", "4ou+"))
rownames(VeicHab) <- c("1", "2", "3", "4ou+")
colnames(VeicHab) <- c("0", "1", "2", "3ou+")
dimnames(VeicHab) <- list("Habitantes por Residência"=c("1","2", "3", "4 ou +"), "Veiculos por Residência"=c("0","1","2","3 ou +"))
VeicHab
## Veiculos por Residência
## Habitantes por Residência 0 1 2 3 ou +
## 1 2.7 3.9 3.8 4.2
## 2 4.1 5.8 6.7 7.1
## 3 5.7 7.3 8.3 9.6
## 4 ou + 6.5 9.4 11.1 12.7
datatable(as.data.frame(VeicHab))
ViagemTipoResidencia = matrix(c("<1000,00", "1000,00 a 2000,00", "2000,00 a 5000,00", ">5000,00", "Todas Residências",5.5,7.5,9.4,10.5,7.6,0.125,0.058,0.046,0.037,0.066),5,3)
ViagemTipoResidencia = as.data.frame(ViagemTipoResidencia)
names(ViagemTipoResidencia) = c("Renda por Residência", "Total de Viagens", "Proporção de Transp. Pub.")
datatable(as.data.frame(ViagemTipoResidencia))
\[P_i = 120+0.155Pi+0.142Hi \\ A_i = 85+0.065Pi+0+.80Ei\]
EstimativaFutura = matrix(c(1, 2, 3, 4, 5,400,2760,4050,1570,855,280,940,1405,865,380,2200,510,650,332,228),5,4)
EstimativaFutura = as.data.frame(EstimativaFutura)
names(EstimativaFutura) = c("Zona", "População (PI)", "Habitacão (Hi)", "Emprego Ei")
datatable(as.data.frame(EstimativaFutura))
GerViaFut = matrix(c(1,2,3,4,5, 0,0,0,0,0,0,0,0,0,0),5,3)
GerViaFut = as.data.frame(GerViaFut)
GerViaFut$V2 = round(120 + EstimativaFutura$`População (PI)`*0.155 + EstimativaFutura$`Habitacão (Hi)`*0.142, 0)
GerViaFut$V3 = round(85 + EstimativaFutura$`População (PI)`*0.065 + EstimativaFutura$`Emprego Ei`*0.380, 0)
names(GerViaFut) = c("Zonas", "Produção Futura", "Atração Futura")
computo = c("Total", sum(GerViaFut$`Produção Futura`), sum(GerViaFut$`Atração Futura`))
GerViaFut = rbind(GerViaFut, computo)
GerViaFut[, 2] = as.numeric(GerViaFut[, 2])
GerViaFut[, 3] = as.numeric(GerViaFut[, 3])
datatable(as.data.frame(GerViaFut))
Como o número de viagens geradas e atraidas difere, é calculado o fator de equilíbrio a ser aplicado sobre as viagens atraídas e assim equilibrar o número de viagens geradas e atraídas.
fim = dim(GerViaFut)[1]
FatEquilibrio = GerViaFut$`Produção Futura`[fim]/GerViaFut$`Atração Futura`[fim]
FatEquilibrio
## [1] 1.040157
GerViaFut$`Atração Futura`[1:(fim-1)] = round(GerViaFut$`Atração Futura`[1:(fim-1)]*FatEquilibrio, 0)
GerViaFut$`Atração Futura`[fim] = sum(GerViaFut$`Atração Futura`[1:(fim-1)])
datatable(as.data.frame(GerViaFut))
#MatrizOD = matrix(c(0,12,10,16,12,0,15,7,10,15,0,18,16,7,18,0),4,4)
MatrizOD = matrix(c(0,12,10,16,21,12,0,15,7,41,10,15,0,18,11,16,7,18,0,31,21,41,11,31,0),5,5)
MatrizOD = MatrizOD*multiplicador
futuro = c(80,46,108,45)*multiplicador
futuro = c(80,96,108,95,120)*multiplicador
cbind(ods,MatrizOD, rowSums(MatrizOD), futuro)
## ods futuro
## [1,] "A" "0" "12000" "10000" "16000" "21000" "59000" "80000"
## [2,] "B" "12000" "0" "15000" "7000" "41000" "75000" "96000"
## [3,] "C" "10000" "15000" "0" "18000" "11000" "54000" "108000"
## [4,] "D" "16000" "7000" "18000" "0" "31000" "72000" "95000"
## [5,] "E" "21000" "41000" "11000" "31000" "0" "104000" "120000"
datatable(as.data.frame(cbind(ods,MatrizOD, rowSums(MatrizOD), futuro)), colnames = c("Zona", ods, "ATUAL", "FUTURO"), rownames = 1:length(MatrizOD[1,]))
FatCrescMedio = futuro/rowSums(MatrizOD)
FatCrescMedio
## [1] 1.355932 1.280000 2.000000 1.319444 1.153846
dimmatriz = dim(MatrizOD)[2]
for (r in 1:dimmatriz) {
for (c in 1:dimmatriz) {
#print(paste(r, c, MatrizOD[r, c], sep = " "))
MatrizOD[r, c] = round((MatrizOD[r, c]*(FatCrescMedio[r]+FatCrescMedio[c]))/2,0)
}
}
datatable(as.data.frame(MatrizOD))
rowSums(MatrizOD)
## [1] 80352 99408 88601 98712 131929
all((1-abs(futuro / rowSums(MatrizOD)))<IntervaloDeConvergencia)
## [1] FALSE
dimmatriz = dim(MatrizOD)[2]
intervalo = FALSE
controle = 1
while (intervalo!=TRUE) {
FatCrescMedio = futuro/rowSums(MatrizOD)
for (r in 1:dimmatriz) {
for (c in 1:dimmatriz) {
#print(paste(r, c, MatrizOD[r, c], sep = " "))
MatrizOD[r, c] = round((MatrizOD[r, c]*(FatCrescMedio[r]+FatCrescMedio[c]))/2,0)
}
}
(1-abs(futuro / rowSums(MatrizOD)))<IntervaloDeConvergencia
intervalo = all((1-abs(futuro / rowSums(MatrizOD)))<IntervaloDeConvergencia)
print(paste0("Iteracão:", controle ))
print(paste("Atende Criério:", intervalo, "Fator de Crescimento:", str_c(FatCrescMedio,collapse=','), sep = " "))
print(MatrizOD)
controle = controle+1
}
## [1] "Iteracão:1"
## [1] "Atende Criério: FALSE Fator de Crescimento: 0.995619275189168,0.965717044905843,1.21894786740556,0.962395656049923,0.909580152961062"
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 15510 18580 20954 25104
## [2,] 15510 0 26871 8771 46783
## [3,] 18580 26871 0 32584 18461
## [4,] 20954 8771 32584 0 35882
## [5,] 25104 46783 18461 35882 0
## [1] "Iteracão:2"
## [1] "Atende Criério: FALSE Fator de Crescimento: 0.998153416180067,0.980241997243069,1.11921737688609,0.9675021132283,0.950645646835142"
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 15342 19670 20594 24461
## [2,] 15342 0 28207 8542 45166
## [3,] 19670 28207 0 33997 19106
## [4,] 20594 8542 33997 0 34413
## [5,] 24461 45166 19106 34413 0
## [1] "Iteracão:3"
## [1] "Atende Criério: FALSE Fator de Crescimento: 0.999163200819314,0.987075480428144,1.06951871657754,0.973899493572263,0.974453088204245"
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 15236 20345 20317 24138
## [2,] 15236 0 29005 8375 44297
## [3,] 20345 29005 0 34735 19526
## [4,] 20317 8375 34735 0 33524
## [5,] 24138 44297 19526 33524 0
## [1] "Iteracão:4"
## [1] "Atende Criério: FALSE Fator de Crescimento: 0.999550202408916,0.990579179263876,1.04236036714248,0.979876432424627,0.987776268675145"
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 15161 20771 20108 23985
## [2,] 15161 0 29483 8251 43818
## [3,] 20771 29483 0 35121 19820
## [4,] 20108 8251 35121 0 32982
## [5,] 23985 43818 19820 32982 0
## [1] "Iteracão:5"
## [1] "Atende Criério: FALSE Fator de Crescimento: 0.999687597625742,0.992627671564319,1.02666476543562,0.984843772677324,0.994983624227851"
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 15103 21045 19952 23921
## [2,] 15103 0 29767 8158 43547
## [3,] 21045 29767 0 35323 20035
## [4,] 19952 8158 35323 0 32649
## [5,] 23921 43547 20035 32649 0
## [1] "Iteracão:6"
## [1] "Atende Criério: TRUE Fator de Crescimento: 0.999737568888167,0.994046078177582,1.01723650748799,0.988738785620616,0.998734935748052"
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 15056 21224 19837 23903
## [2,] 15056 0 29935 8088 43390
## [3,] 21224 29935 0 35429 20195
## [4,] 19837 8088 35429 0 32445
## [5,] 23903 43390 20195 32445 0
datatable(as.data.frame(cbind(MatrizOD, rowSums(MatrizOD), futuro)), colnames = c(ods, "Prod. Futura", "Produção Total"), rownames = ods)
Primeiramente é calculado o fator de crescimento intrazona:
\[F_i = \frac{P_i^*}{P_i}\] Calcula-se as viagens entre zonas:
\[t_{ij} = \frac{P_i^**t_{ij}*f_i}{\sum_j t_{ij}*f_i}\]
Geração: \[t_{ij} = \frac{1}{2}(t`_{ij}+t`_{ji}) \to (t'valor\ calculado\ na\ iteracão) \]
#MatrizOD = matrix(c(0,12,10,16,12,0,15,7,10,15,0,18,16,7,18,0),4,4)
MatrizOD = matrix(c(0,12,10,16,21,12,0,15,7,41,10,15,0,18,11,16,7,18,0,31,21,41,11,31,0),5,5)
MatrizOD = MatrizOD*multiplicador
MatrizOD
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 12000 10000 16000 21000
## [2,] 12000 0 15000 7000 41000
## [3,] 10000 15000 0 18000 11000
## [4,] 16000 7000 18000 0 31000
## [5,] 21000 41000 11000 31000 0
cbind(c("A", "B", "C", "D", "E"),MatrizOD, rowSums(MatrizOD), futuro)
## futuro
## [1,] "A" "0" "12000" "10000" "16000" "21000" "59000" "80000"
## [2,] "B" "12000" "0" "15000" "7000" "41000" "75000" "96000"
## [3,] "C" "10000" "15000" "0" "18000" "11000" "54000" "108000"
## [4,] "D" "16000" "7000" "18000" "0" "31000" "72000" "95000"
## [5,] "E" "21000" "41000" "11000" "31000" "0" "104000" "120000"
FatCrescMedio = futuro/rowSums(MatrizOD)
FatCrescMedio
## [1] 1.355932 1.280000 2.000000 1.319444 1.153846
ods = c("A", "B", "C", "D", "E")
dimmatriz = dim(MatrizOD)[2]
intervalo = FALSE
controle = 1
MatrizODDois = matrix(0, dim(MatrizOD), dim(MatrizOD))
while (intervalo!=TRUE) {
FatCrescMedio = futuro/colSums(MatrizOD)
for (i in 1:dimmatriz) {
for (j in 1:dimmatriz) {
MatrizODDois[i, j] = (futuro[i]*MatrizOD[i, j]*FatCrescMedio[j])/sum(MatrizOD[i,]*FatCrescMedio)
}
}
MatrizOD = (MatrizODDois+t(MatrizODDois))/2
intervaloB = abs(1-(futuro / rowSums(MatrizOD)))
intervalo = all(abs(1-(futuro / rowSums(MatrizOD)))<IntervaloDeConvergencia)
print(paste0("Iteracão:", controle ))
print(MatrizOD)
controle = controle+1
}
## [1] "Iteracão:1"
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0.00 15209.539 20493.75 20524.939 23886.19
## [2,] 15209.54 0.000 28988.05 8467.222 43974.32
## [3,] 20493.75 28988.046 0.00 35228.083 19079.92
## [4,] 20524.94 8467.222 35228.08 0.000 33647.98
## [5,] 23886.19 43974.324 19079.92 33647.984 0.00
## [1] "Iteracão:2"
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0.00 15032.589 21432.89 19774.929 23786.91
## [2,] 15032.59 0.000 30054.94 8087.099 43413.17
## [3,] 21432.89 30054.935 0.00 35604.766 19931.05
## [4,] 19774.93 8087.099 35604.77 0.000 32381.66
## [5,] 23786.91 43413.172 19931.05 32381.663 0.00
O resultado converte? TRUE.
A relação com o Fator de Crescimento foi de 0.999658743476936,0.993914390644558,1.00912283220793,0.99114792786637,1.00407658584399.
Resultando em diferenças da ordem de: 3.412565210^{-4}, 0.0060856, 0.0091228, 0.0088521, 0.0040766, estando contidas dentro do intervalo de erro admitido de 0.01%.
## A B C D E
## A 0.00 15032.589 21432.89 19774.929 23786.91
## B 15032.59 0.000 30054.94 8087.099 43413.17
## C 21432.89 30054.935 0.00 35604.766 19931.05
## D 19774.93 8087.099 35604.77 0.000 32381.66
## E 23786.91 43413.172 19931.05 32381.663 0.00
datatable(as.data.frame(cbind(ods,MatrizOD, rowSums(MatrizOD), futuro)), colnames = c("Zona", ods, "ATUAL", "FUTURO"), rownames = 1:length(MatrizOD[1,]))
Em desenvolvimento
Em desenvolvimento
Em desenvolvimento
Em desenvolvimento
Em desenvolvimento
Campos, Vânia Barcellos Gouvêa. 2013. Planejamento de transportes: conceitos e modelos. Interciência,