# Data Science for Operational Excellence Exercises (Part-2)

**R-exercises**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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.

**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 about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.