2017-07-20 7 views
1

で非自明な係数を有するlpSolveAPI:P1、P2P3最適化することには、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が、私はこのような機能を最適化するために使用すべきパッケージではありませんが、私は本当に使用する任意の他のパッケージを発見していない可能性があります。

答えて

0

私はあなたの方程式が線形であるとは思わないので、lpSolveはあなたの目的関数の現在の定式化にあまり役に立たないでしょう。

y = P1*y+sum(x1-P1) + P2*y+sum(x2-P2) + P3*y+sum(x3-P3) 
y = y*P1 + y*P2 + y*P3 + sum(x1) + sum(x2) + sum(x3) - n*P1 - n*P2 - n*P3 

I:ここで

は、私は(私はそれぞれの1xNは、異なるサイズが本当に以下の分析に影響を与えるはずのいるごベクトル×1×2×3を仮定している)あなたの関数yを再配置するためにできる最善であります

y = y*(P1 + P2 + P3) - n*(P1 + P2 + P3) 
y = -n*(P1 + P2 + P3)/(1 - P1 - P2 - P3) 

または代わり

:彼らは一定のいくつかの並べ替えているとして、あなたの目的関数はに単純化することができるので、合計(X1)+ SUM(×2)+ SUM(X3)が本当に必要とされているとは思いません
y = n*(P1 + P2 + P3)/(P1 + P2 + P3 - 1) 

http://lpsolve.sourceforge.net/5.5/の比率のセクションを見てください。目的関数の比率を再調整する方法や、lpsolveを使用できるようにする制約があります。

関連する問題