R has many powerful libraries to handle operations research. This exercise tries to demonstrate a few basic functionality of R while dealing with linear programming.

Linear programming is a technique for the optimization of a linear objective function, subject to linear equality and linear inequality constraints.

The lpsolve package in R provides a set of functions to create models from scratch or use some prebuilt ones like the assignment and transportation problems.

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 packages lpSolve and igraph. Then, take a look at lp.assign to see how it works.

**Exercise 2**

Create a matrix representing the cost related to assign 4 tasks(rows) to 4 workers(cols) by generating integer random numbers between 50 and 100, with replacement. In order to make this exercise reproducible, define seed as 1234.

**Exercise 3**

Who should be assign to each task to obtain all the work done at minimal cost?

**Exercise 4**

Based on the resource allocation plan, how much we will spend to get all this work done?

**Exercise 5**

Take a look at lp.transport to see how it works. Set up the cost matrix by generating integer random numbers between 0 and 1000, without replacement. Consider that will be 8 factories(rows) serving 5 warehouses(cols).

**Exercise 6**

Set up the offer constraint by generating integer random numbers between 50 and 300, without replacement.

**Exercise 7**

Set up the demand constraint by generating integer random numbers between 100 and 500, without replacement.

**Exercise 8**

Find out which factory will not use all its capacity at the optimal cost solution.

**Exercise 9**

What is the cost associated to the optimal distribution?

**Exercise 10**

Create adjacency matrix using your solution in order to create a graph using igraph package.

## Leave a Reply