Data Science for Operational Excellence (Part-3)

April 24, 2017
By

(This article was first published on R-exercises, and kindly contributed to R-bloggers)


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.

Exercise 1
Load libraries: ggmap, fields, lpSolve, leaflet, dplyr, magrittr. Use the following vectors to create a new one called allCitiesAux: soyaCities <- c("Sapezal","Sorriso", "Nova Mutum", "Diamantino", "Cascavel") , transhipment <- c("Alto Araguaia", "Cascavel"), ports <- c("Santos", "Paranagua").
Exercise 2
Use the function geocode to collect latitude and longitude for all cities.
Exercise 3
Create a data frame and with columns names: City, lat and lng.
Exercise 4
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.

Learn more about geo visualization in the online course R: Complete Data Visualization Solutions. In this course you will learn how to:

  • Build advanced map visualizations
  • Work with different sources for maps
  • And much more visualizations

Exercise 5
Create 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.
Exercise 6
Solve the transportation problem and change columns and row names to match the names from the cost matrix.
Exercise 7
Create a list of data frames to store all segments presented in the solution. Example, one of this segments should be Sapezal to Santos.
Exercise 8
Create a map using leaflet and add lines for each segment based on the list of data frames created previously.
Exercise 9
Create a list of data frames to store road routes extracted using the route function from ggmap.
Exercise 10
Create a new map using leaflet that, instead of showing straight lines from origin to destination, shows road routes.

To leave a comment for the author, please follow the link and comment on their blog: R-exercises.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)