-
Notifications
You must be signed in to change notification settings - Fork 0
/
scenarioASIS_Madrid.R
136 lines (111 loc) · 6.18 KB
/
scenarioASIS_Madrid.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#Rscript U:/20211027ZLC/scenarioASIS_Madrid.R U:/20211027ZLC/INPUT/config.csv U:/20211027ZLC/INPUT/services.csv U:/20211027ZLC/INPUT/facilitiesASIS.csv U:/20211027ZLC/INPUT/vehiclesASIS.csv U:/20211027ZLC
#--------------------------------------------------------------
#Description: Script for executing Madrid scenarios
#--------------------------------------------------------------
args= commandArgs(trailingOnly = TRUE)
if (length(args)==0) {
stop("Four arguments need to be supplied", call.=FALSE)
} else if (length(args)==5) {
# default output file
file_config = args[1]
file_services = args[2]
file_facilities_ASIS=args[3]
file_vehicles_ASIS =args[4]
file_dir=args[5]
}
file_ouptut_ASIS =paste(file_dir,"/OUTPUT/testOutputASIS.txt",sep="")
source(paste(file_dir,"/Shapefile_to_Zone.R",sep=""))
source(paste(file_dir,"/TwoEchelonModel_script.R",sep=""))
str_url= "https://datos.madrid.es/egob/catalogo/300229-0-trafico-madrid-central.zip"
str_file_name=paste(file_dir,"/TEMP/Madrid_Central.shp",sep="")
#-----------------------------------------------------------
#read default paremeters from config
#----------------------------------------------------------
fdconfig = read.csv(file_config,header=T,";")
configUI = as.matrix(fdconfig,nrow=2,ncol=7,byrow=TRUE)
k= configUI[1,1]
workshift = configUI[1,2]
branchHandlingTime = configUI[1,3]
UCCHandlingTime = configUI[1,4]
stopTimeFirstEchelon = configUI[1,5]
stopTimeSecondEchelon = configUI[1,6]
distanceType = configUI[1,7]
#---------------------------------------------------------------
#Read data of facilities to serve the consumers. First row of the
#document (.csv) contains the information for the
#first leg and the the seconf row for the second leg
#---------------------------------------------------------------
fdFacilities=read.csv(file_facilities_ASIS,header=F,";")
print(file_facilities_ASIS)
#FacilityUI = Information in the file (Name Address Number City ZipCode Latitude Longitude HandlingTime (minutes) StartHour EndHour)
facilityUI = as.matrix(fdFacilities,nrow=3,ncol=10,byrow=TRUE)
#Model data input : facility = (name, handling time(h), latitude, longitude)'
#facility first leg in San Fernando = origin of the route
facility1 = c(facilityUI[1,1], as.integer(facilityUI[1,8])/60, as.double(facilityUI[1,6]),as.double(facilityUI[1,7]))
#--------------------------------------------------------------------
#Read data od the vehicles to serve the consumer. First row of the
#document (.csv) contains the information for the
#first leg and the the seconf row for the second leg
#--------------------------------------------------------------------
#vehicles'
fdVehicles=read.csv(file_vehicles_ASIS,header=F,";")
#vehiclesUI = (type, capacityParcels, CapacityKg, CapacityM3, FixedCosts, AverageSpeed(km/h), MaxKilometerDay)
vehiclesUI = as.matrix(fdVehicles,nrow=3,ncol=7,byrow=TRUE)
#vehicle = (name, capacity (Porto in boxes), speed (km/h), stop time (h))
vehicle1 = c(vehiclesUI[1,1], vehiclesUI[1,2], vehiclesUI[1,6], stopTimeSecondEchelon)
#---------------------------------------------------------------------
#read the data of the services and geographic data of the delivery area
#to create the zones.
#----------------------------------------------------------------------
#read the file with the orders for echelon 1 (aggregated orders) and echelon 2 (average size of the orders)'
fd=read.csv(file_services,header=F,";")
zoneAvgOrderSize=mean(fd$V20)
zoneNOrders=nrow(fd)
zoneAggregatedOrdersSize = sum(fd$V20)
#read geographic data od the delivery area'
print(getwd())
Read_url_GeographicData(str_url,file_dir)
zoneArea = Read_area(str_file_name)
zoneArea = zoneArea/1000000
zoneCentroid = Read_centroid(str_file_name)
zoneCentroidGeometry = st_geometry(zoneCentroid)
zoneCoordinatesCentroid = st_coordinates(zoneCentroidGeometry)
zoneCentroidX = zoneCoordinatesCentroid[2]
zoneCentroidY = zoneCoordinatesCentroid[1]
#----------------------------------------------------------------------------
#Zone 1
# ZOne 1: latitude and longitude of the centroid
# zone 1: area of delivery zone (WARNING in km2)
# zone 1: number of delivery nodes = number of services
# zone 1: avgSize is the average size
#---------------------------------------------------------------------------
#create the zone for echelon 1: 1 delivery point (UCC) from the branch with agregated orders
zone1 = c(1,zoneAvgOrderSize,zoneArea, zoneCentroidX, zoneCentroidY,zoneNOrders)
#------------------------------------------------------------------------------'
#workshift = 8 for the tow legs. We assume independent resources and times
#K = parameter required for the model
config =c(workshift,k)
#------------------------------------------------------------------------------'
solution = calculateSolutionLeg(zone1, vehicle1, facility1, config)
dfSolution = data.frame(Echelon= c(1),
zoneName = c(zone1[1]),
zoneAvgSize = c (zone1[2]),
zoneArea = c (zone1[3]),
#zoneLatitude = c (zoneFirstLeg[4], zoneSecondLeg[4]),
#zoneLongitude = c (zoneFirstLeg[5], zoneSecondLeg[5]),
zoneTotalDeliveries = c (zone1[6]),
vehicleName = c(vehicle1[1]),
vehicleCapacity = c(vehicle1[2]),
vehicleSpeed = c(vehicle1[3]),
vehicleStopTime = c(vehicle1[4]),
facilityName = c(facility1[1]),
facilityHandlingTime = c(facility1[2]),
#facilityLatitude = c(facilityFirstLeg[3],facilitySecontLeg[3]),
#facilityLongitude = c(facilityFirstLeg[4],facilitySecontLeg[4]),
totalDistance = c(solution[1]),
totalTime = c(solution[2]),
m = c(solution[3])
)
#write.csv2(dfSolution,"./Madrid_Centro/testOutputASIS.csv",sep =";", row.names = FALSE, dec=".")
write.table(dfSolution,file_ouptut_ASIS,sep =";", dec=".", row.names = FALSE)
print("Terminado AS IS")