Optimized transportation planning is a task usually left to the firm’s logistic department. However, it is often difficult to visualize, specially if there are many points involved in the logistic network. R and its packages can help solving this issue. Our goal here is to expand logistics networking visualization. In order to do that, we will use packages as ggmap and leaflet.
Answers to the exercises are available here.
Load libraries: ggmap, fields, lpSolve, leaflet, dplyr, magrittr. Use the following vectors to create a new one called
soyaCities <- c("Sapezal","Sorriso", "Nova Mutum", "Diamantino", "Cascavel") , transhipment <- c("Alto Araguaia", "Cascavel"), ports <- c("Santos", "Paranagua").
Use the function
geocode to collect latitude and longitude for all cities.
Create a data frame and with columns names: City, lat and lng.
Create a matrix that contains all the distance between all cities. We will use this in the
lp.transportation function, so remember that rows must be offer points and columns demand points.
row.signs, row.rhs, col.signs, col.rhs. For that, remember to set a seed equals to 123 and that all soya must be exported through ports. For the “right hand side” variables use random generated number. Port demands should be between 300 and 600. Soya production should be between 50 and 300.
Solve the transportation problem and change columns and row names to match the names from the cost matrix.
Create a list of data frames to store all segments presented in the solution. Example, one of this segments should be Sapezal to Santos.
Create a map using leaflet and add lines for each segment based on the list of data frames created previously.
Create a list of data frames to store road routes extracted using the
route function from ggmap.
Create a new map using leaflet that, instead of showing straight lines from origin to destination, shows road routes.
Leave a Reply