#15159: Segfault after deepcopy of MixedIntegerLinearProgram
--------------------------------------+------------------------
       Reporter:  jvkersch            |        Owner:
           Type:  defect              |       Status:  new
       Priority:  major               |    Milestone:  sage-6.4
      Component:  linear programming  |   Resolution:
       Keywords:                      |    Merged in:
        Authors:                      |    Reviewers:
Report Upstream:  N/A                 |  Work issues:
         Branch:                      |       Commit:
   Dependencies:  #20414              |     Stopgaps:
--------------------------------------+------------------------
Changes (by mkoeppe):

 * dependencies:   => #20414


Comment:

 These segfaults happen because `deepcopy` does not copy the backend at
 all:
 {{{
 sage: p = MixedIntegerLinearProgram()
 sage: w = p.new_variable()
 sage: q = deepcopy(p)
 sage: p.get_backend()
 <sage.numerical.backends.coin_backend.CoinBackend object at 0x19e7be670>
 sage: q.get_backend()
 }}}
 #20414 supplies the necessary `__deepcopy__` methods.


 However, the same example with `copy` instead of `deepcopy` also does not
 work, but for a different reason.
 {{{
 sage: p = MixedIntegerLinearProgram(solver='glpk')
 sage: w = p.new_variable()
 sage: q = copy(p)
 sage: q.add_constraint(w[0] >= 0)
 ...
 GLPKError: glp_set_mat_row: i = 1; len = 1; invalid row length
 Error detected in file glpapi01.c at line 760
 }}}
 What's happening in this example is that the variable w[0] is created in
 the wrong MIP -- in `p`; because `w` belongs to `p` and knows nothing
 about `q`. Then using that variable in `q` leads to an out-of-bounds error
 (with GLPK) or crash (with COIN) as reported in #19523, #19525, #20360.

 If one creates the variable `w[0]` before copying (simply by "mentioning"
 it), then this code goes through:
 {{{
 sage: p = MixedIntegerLinearProgram()
 sage: w = p.new_variable()
 sage: w[0]
 x_0
 sage: sage: q = deepcopy(p)
 sage: sage: q.add_constraint(w[0] >= 0)
 }}}

 We should conclude that `copy` (or `deepcopy`) of a
 `MixedIntegerLinearProgram` is not very useful because we can no longer
 (safely) access its variables. See #19523.

--
Ticket URL: <http://trac.sagemath.org/ticket/15159#comment:6>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to