[SOLVED] 代写 R (Exercise 3) Let’s see how we can use an R package to solve linear programming problems: consider the following simple LP

30 $

File Name: 代写_R_(Exercise_3)_Let’s_see_how_we_can_use_an_R_package_to_solve_linear_programming_problems:_consider_the_following_simple_LP.zip
File Size: 1243.44 KB

SKU: 8476643669 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


(Exercise 3) Let’s see how we can use an R package to solve linear programming problems: consider the following simple LP
maximize x1 + x2
subject to x1 + 2×2 ≤ 100,
3×1 + x2 ≤ 75, x1,x2 ≥0,
Start by loading the package called “lpSolve” this loads a function called lp. We need to provide the function with
• A string, to say whether the problem is a maximization or minimization; • A vector of objective function coefficients;
• A matrix of constraints coefficients, A;
• A vector of constraint right-hand side values; and
• A vector specifying whether constraints are ≥, ≤ or =. Now let’s see it in action. . .
First we create the three vectors and matrix to use as input to the function.
f . o b j <− c ( 1 , 1 )f.con <− matrix(c(1, 2, 3, 1), nrow = 2, byrow = TRUE) f.ineqs <− c(”<=”, ”<=”)f.rhs <− c(100, 75)This creates the vectors containing the data of the problem, there are then various ways of calling the simplex solver, depending on how much information you would like about the solution. Here are two such options:lp(”max”, f.obj, f.con, f.ineqs, f.rhs) lp(”max”, f.obj, f.con, f.ineqs, f.rhs)$solutionTo see some other available properties of the solution consult the help file for “lp”, via “?lp”, or “help(lp)”.Remember to add comments to your code with the # symbol, and/or to use “`r and “` to separate R code from your words.4 Exercise 3 (Anaxagoras). Consider the Tables & Chairs example in the notes. (Remember to add comments to your code!)(i) Follow the steps outlined above to find the optimal value and optimal solution for the problem, using R.(ii) Instead, augment the problem before using R and use the computer to solve a problem with four optimization variables, and two equality constraints. Verify the optimum is the same. What values do the slack variables take at the optimum? Could you have worked it out previously?(iii) Now suppose that the tables and chairs need to be transported to the daily market in a single lorry of volume 150 units. Each chair requires 1 unit of space in the lorry and each table 3 units. Formulate a new constraint and use R to re-solve the problem now. Say a few words about what you’ve discovered.(iv) Re-solve the original problem (without the lorry) with wood constraint values of b1 = 99, 98, 97, 96, . . .. How does the solution change? Does the optimal basis change? (Think carefully about the term optimal basis!)(v) Try and automate this procedure to find the largest value of b1 with an un- changed optimal basis. (Code hint: consider using an ‘until’ or ‘while’ loop, or just a ‘for’ loop with an ’if’ condition)(vi) Sketch the constraints in the (x1, x2)-plane and see if you can describe in words what is happening to the optimal solution as the value of b1 is varied.(vii) Extension*: is there similar behaviour if you consider changing the value of b2? 5

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] 代写 R (Exercise 3) Let’s see how we can use an R package to solve linear programming problems: consider the following simple LP
30 $