R: Solves a linear inverse model using linear programming.
Linp
R Documentation
Solves a linear inverse model using linear programming.
Description
Solves a linear inverse model using linear programming
Input presented either as:
matrices E, F, A, B, G, H (Linp.double) or
as a list (Linp.lim) or
as a lim input file (Linp.limfile)
Usage
Linp(...)
## S3 method for class 'lim'
Linp(lim, cost = NULL, ispos = lim$ispos, ...)
## S3 method for class 'limfile'
Linp(file, verbose = TRUE,...)
## S3 method for class 'character'
Linp(...)
## S3 method for class 'double'
Linp(...)
Arguments
lim
a list that contains the linear inverse model
specification, as generated by function setup.limfile.
file
name of the inverse input file.
verbose
if TRUE: when reading the file,
prints warnings and messages to the screen.
cost
if not NULL, a vector with the coefficients of the
cost function (to be minimised).
ispos
if TRUE: all x-values have to be positive.
...
other arguments passed to function linp
from packagelimSolve.
Details
Solves the following inverse problem:
min(∑ {Cost_i*x_i})
or
max(∑ {Profit_i*x_i})
subject to
x_i>=0
Ax=B
Gx>=H
and where Cost_i or Profit_i are weighting coefficients
Value
a list containing:
X
vector containing the solution of the linear programming problem.
unconstrained.solution
vector containing the unconstrained
solution of the linear programming problem.
residualNorm
scalar, the sum of residuals of equalities
and violated inequalities.
solutionNorm
scalar, the value of the quadratic function
at the solution.
IsError
logical, TRUE if an error occurred.
Error
linp error text.
type
linp.
Author(s)
Karline Soetaert <karline.soetaert@nioz.nl>
References
Michel Berkelaar and others (2005). lpSolve: Interface to Lpsolve v. 5
to solve linear/integer programs. R package version 1.1.9.
See Also
linp, the more general function from package lpSolve
Ldei, to solve the linear inverse problem by least
distance programming
Lsei, to solve the linear inverse problem by lsei
(least squares with equality and inequality constraints)
function linp from packagelimSolve
Examples
# the Blending example
Linp(LIMBlending)
# the E coli example: two functions to maximimise
Linp(LIMEcoli)
# E coli example, but only first function optimised..
Linp(LIMEcoli, cost = -LIMEcoli$Profit[1,])
# a foodweb example: need to specify the cost function
# here just sum of absolute values of flows...
Linp(LIMRigaAutumn, cost = (rep(1, LIMRigaAutumn$NUnknowns)))
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(LIM)
Loading required package: limSolve
Loading required package: diagram
Loading required package: shape
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/LIM/Linp.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Linp
> ### Title: Solves a linear inverse model using linear programming.
> ### Aliases: Linp Linp.lim Linp.limfile Linp.character Linp.double
> ### Keywords: algebra array optimize
>
> ### ** Examples
>
> # the Blending example
> Linp(LIMBlending)
$residualNorm
[1] 0
$solutionNorm
[1] 31.81818
$X
PINGREDIENT1 PINGREDIENT2 PFILLER
[1,] 0.5909091 0.1363636 0.2727273
>
> # the E coli example: two functions to maximimise
> Linp(LIMEcoli)
$residualNorm
[1] 1.418687e-11 1.708703e-14
$solutionNorm
[1] 33.11752 0.00000
$X
GLK1 PGI1 PFKA FBP FBA TPIA GAPA
[1,] 0.00000 807.532745 781.590686 0 781.590686 781.590686 1541.43420
[2,] 5.66169 5.639786 5.553995 0 5.553995 5.553995 11.03607
PGK GPMA ENO PPSA PYKA ACEE ZWF PGL GND
[1,] 1541.43420 1492.08909 1492.08909 0 466.65796 1149.2952836 0 0 0
[2,] 11.03607 10.87288 10.87288 0 10.50489 0.1949477 0 0 0
RPIA RPE TKTA1 TKTA2 TALA GLTA
[1,] 23.62383277 -23.62383277 -5.85076232 -17.77307045 -5.85076232 35.4357492
[2,] 0.07812511 -0.07812511 -0.01934874 -0.05877637 -0.01934874 0.1171877
ACNA ICDA SUCA SUCC1 SDHA1 FRDA FUMA MDH DLD1
[1,] 35.4357492 35.4357492 0 0 0 100 -100 -100 0.000000
[2,] 0.1171877 0.1171877 0 0 0 0 0 0 9.595867
ADHE2 PFLA PTA ACKA ACS PCKA PPC MAEB SFCA ACEA ACEB
[1,] 1.000000e+03 10.0000000 0 0 0 0 194.3849394 0 0 0 0
[2,] 7.228398e-02 0.4041332 0 0 0 0 0.3121354 0 0 0 0
PPA GLPK GPSA1 RBSK NUOA FDOH GLPD CYOA SDHA2 PNT1A PNT2A
[1,] 0 0 0 0 140 0 0 40 -100 0 567.965512
[2,] 0 0 0 0 0 0 0 0 0 0 1.878288
ATPA GLCUP GLCPTS GLUP RIBUP ACUP LACUP FORUP
[1,] -145.46632929 0.00000 814.1562 0 0 0 0.000000 -10.0000000
[2,] -0.06247093 5.66169 0.0000 0 0 0 -9.595867 -0.4041332
ETHUP SUCCUP PYRUP PIUP O2TX CO2TX ATPM ADK
[1,] -1.000000e+03 -100 -27.79634 120.5477822 20 -990.3461 5.87 0
[2,] -7.228398e-02 0 0.00000 0.3986571 0 0.0000 5.87 0
Growth
[1,] 33.1175226
[2,] 0.1095212
>
> # E coli example, but only first function optimised..
> Linp(LIMEcoli, cost = -LIMEcoli$Profit[1,])
$residualNorm
[1] 1.418687e-11
$solutionNorm
[1] -33.11752
$X
GLK1 PGI1 PFKA FBP FBA TPIA GAPA PGK GPMA
[1,] 0 807.5327 781.5907 0 781.5907 781.5907 1541.434 1541.434 1492.089
ENO PPSA PYKA ACEE ZWF PGL GND RPIA RPE TKTA1
[1,] 1492.089 0 466.658 1149.295 0 0 0 23.62383 -23.62383 -5.850762
TKTA2 TALA GLTA ACNA ICDA SUCA SUCC1 SDHA1 FRDA FUMA
[1,] -17.77307 -5.850762 35.43575 35.43575 35.43575 0 0 0 100 -100
MDH DLD1 ADHE2 PFLA PTA ACKA ACS PCKA PPC MAEB SFCA ACEA ACEB PPA
[1,] -100 0 1000 10 0 0 0 0 194.3849 0 0 0 0 0
GLPK GPSA1 RBSK NUOA FDOH GLPD CYOA SDHA2 PNT1A PNT2A ATPA GLCUP
[1,] 0 0 0 140 0 0 40 -100 0 567.9655 -145.4663 0
GLCPTS GLUP RIBUP ACUP LACUP FORUP ETHUP SUCCUP PYRUP PIUP O2TX
[1,] 814.1562 0 0 0 0 -10 -1000 -100 -27.79634 120.5478 20
CO2TX ATPM ADK Growth
[1,] -990.3461 5.87 0 33.11752
>
> # a foodweb example: need to specify the cost function
> # here just sum of absolute values of flows...
> Linp(LIMRigaAutumn, cost = (rep(1, LIMRigaAutumn$NUnknowns)))
$residualNorm
[1] 5.725698e-13
$solutionNorm
[1] 761.2296
$X
P1->CO2 Flow(P2,CO2)=ZeroOrder Flow(Z,CO2)=ZeroOrder
[1,] 17.22501 29.95399 27.64922
Flow(N,CO2)=ZeroOrder Flow(B,CO2)=ZeroOrder Flow(CO2,P1)=ZeroOrder
[1,] 13.40297 247.5388 31.3182
Flow(CO2,P2)=ZeroOrder Flow(P1,Z)=ZeroOrder Flow(P1,N)=ZeroOrder
[1,] 54.4618 10.49431 4.12297
Flow(P1,DOC)=ZeroOrder P1->Sedimentation Flow(P2,DOC)=ZeroOrder
[1,] 1.56591 0.1 2.72309
Flow(P2,Z)=ZeroOrder Flow(P2,D)=ZeroOrder Flow(P2,Sedimentation)
[1,] 21.25472 0 0.34
Flow(N,DOC)=ZeroOrder Flow(N,Z)=ZeroOrder Flow(Z,DOC)=ZeroOrder
[1,] 0 0 6.509806
Flow(Z,D)=ZeroOrder Z->Sedimentation Flow(D,Z)=ZeroOrder
[1,] 0 0.78 4.7
Flow(D,DOC)=ZeroOrder D->Sedimentation Flow(B,N)=ZeroOrder
[1,] 0 13.92 9.44
B->Sedimentation Flow(DOC,B)=ZeroOrder
[1,] 0 263.7288
>
>
>
>
>
> dev.off()
null device
1
>