で非自明な係数を有するlpSolveAPI:P1、P2とP3最適化することには、3つのパラメータを持つR Iは次のように見える機能を最適化するset.objfn
y= P1*y+sum(x1-P1) + P2*y+sum(x2-P2) + P3*y+sum(x3-P3)
およびy機能が最小化される。 x1、x2x3はデータのベクトルです。制約の下で
:制約があるので
P2-P1 >= 0
P3-P2 >=0
が、私はRの関数OPTIM()を使用することはできませんので、私はlpSolveAPIに見ていました。
私は行くだろうlpSolveAPIを使用して:
lps.model <- make.lp(0, 3)
add.constraint(lps.model, c(-1,1,0), ">=", 1)
add.constraint(lps.model, c(0,-1,1), ">=", 1)
しかし、私はそのように定義されなければならない "set.objfn" を定義したい場合、それは問題になる:
set.objfn(lprec, obj, indices) with
lprec: an lpSolve linear program model object.
obj: a numeric vector of length n (where n is the number of decision variables in lprec) containing the coefficients of the objective function. Alternatively, if indices is also provided, a numeric vector of the same length as indices containing only the nonzero coefficients.
indices: optional for sparse obj. A numeric vector the same length as obj of unique values from the set {1, ..., n} where n is the number of decision variables in lprec; obj[i] is entered into column indices[i] in objective function. The coefficients for the columns not in indices are set to zero. This argument should be omitted when length(obj) == n.
私はまだこのように関数yを書き換えることができます:
y = P1 (y + [ (x1/P1) - 1 ]) + P2 (y + [ (x2/P2) - 1 ]) + P3 (y + [ (x3/P3) - 1 ])
私のパラメータP1 - P3は実際には係数の一部なので、関数 "set.objfn"の "obj"部分の私のパラメータの前にこれらの係数を書き込むはずです。
obj = c((y + [ (x1/ P1) - 1 ] , ...)
それはlpSolveAPIが、私はこのような機能を最適化するために使用すべきパッケージではありませんが、私は本当に使用する任意の他のパッケージを発見していない可能性があります。