From 9b45ba2b474cc23cb46d128eef1aa9d60aa70321 Mon Sep 17 00:00:00 2001
From: Claus Jonathan Fritzemeier <clausjonathan.fritzemeier@hhu.de>
Date: Thu, 28 Jan 2016 15:46:39 +0100
Subject: [PATCH] non working maximum total flux

---
 R/sysBiolAlg_mtfClass.R     | 28 ++++++++++++++++++++++------
 inst/NEWS.Rd                |  7 +++++++
 man/sysBiolAlg_mtf-class.Rd |  5 +++++
 3 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/R/sysBiolAlg_mtfClass.R b/R/sysBiolAlg_mtfClass.R
index 362d339..cacd177 100644
--- a/R/sysBiolAlg_mtfClass.R
+++ b/R/sysBiolAlg_mtfClass.R
@@ -47,6 +47,7 @@ setMethod(f = "initialize",
                                 react = NULL, lb = NULL, ub = NULL,
                                 costcoefbw = NULL,
                                 costcoeffw = NULL,
+                                lpdir = "min",
                                 absMAX = SYBIL_SETTINGS("MAXIMUM"),
                                 useNames = SYBIL_SETTINGS("USE_NAMES"),
                                 cnames = NULL,
@@ -65,6 +66,7 @@ setMethod(f = "initialize",
                   stopifnot(is(model, "modelorg"),
                             is(wtobj, "numeric"),
                             is(absMAX, "numeric"))
+                  stopifnot(lpdir %in% c("min", "max"))
 
                   # If wtobj is longer than 1, mtf algorithm has to run several
                   # times. In that case, wtobj is not written in the problem
@@ -102,6 +104,8 @@ setMethod(f = "initialize",
                   #            |      |      |
                   #  obj    0  |  1   |  1   |
 
+                  # NOTE: if lpdir == "max" the 2nd and 3rd block
+                  # will be <= instead of >= and signs change.
 
                   # ---------------------------------------------
                   # problem dimensions
@@ -131,10 +135,18 @@ setMethod(f = "initialize",
                   fi <- c(1:nc)
 
                   # rows for the delta match matrix
-                  diag(LHS[(nr+1)   :(nr+nc)  ,1       :nc    ]) <-  1
-                  diag(LHS[(nr+1)   :(nr+nc)  ,(nc+1)  :(2*nc)]) <-  1
-                  diag(LHS[(nr+nc+1):(nr+2*nc),1       :nc    ]) <- -1
-                  diag(LHS[(nr+nc+1):(nr+2*nc),(2*nc+1):(3*nc)]) <-  1
+                  if(lpdir=="min"){
+                  	diag(LHS[(nr+1)   :(nr+nc)  ,1       :nc    ]) <-  1
+                  	diag(LHS[(nr+1)   :(nr+nc)  ,(nc+1)  :(2*nc)]) <-  1
+                  	diag(LHS[(nr+nc+1):(nr+2*nc),1       :nc    ]) <- -1
+                  	diag(LHS[(nr+nc+1):(nr+2*nc),(2*nc+1):(3*nc)]) <-  1
+                  }else{
+                  	diag(LHS[(nr+1)   :(nr+nc)  ,1       :nc    ]) <-  1
+                  	diag(LHS[(nr+1)   :(nr+nc)  ,(nc+1)  :(2*nc)]) <-  -1
+                  	diag(LHS[(nr+nc+1):(nr+2*nc),1       :nc    ]) <- -1
+                  	diag(LHS[(nr+nc+1):(nr+2*nc),(2*nc+1):(3*nc)]) <-  1
+                  }
+                  
 
                   # fix the value of the objective function
                   LHS[(nr+2*nc+1),1:nc] <- obj_coef(model)
@@ -156,7 +168,11 @@ setMethod(f = "initialize",
                   #rupper <- c(rhs(model), rep(absMAX, 2*nc + 1))
                   rlower <- c(rep(0, nr), rep(0, 2*nc), currmo)
                   rupper <- c(rep(0, nr), rep(absMAX, 2*nc + 1))
-                  rtype  <- c(rep("E", nr), rep("L", 2*nc + 1))
+                  if(lpdir == "min"){
+                  	rtype  <- c(rep("E", nr), rep("L", 2*nc), "L")
+                  }else{
+                  	rtype  <- c(rep("E", nr), rep("U", 2*nc), "L")
+                  }
 
                   # ---------------------------------------------
                   # objective function
@@ -252,7 +268,7 @@ setMethod(f = "initialize",
                                             rlb        = rlower,
                                             rub        = rupper,
                                             rtype      = rtype,
-                                            lpdir      = "min",
+                                            lpdir      = lpdir,
                                             ctype      = NULL,
                                             cnames     = colNames,
                                             rnames     = rowNames,
diff --git a/inst/NEWS.Rd b/inst/NEWS.Rd
index 2875c43..8c6c333 100644
--- a/inst/NEWS.Rd
+++ b/inst/NEWS.Rd
@@ -6,6 +6,13 @@
 
 \newcommand{\CRANpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}}
 
+\section{Changes in version 1.3.4 2016-01-27}{
+  \itemize{
+    \item \code{sysBiolAlg_mtfClass} got option to be used as maximum total
+    flux, too.
+  }
+}
+% ---------------------------------------------------------------------------- %
 \section{Changes in version 1.3.3 2015-11-25}{
   \itemize{
     \item \code{addReact} crashed for irreversible models.
diff --git a/man/sysBiolAlg_mtf-class.Rd b/man/sysBiolAlg_mtf-class.Rd
index baf906d..397adb5 100644
--- a/man/sysBiolAlg_mtf-class.Rd
+++ b/man/sysBiolAlg_mtf-class.Rd
@@ -111,6 +111,11 @@
       values given in \code{costcoeffw}.\cr
       Default: \code{NULL}.
     }
+    \item{\code{lpdir}:}{Object of class \code{"character"}
+      giving the direction of optimization. with \code{max} this class can be
+      used to optimize maximum total flux. Cavetas: Because of changes in the
+      linear problem, this cannot be changed later. Default: \code{min}.
+    }
     \item{absMAX}{
       A single numerical value used as a maximum value for upper variable
       and contraint bounds.\cr
-- 
GitLab