Ejemplo n.º 1
0
    def test_glpk_remove_variable(self):
        var = self.model.variables[0]
        self.assertEqual(
            (self.model.constraints["M_atp_c"].expression - (
                -1.0 * self.model.variables.R_ACKr - 1.0 * self.model.variables.R_ADK1 + 1.0 * self.model.variables.R_ATPS4r -
                1.0 * self.model.variables.R_PGK - 1.0 * self.model.variables.R_SUCOAS - 59.81 * self.model.variables.R_Biomass_Ecoli_core_w_GAM -
                1.0 * self.model.variables.R_GLNS - 1.0 * self.model.variables.R_GLNabc - 1.0 * self.model.variables.R_PFK -
                1.0 * self.model.variables.R_PPCK - 1.0 * self.model.variables.R_PPS + 1.0 * self.model.variables.R_PYK -
                1.0 * self.model.variables.R_ATPM
            )).expand() - 0, 0
        )
        self.assertEqual(self.model.constraints["M_atp_c"].lb, 0)
        self.assertEqual(self.model.constraints["M_atp_c"].ub, 0)

        self.assertEqual(var.problem, self.model)
        self.model.remove(var)
        self.model.update()

        self.assertEqual(
            (self.model.constraints["M_atp_c"].expression - (
                -1.0 * self.model.variables.R_ACKr - 1.0 * self.model.variables.R_ADK1 + 1.0 * self.model.variables.R_ATPS4r -
                1.0 * self.model.variables.R_SUCOAS - 1.0 * self.model.variables.R_PGK -
                1.0 * self.model.variables.R_GLNS - 1.0 * self.model.variables.R_GLNabc - 1.0 * self.model.variables.R_PFK -
                1.0 * self.model.variables.R_PPCK - 1.0 * self.model.variables.R_PPS + 1.0 * self.model.variables.R_PYK -
                1.0 * self.model.variables.R_ATPM
            )).expand() - 0, 0
        )

        self.assertNotIn(var, self.model.variables.values())
        self.assertEqual(glp_find_col(self.model.problem, var.name), 0)
        self.assertEqual(var.problem, None)
Ejemplo n.º 2
0
 def name(self, value):
     old_name = getattr(self, "name", None)
     super(Variable, Variable).name.fset(self, value)
     _glpk_validate_id(value)
     if getattr(self, 'problem', None) is not None:
         glp_set_col_name(self.problem.problem,
                          glp_find_col(self.problem.problem, old_name),
                          str(value))
Ejemplo n.º 3
0
 def name(self, value):
     old_name = getattr(self, 'name', None)
     self._name = value
     if getattr(self, 'problem', None) is not None:
         glp_set_col_name(self.problem.problem,
                          glp_find_col(self.problem.problem, old_name),
                          str(value))
         self.problem.variables.update_key(old_name)
Ejemplo n.º 4
0
 def name(self, value):
     if len(value) > 256:
         raise ValueError(
             "GLPK does not support ID's longer than 256 characters")
     if getattr(self, 'problem', None) is not None:
         glp_set_col_name(self.problem.problem,
                          glp_find_col(self.problem.problem, self.name),
                          str(value))
     super(Variable, Variable).name.fset(self, value)
Ejemplo n.º 5
0
 def _index(self):
     if self.problem is not None:
         i = glp_find_col(self.problem.problem, str(self.name))
         if i != 0:
             return i
         else:
             raise IndexError(
                 "Could not determine column index for variable %s" % self)
     else:
         return None
Ejemplo n.º 6
0
 def index(self):
     if self.problem is not None:
         i = glp_find_col(self.problem.problem, str(self.name))
         if i != 0:
             return i
         else:
             raise IndexError(
                 "Could not determine column index for variable %s" % self)
     else:
         return None
Ejemplo n.º 7
0
 def test_glpk_remove_variable(self):
     var = self.model.variables.values()[0]
     self.assertEqual(self.model.constraints['M_atp_c'].__str__(
     ), 'M_atp_c: 0.0 <= -1.0*R_ACKr - 1.0*R_ADK1 + 1.0*R_ATPS4r - 1.0*R_PGK - 1.0*R_SUCOAS - 59.81*R_Biomass_Ecoli_core_w_GAM - 1.0*R_GLNS - 1.0*R_GLNabc - 1.0*R_PFK - 1.0*R_PPCK - 1.0*R_PPS + 1.0*R_PYK - 1.0*R_ATPM <= 0.0'
                      )  # noqa: E501
     self.assertEqual(var.problem, self.model)
     self.model.remove(var)
     self.model.update()
     self.assertEqual(self.model.constraints['M_atp_c'].__str__(
     ), 'M_atp_c: 0.0 <= -1.0*R_ACKr - 1.0*R_ADK1 + 1.0*R_ATPS4r - 1.0*R_PGK - 1.0*R_SUCOAS - 1.0*R_GLNS - 1.0*R_GLNabc - 1.0*R_PFK - 1.0*R_PPCK - 1.0*R_PPS + 1.0*R_PYK - 1.0*R_ATPM <= 0.0'
                      )  # noqa: E501
     self.assertNotIn(var, self.model.variables.values())
     self.assertEqual(glp_find_col(self.model.problem, var.name), 0)
     self.assertEqual(var.problem, None)
    def test_glpk_remove_variable(self):
        var = self.model.variables[0]
        self.assertEqual(
            (self.model.constraints["M_atp_c"].expression -
             (-1.0 * self.model.variables.R_ACKr - 1.0 *
              self.model.variables.R_ADK1 + 1.0 * self.model.variables.R_ATPS4r
              - 1.0 * self.model.variables.R_PGK -
              1.0 * self.model.variables.R_SUCOAS -
              59.81 * self.model.variables.R_Biomass_Ecoli_core_w_GAM - 1.0 *
              self.model.variables.R_GLNS - 1.0 * self.model.variables.R_GLNabc
              - 1.0 * self.model.variables.R_PFK - 1.0 *
              self.model.variables.R_PPCK - 1.0 * self.model.variables.R_PPS +
              1.0 * self.model.variables.R_PYK -
              1.0 * self.model.variables.R_ATPM)).expand() - 0, 0)
        self.assertEqual(self.model.constraints["M_atp_c"].lb, 0)
        self.assertEqual(self.model.constraints["M_atp_c"].ub, 0)

        self.assertEqual(var.problem, self.model)
        self.model.remove(var)
        self.model.update()

        self.assertEqual(
            (self.model.constraints["M_atp_c"].expression -
             (-1.0 * self.model.variables.R_ACKr - 1.0 *
              self.model.variables.R_ADK1 + 1.0 * self.model.variables.R_ATPS4r
              - 1.0 * self.model.variables.R_SUCOAS - 1.0 *
              self.model.variables.R_PGK - 1.0 * self.model.variables.R_GLNS -
              1.0 * self.model.variables.R_GLNabc - 1.0 *
              self.model.variables.R_PFK - 1.0 * self.model.variables.R_PPCK -
              1.0 * self.model.variables.R_PPS +
              1.0 * self.model.variables.R_PYK -
              1.0 * self.model.variables.R_ATPM)).expand() - 0, 0)

        self.assertNotIn(var, self.model.variables.values())
        self.assertEqual(glp_find_col(self.model.problem, var.name), 0)
        self.assertEqual(var.problem, None)
Ejemplo n.º 9
0
 def name(self, value):
     if getattr(self, 'problem', None) is not None:
         glp_set_col_name(self.problem.problem,
                          glp_find_col(self.problem.problem, self.name),
                          str(value))
     super(Variable, Variable).name.fset(self, value)
Ejemplo n.º 10
0
 def name(self, value):
     old_name = getattr(self, 'name', None)
     self._name = value
     if getattr(self, 'problem', None) is not None:
         glp_set_col_name(self.problem.problem, glp_find_col(self.problem.problem, old_name), str(value))
         self.problem.variables.update_key(old_name)
Ejemplo n.º 11
0
 def name(self, value):
     if getattr(self, 'problem', None) is not None:
         glp_set_col_name(self.problem.problem, glp_find_col(self.problem.problem, self.name), str(value))
     super(Variable, Variable).name.fset(self, value)
Ejemplo n.º 12
0
 def name(self, value):
     old_name = getattr(self, "name", None)
     super(Variable, Variable).name.fset(self, value)
     _glpk_validate_id(value)
     if getattr(self, 'problem', None) is not None:
         glp_set_col_name(self.problem.problem, glp_find_col(self.problem.problem, old_name), str(value))