4

R での LP モデリングは初めてです。lpSolveAPI を使用しています。2 つの決定変数を使用して小さな例を試してモデルを印刷すると、完全なモデルが印刷されます。

library(lpSolveAPI)
lprec <- make.lp(nrow=0,ncol=2,verbose="full")

set.objfn(lprec,c(6,5))
lp.control(lprec,sense="max")

add.constraint(lprec,c(1,1),"<=",5)
add.constraint(lprec,c(3,2),"<=",12)

set.bounds(lprec,lower=c(0,0),columns = c(1,2))


RowNames <- c("A","B")
ColNames <- c("R1","R2")
dimnames(lprec) <- list(RowNames, ColNames)

print(lprec)

#   Model name: 

#            R1    R2        
#Maximize     6     5        
#A            1     1  <=   5
#B            3     2  <=  12
#Kind       Std   Std        
#Type      Real  Real        
#Upper      Inf   Inf        
#Lower        0     0 

しかし、25 個の決定変数を使用してモデルを試し、いくつかの制約を追加した後、モデルを印刷しようとすると、次のように表示されます。

Model name: 
a linear program with 25 decision variables and 5 constraints

より大きなモデルを表示する方法を提案してください。

4

2 に答える 2

0

これは単純な LP で再現できます。

library(lpSolveAPI)
lprec <- make.lp(nrow=0,ncol=25,verbose="full")
add.constraint(lprec, rep(1, 25), "<=", 1)
add.constraint(lprec, c(1, rep(0, 24)), "<=", 5)
print(lprec)
# Model name: 
#   a linear program with 25 decision variables and 2 constraints

それから?print.lpExtPtr、印刷機能へのすべての追加パラメータは無視されるようです:

使用法

## クラス 'lpExtPtr' print(x, ...) の S3 メソッド

引数

x lpSolve 線形計画法モデル オブジェクト。

... 追加の引数は無視されます。

結果として、最善の策はおそらく個々の情報を抽出して出力することです。例えば:

# Rows and columns
nr <- dim(lprec)[1]
nc <- dim(lprec)[2]

# Constraint matrix
sapply(1:(dim(lprec)[2]), function(x) {
  ret <- rep(0, nr)
  c <- get.column(lprec, x)
  ret[c$nzrow] <- c$column
  ret
})
#      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16] [,17] [,18] [,19]
# [1,]    1    1    1    1    1    1    1    1    1     1     1     1     1     1     1     1     1     1     1
# [2,]    1    0    0    0    0    0    0    0    0     0     0     0     0     0     0     0     0     0     0
#      [,20] [,21] [,22] [,23] [,24] [,25]
# [1,]     1     1     1     1     1     1
# [2,]     0     0     0     0     0     0

# Constraint directions
get.constr.type(lprec)
# [1] "<=" "<="

# Right-hand sides
get.constr.value(lprec)
# [1] 1 5
于 2015-08-05T06:17:57.243 に答える