Ticket #13148: trac_13148-number_of_variables_in_LP.patch

File trac_13148-number_of_variables_in_LP.patch, 2.1 KB (added by ppurka, 11 years ago)

a patch to have <LP>.number_of_variables() return what it should (just minor changes)

  • sage/numerical/mip.pxd

    # HG changeset patch
    # User Dmitrii Pasechnik <dimpase@gmail.com>
    # Date 1340443773 -10800
    # Node ID 91eb41bf5fbdfa4db888780158232cb27be82235
    # Parent  caf386433bbef30e147fa04baa7159804f810704
    adding  number_of_variables() method to MixedIntegerProgram class
    
    diff --git a/sage/numerical/mip.pxd b/sage/numerical/mip.pxd
    a b  
    2020    cdef int __REAL
    2121    cdef int __INTEGER
    2222    cpdef int number_of_constraints(self)
     23    cpdef int number_of_variables(self)
    2324    cdef int _check_redundant
    2425    cdef list _constraints
    2526
  • sage/numerical/mip.pyx

    diff --git a/sage/numerical/mip.pyx b/sage/numerical/mip.pyx
    a b  
    440440      """
    441441      return self._backend.nrows()
    442442
     443    cpdef int number_of_variables(self):
     444      r"""
     445      Returns the number of variables used so far. Note that this is
     446      backend-dependent, i.e. we count solver's variables rather than
     447      user's variables. An example of the latter can be seen below:
     448      Gurobi converts double inequalities, i.e. inequalities like
     449      `m <= c^T x <= M`, with `m<M`,  into equations, by adding extra
     450      variables: `c^T x + y = M`, `0 <= y <= M-m`.
     451
     452      EXAMPLE::
     453            sage: p = MixedIntegerLinearProgram()
     454            sage: p.add_constraint(p[0] - p[2], max = 4)
     455            sage: p.number_of_variables()
     456            2
     457            sage: p.add_constraint(p[0] - 2*p[1], min = 1)
     458            sage: p.number_of_variables()
     459            3
     460            sage: p = MixedIntegerLinearProgram(solver="glpk")
     461            sage: p.add_constraint(p[0] - p[2], min = 1, max = 4)
     462            sage: p.number_of_variables()
     463            2
     464            sage: p = MixedIntegerLinearProgram(solver="gurobi")   # optional - Gurobi
     465            sage: p.add_constraint(p[0] - p[2], min = 1, max = 4)  # optional - Gurobi
     466            sage: p.number_of_variables()                          # optional - Gurobi
     467            3
     468      """
     469      return self._backend.ncols()
     470
    443471    def constraints(self, indices = None):
    444472        r"""
    445473        Returns a list of constraints, as 3-tuples.