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
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.
Load libraries lpsove and igraph and learn how to use lp function by replicating the example in
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.
Run the this transportation problem one more time using
lp.transport. Check the objective function and decision variables values.
Rearrange the data in a format required for the objective function to use at the lp function.
Construct the binary matrix to model the DEMAND constraints.Observe that the variables should be at the same order defined at the objective function.
Forget about the OFFER constraints for a while. Run the lp function only with de DEMAND constraint and see what happens.
Construct the binary matrix to model the OFFER constraints.Observe that the variables should be at the same order defined at the objective function.
Bind both offer and demand constraints to construct a matrix to
f.con and vectors to
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
Rename rows to represent factories and columns to be depots. Create an graph using
graph_from_incidence_matrix based on decision variables optimum values.
- Become a Top R Programmer Fast with our Individual Coaching Program
- Explore all our (>4000) R exercises
- Find an R course using our R Course Finder directory
- Subscribe to receive weekly updates and bonus sets by email
- Share with your friends and colleagues using the buttons below