Below are the solutions to these exercises on Linear Programming.

#################### # # # Exercise 1 # # # #################### library(lpSolve) library(igraph) #################### # # # Exercise 2 # # # #################### set.seed(1234) assign.costs <- matrix(sample(50:100, 16, replace=T), ncol=4) #################### # # # Exercise 3 # # # #################### x <- lp.assign(assign.costs) x$solution

## [,1] [,2] [,3] [,4] ## [1,] 1 0 0 0 ## [2,] 0 0 1 0 ## [3,] 0 0 0 1 ## [4,] 0 1 0 0

#################### # # # Exercise 4 # # # #################### x$objval

## [1] 256

#################### # # # Exercise 5 # # # #################### set.seed(1234) transp.costs <- matrix(sample(0:1000, 40, replace=F), nrow = 8) transp.costs

## [,1] [,2] [,3] [,4] [,5] ## [1,] 113 661 281 213 295 ## [2,] 622 510 262 791 491 ## [3,] 608 687 183 512 175 ## [4,] 999 539 228 890 733 ## [5,] 858 279 310 808 194 ## [6,] 637 912 296 44 249 ## [7,] 9 288 155 442 955 ## [8,] 231 825 39 257 776

#################### # # # Exercise 6 # # # #################### row.signs <- rep ("<", 8) row.rhs <- sample(50:300, 8, replace=F) row.rhs

## [1] 188 211 127 204 131 173 215 168

#################### # # # Exercise 7 # # # #################### col.signs <- rep (">", 5) col.rhs <- sample(100:500, 5, replace=F) col.rhs

## [1] 197 406 129 223 384

#################### # # # Exercise 8 # # # #################### sol <- lp.transport (transp.costs, "min", row.signs, row.rhs, col.signs, col.rhs, compute.sens=0) sol$solution

## [,1] [,2] [,3] [,4] [,5] ## [1,] 0 0 0 11 177 ## [2,] 0 211 0 0 0 ## [3,] 0 0 0 0 127 ## [4,] 0 126 0 0 0 ## [5,] 0 51 0 0 80 ## [6,] 0 0 0 173 0 ## [7,] 197 18 0 0 0 ## [8,] 0 0 129 39 0

#################### # # # Exercise 9 # # # #################### sol

## Success: the objective function is 311679

#################### # # # Exercise 10 # # # #################### AdjMatrix <- cbind(sol$solution, matrix(rep(0,8*3), ncol=3)) AdjMatrix <- AdjMatrix / AdjMatrix graph <- graph_from_adjacency_matrix(AdjMatrix, mode = "direct", weighted = NULL) plot(graph)

Kafeel Basha says

Very good Exercise.

Can I get similar exercise on Travel Salesman Problem?.

I have some knowledge on TSP package.