R programming Linear programming problems

+1 vote

I am looking for a R package to solve linear programming models. The default lpSolve::lp works fine, but I can't get the shadow and reduced prices. For example:

Sample model:

A = rbind(
    c(0.5, 0.2, 0.2),
    c( -1,   1,   0),
    c(  0,   1,  -1),
    c( -1,  -1,  -1),
    c( -1,   0,   0),
    c(  0,  -1,   0),
    c(  0,   0,  -1)
)
b = c(5, 0, 0, -13, 0, 0, 0)
c_ = c(8.4, 6, 9.2)
(signs = c('=', rep('<=', 6)))

res = lpSolve::lp('min', c_, A, signs, b,  all.int = TRUE)

# Objective function
res
# Variables
res$solution

# Shadow prices?
# Reduced prices?
Feb 4, 2019 in Data Analytics by Sophie may
• 10,620 points
907 views

1 answer to this question.

0 votes

The documentation for the lp package provides all functions. Here's a part of the documentation:

# Get sensitivities
lp ("max", f.obj, f.con, f.dir, f.rhs, compute.sens=TRUE)$sens.coef.from
## Not run: [1] -1e+30 2e+00 -1e+30
lp ("max", f.obj, f.con, f.dir, f.rhs, compute.sens=TRUE)$sens.coef.to
## Not run: [1] 4.50e+00 1.00e+30 1.35e+01

# Right now the dual values for the constraints and the variables are
# combined, constraints coming first. So in this example...

lp ("max", f.obj, f.con, f.dir, f.rhs, compute.sens=TRUE)$duals
## Not run: [1] 4.5 0.0 -3.5 0.0 -10.5

# ...the duals of the constraints are 4.5 and 0, and of the variables,
# -3.5, 0.0, -10.5. Here are the lower and upper limits on these:

lp ("max", f.obj, f.con, f.dir, f.rhs, compute.sens=TRUE)$duals.from
## Not run: [1] 0e+00 -1e+30 -1e+30 -1e+30 -6e+00
lp ("max", f.obj, f.con, f.dir, f.rhs, compute.sens=TRUE)$duals.to
## Not run: [1] 1.5e+01 1.0e+30 3.0e+00 1.0e+30 3.0e+00
answered Feb 4, 2019 by Tyrion anex
• 8,700 points

Related Questions In Data Analytics

0 votes
1 answer
0 votes
1 answer

Steps to evaluate Linear Regression in R

 These are sequential steps which need to ...READ MORE

answered Jul 25, 2018 in Data Analytics by CodingByHeart77
• 3,750 points
1,231 views
0 votes
2 answers

What are the rules to define a variable name in R programming language?

The same rules almost follow for all ...READ MORE

answered Aug 26, 2019 in Data Analytics by anonymous
• 33,030 points
15,179 views
0 votes
1 answer

How can I create log linear models in R language?

By using the loglm () function  READ MORE

answered Oct 10, 2018 in Data Analytics by zombie
• 3,790 points
1,240 views
+5 votes
2 answers
0 votes
1 answer

R programming: Linear Equation

Use expand.grid to get all possible combinations ...READ MORE

answered Apr 30, 2019 in Data Analytics by Sophie may
• 10,620 points
1,277 views
+10 votes
3 answers

Which is a better initiative to learn data science: Python or R?

Well it truly depends on your requirement, If ...READ MORE

answered Aug 9, 2018 in Data Analytics by Abhi
• 3,720 points
1,669 views
+1 vote
2 answers
+1 vote
1 answer

R programming error

Alright, you can either use gsub to match the ...READ MORE

answered Dec 18, 2018 in Data Analytics by Tyrion anex
• 8,700 points
693 views
0 votes
1 answer

Check if a matrix is diagonalizable in R Programming Language

On a given matrix, a, the first way ...READ MORE

answered Dec 24, 2018 in Data Analytics by Tyrion anex
• 8,700 points
1,844 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP