Data Science for Operational Excellence Exercises (Part-2)

April 14, 2017

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

Network problems are everywhere. We can easily find instances in logistics, telecom, project mangement, among others. In order to attack these problems using linear programming we need to go beyond assign and transportation problems that we saw in part I. Our goal here is to expand the problems we can solve using lpsove and igraph R packages. For that, we will formulate the transportation problem using a more generic function lp.
Answers to the exercises are available here. If you obtained a different (correct) answer than those
listed on the solutions page, please feel free to post your answer as a comment on that page.
Please install and load the package lpsolve and igraph before starting the exercise.

Answers to the exercises are available here.

Exercise 1
Load libraries lpsove and igraph and learn how to use lp function by replicating the example in ?lp.

Exercise 2
We want to rewrite the transport problem stated in part I, but this time using lp function. First, load the data used in part I exercise.

Exercise 3
Run the this transportation problem one more time using lp.transport. Check the objective function and decision variables values.

Exercise 4
Rearrange the data in a format required for the objective function to use at the lp function.

Exercise 5
Construct the binary matrix to model the DEMAND constraints.Observe that the variables should be at the same order defined at the objective function.

Learn more about Network Analysis in the online course Statistics with R – Advanced Level. In this course you will learn how to:

  • Run a cluster analysis
  • Perform multidimensional scaling
  • And much more

Exercise 6
Forget about the OFFER constraints for a while. Run the lp function only with de DEMAND constraint and see what happens.

Exercise 7
Construct the binary matrix to model the OFFER constraints.Observe that the variables should be at the same order defined at the objective function.

Exercise 8
Bind both offer and demand constraints to construct a matrix to f.con and vectors to f.dir, and f.rhs.

Exercise 9
Now, solve the problem using lp function. Find the solution for each variable and the objective function value.Check if it matches the values from lp.transport.

Exercise 10
Rename rows to represent factories and columns to be depots. Create an graph using graph_from_incidence_matrix based on decision variables optimum values.

To leave a comment for the author, please follow the link and comment on their blog: R-exercises. 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.


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)