こんにちは、よろしくお願いします。このパッケージlpSolveAPI
を使用して、線形計画法の問題を解決しています。線形計画法オブジェクトを作成してから制約をmat
追加すると、制約マトリックスのすべての行を反復処理し、制約を個別に追加します。ここの例は、列を設定することを除いて同じことをしているようです。各制約を個別に追加する必要がありますか? または、制約行列全体、方向ベクトル、および右側のベクトルを一度にアタッチする方法はありますか?
#Generate Linear Programming Object
lprec <- make.lp(nrow = nrow(mat) # Number of Constraints
, ncol = ncol(mat) # Number of Decision Variables
)
#Set Objective Function to Minimize
set.objfn(lprec, obj)
#Adding Constraints Separately
#Note Direction is included along with Constraint Value
for(i in 1:nrow(mat) ){
add.constraint(lprec,mat[i,], dir[i], rhs[i])
print(i)
}