Какое ограничение является обязательным при оптимальном решении - R / lpSolveAPI / lpsolve - PullRequest
0 голосов
/ 11 октября 2019

У меня есть следующая основная задача оптимизации ограничений, разработанная в R с использованием lpSolveAPI. Мне было интересно, если есть способ узнать, какое ограничение является обязательным при оптимальном решении. В SAS мы можем получить доступ к status определенного ограничения, чтобы получить информацию

require(lpSolveAPI)

lprec <- make.lp(0, 2)
lp.control(lprec, sense="min")
set.objfn(lprec, c(9.3, 8.4))
add.constraint(lprec, c(1, 1), ">=", 50)
add.constraint(lprec, c(-.21, .3 ), ">=", 0)
add.constraint(lprec, c(-.03, .01), "<=", 0)
lprec
solve(lprec)
variables <- get.variables(lprec)
total_profit <- get.objective(lprec)
variables
total_profit

Альтернативно, используя lpSolve

# using lpSolve
# install.packages("lpSolve")
require(lpSolve)

# Set the coefficients of the decision variables -> C
C <- c(9.3, 8.4)
# Create constraint martix A
A <- matrix(c(1, 1,
              -.21, .3,
              -.03, .01), nrow=3, byrow = TRUE)
B <- c(50, 0, 0)
constranints_direction <- c(">=", ">=", "<=")
# Find the optimal solution
optimum <-  lp(direction="min",
               objective.in = C,
               const.mat = A,
               const.dir = constranints_direction,
               const.rhs = B,
               all.int = F)
# Print status: 0 = success, 2 = no feasible solution
print(optimum$status)

# Display the optimum values for c and s
best_sol <- optimum$solution
names(best_sol) <- c("c", "s") 
print(best_sol)
print(paste("Total cost: ", optimum$objval, sep=""))
...