Ticket #11917: trac_11917.patch

File trac_11917.patch, 4.4 KB (added by ncohen, 9 years ago)
  • sage/numerical/backends/coin_backend.pxd

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1318429072 -7200
    # Node ID 35f9c5e851294617d2b5ce5d3076df9455bea51b
    # Parent  8817e6aa58bb3ac0fd415a172f6685632d4ba9f4
    trac 11917 -- Memory leaks in Linear Programs
    
    diff --git a/sage/numerical/backends/coin_backend.pxd b/sage/numerical/backends/coin_backend.pxd
    a b  
    9898         void addRow (c_CoinPackedVector vec, double rowlb, double rowub)
    9999         c_CoinPackedMatrix * getMatrixByRow()
    100100         c_OsiCbcSolverInterface * c_OsiCbcSolverInterface(OsiSolverInterface * solver)
    101      c_OsiCbcSolverInterface *new_c_OsiCbcSolverInterface "new OsiCbcSolverInterface" ()
    102      c_OsiCbcSolverInterface * new2_c_OsiCbcSolverInterface "new OsiCbcSolverInterface" (OsiSolverInterface * solver)
    103      void del_OsiCbcSolverInterface "delete" (c_OsiCbcSolverInterface *)
     101     #c_OsiCbcSolverInterface *new_c_OsiCbcSolverInterface "new OsiCbcSolverInterface" ()
     102     #c_OsiCbcSolverInterface * new2_c_OsiCbcSolverInterface "new OsiCbcSolverInterface" (OsiSolverInterface * solver)
     103     #void del_OsiCbcSolverInterface "delete" (c_OsiCbcSolverInterface *)
    104104
    105105cdef class CoinBackend(GenericBackend):
    106106    cdef c_OsiCbcSolverInterface * si
  • sage/numerical/backends/coin_backend.pyx

    diff --git a/sage/numerical/backends/coin_backend.pyx b/sage/numerical/backends/coin_backend.pyx
    a b  
    2020
    2121    def __cinit__(self, maximization = True):
    2222       
    23         self.si = new_c_OsiCbcSolverInterface();
     23        self.si = new c_OsiCbcSolverInterface(NULL)
    2424        # stuff related to the loglevel
    2525        cdef c_CbcModel * model
    2626        model = self.si.getModelPtr()
     
    3535        else:
    3636            self.set_sense(-1)
    3737
     38    def __dealloc__(self):
     39        r"""
     40        Destructor function
     41        """
     42        del self.si
     43
    3844    cpdef int add_variable(self, lower_bound=0.0, upper_bound=None, binary=False, continuous=False, integer=False, obj=0.0, name=None) except -1:
    3945        """
    4046        Add a variable.
     
    981987        """
    982988        cdef CoinBackend p = CoinBackend(maximization = (1 if self.is_maximization() else -1))
    983989
    984         p.si = new2_c_OsiCbcSolverInterface(<OsiSolverInterface *> self.si)
     990        p.si = new c_OsiCbcSolverInterface(<OsiSolverInterface *> self.si)
    985991
    986992        return p
    987993
  • sage/numerical/backends/generic_backend.pyx

    diff --git a/sage/numerical/backends/generic_backend.pyx b/sage/numerical/backends/generic_backend.pyx
    a b  
    2626
    2727
    2828cdef class GenericBackend:
     29
    2930    cpdef int add_variable(self, lower_bound=0.0, upper_bound=None, binary=False, continuous=True, integer=False, obj=0.0, name=None) except -1:
    3031        """
    3132        Add a variable.
  • sage/numerical/backends/glpk_backend.pxd

    diff --git a/sage/numerical/backends/glpk_backend.pxd b/sage/numerical/backends/glpk_backend.pxd
    a b  
    2626         int fp_heur
    2727         int mir_cuts
    2828     c_glp_iocp * new_c_glp_iocp "new glp_iocp" ()
     29     #void del_c_glp_iocp "del glp_iocp" ()
    2930     void glp_init_iocp(c_glp_iocp *)
    3031     c_glp_prob * glp_create_prob()
    3132     void glp_set_prob_name(c_glp_prob *, char *)
  • sage/numerical/backends/glpk_backend.pyx

    diff --git a/sage/numerical/backends/glpk_backend.pyx b/sage/numerical/backends/glpk_backend.pyx
    a b  
    1616from sage.numerical.mip import MIPSolverException
    1717
    1818cdef class GLPKBackend(GenericBackend):
     19
    1920    def __cinit__(self, maximization = True):
    2021        """
    2122        Constructor
     
    2526            sage: p = MixedIntegerLinearProgram(solver="GLPK")
    2627        """
    2728        self.lp = glp_create_prob()
    28         self.iocp = new_c_glp_iocp()
     29        self.iocp = <c_glp_iocp* > sage_malloc(sizeof(c_glp_iocp))
    2930        glp_init_iocp(self.iocp)
    3031        self.iocp.presolve = GLP_ON
    3132        self.set_verbosity(0)
     
    10711072        Destructor
    10721073        """
    10731074        glp_delete_prob(self.lp)
     1075        sage_free(self.iocp)
  • sage/numerical/mip.pxd

    diff --git a/sage/numerical/mip.pxd b/sage/numerical/mip.pxd
    a b  
    55    cdef int INTEGER = 0
    66
    77from sage.numerical.backends.generic_backend cimport GenericBackend
     8
    89cdef class MIPVariable
    910cdef class MixedIntegerLinearProgram
    1011