# 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
|
|
98 | 98 | void addRow (c_CoinPackedVector vec, double rowlb, double rowub) |
99 | 99 | c_CoinPackedMatrix * getMatrixByRow() |
100 | 100 | 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 *) |
104 | 104 | |
105 | 105 | cdef class CoinBackend(GenericBackend): |
106 | 106 | cdef c_OsiCbcSolverInterface * si |
diff --git a/sage/numerical/backends/coin_backend.pyx b/sage/numerical/backends/coin_backend.pyx
a
|
b
|
|
20 | 20 | |
21 | 21 | def __cinit__(self, maximization = True): |
22 | 22 | |
23 | | self.si = new_c_OsiCbcSolverInterface(); |
| 23 | self.si = new c_OsiCbcSolverInterface(NULL) |
24 | 24 | # stuff related to the loglevel |
25 | 25 | cdef c_CbcModel * model |
26 | 26 | model = self.si.getModelPtr() |
… |
… |
|
35 | 35 | else: |
36 | 36 | self.set_sense(-1) |
37 | 37 | |
| 38 | def __dealloc__(self): |
| 39 | r""" |
| 40 | Destructor function |
| 41 | """ |
| 42 | del self.si |
| 43 | |
38 | 44 | 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: |
39 | 45 | """ |
40 | 46 | Add a variable. |
… |
… |
|
981 | 987 | """ |
982 | 988 | cdef CoinBackend p = CoinBackend(maximization = (1 if self.is_maximization() else -1)) |
983 | 989 | |
984 | | p.si = new2_c_OsiCbcSolverInterface(<OsiSolverInterface *> self.si) |
| 990 | p.si = new c_OsiCbcSolverInterface(<OsiSolverInterface *> self.si) |
985 | 991 | |
986 | 992 | return p |
987 | 993 | |
diff --git a/sage/numerical/backends/generic_backend.pyx b/sage/numerical/backends/generic_backend.pyx
a
|
b
|
|
26 | 26 | |
27 | 27 | |
28 | 28 | cdef class GenericBackend: |
| 29 | |
29 | 30 | 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: |
30 | 31 | """ |
31 | 32 | Add a variable. |
diff --git a/sage/numerical/backends/glpk_backend.pxd b/sage/numerical/backends/glpk_backend.pxd
a
|
b
|
|
26 | 26 | int fp_heur |
27 | 27 | int mir_cuts |
28 | 28 | c_glp_iocp * new_c_glp_iocp "new glp_iocp" () |
| 29 | #void del_c_glp_iocp "del glp_iocp" () |
29 | 30 | void glp_init_iocp(c_glp_iocp *) |
30 | 31 | c_glp_prob * glp_create_prob() |
31 | 32 | void glp_set_prob_name(c_glp_prob *, char *) |
diff --git a/sage/numerical/backends/glpk_backend.pyx b/sage/numerical/backends/glpk_backend.pyx
a
|
b
|
|
16 | 16 | from sage.numerical.mip import MIPSolverException |
17 | 17 | |
18 | 18 | cdef class GLPKBackend(GenericBackend): |
| 19 | |
19 | 20 | def __cinit__(self, maximization = True): |
20 | 21 | """ |
21 | 22 | Constructor |
… |
… |
|
25 | 26 | sage: p = MixedIntegerLinearProgram(solver="GLPK") |
26 | 27 | """ |
27 | 28 | self.lp = glp_create_prob() |
28 | | self.iocp = new_c_glp_iocp() |
| 29 | self.iocp = <c_glp_iocp* > sage_malloc(sizeof(c_glp_iocp)) |
29 | 30 | glp_init_iocp(self.iocp) |
30 | 31 | self.iocp.presolve = GLP_ON |
31 | 32 | self.set_verbosity(0) |
… |
… |
|
1071 | 1072 | Destructor |
1072 | 1073 | """ |
1073 | 1074 | glp_delete_prob(self.lp) |
| 1075 | sage_free(self.iocp) |
diff --git a/sage/numerical/mip.pxd b/sage/numerical/mip.pxd
a
|
b
|
|
5 | 5 | cdef int INTEGER = 0 |
6 | 6 | |
7 | 7 | from sage.numerical.backends.generic_backend cimport GenericBackend |
| 8 | |
8 | 9 | cdef class MIPVariable |
9 | 10 | cdef class MixedIntegerLinearProgram |
10 | 11 | |