Opened 7 years ago

Last modified 20 months ago

#19523 new defect

Raise an error when constraints are added to the wrong MILP — at Version 17

Reported by: Jeroen Demeyer Owned by:
Priority: major Milestone: sage-7.3
Component: linear programming Keywords:
Cc: Yuan Zhou Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by Jeroen Demeyer)

sage: p = MixedIntegerLinearProgram(solver="glpk")
sage: q = MixedIntegerLinearProgram(solver="glpk")
sage: q.add_constraint(p[0] <= 1)
------------------------------------------------------------------------
Unhandled SIGABRT: An abort() occurred in Sage.
This probably occurred because a *compiled* component of Sage has a bug
in it and is not properly wrapped with sig_on(), sig_off().
Sage will now terminate.
------------------------------------------------------------------------
sage: p = MixedIntegerLinearProgram(solver="glpk")
sage: q = MixedIntegerLinearProgram(solver="glpk")
sage: q.add_constraint(p[0] <= 1)
---------------------------------------------------------------------------
GLPKError                                 Traceback (most recent call last)
...
GLPKError: glp_set_mat_row: i = 1; len = 1; invalid row length 
Error detected in file glpapi01.c at line 760

Before #19525, this would instead crash Sage. A crash still happens with COIN (#20360).

This ticket is to actually fix the error completely or give a better error message.

And low-level error message with the PPL and InteractiveLP (#20296 ) backends.

The CVX backend silently adds a new variable that is accessible only to the backend:.

sage: sage: default_mip_solver("cvxopt")
sage: sage: p = MixedIntegerLinearProgram()
sage: sage: q = MixedIntegerLinearProgram()
sage: sage: q.add_constraint(p[0] <= 1)
sage: q.number_of_variables()
1

Change History (17)

comment:1 Changed 7 years ago by Jeroen Demeyer

Dependencies: #19525
Description: modified (diff)

comment:2 Changed 7 years ago by Nathann Cohen

Cc: Nathann Cohen added

comment:3 Changed 7 years ago by Jeroen Demeyer

Description: modified (diff)
Priority: criticalmajor

comment:4 Changed 7 years ago by Matthias Köppe

While MIPVariable objects know which MIP they belong to, their "components" gotten by p[0] etc. are elements of LinearFunctionsParent(base_ring), and do not remember their MIP (nor even their name). So with the current design it does not seem possible to catch the error of adding constraints to the wrong MIP. So unfortunately only lower-level error checking, catching out-of-bounds indices, is possible.

comment:5 Changed 7 years ago by Matthias Köppe

Description: modified (diff)

comment:6 Changed 7 years ago by Jeroen Demeyer

Given that p[0] is just a linear function, it would make the most sense if q.add_constraint(p[0] <= 1) would simply work, not give an error message.

comment:7 Changed 7 years ago by Matthias Köppe

No, q has no variables at this point.

comment:8 in reply to:  7 Changed 7 years ago by Jeroen Demeyer

Replying to mkoeppe:

No, q has no variables at this point.

That's exactly my point: the variables should be added by q.add_constraint().

comment:9 Changed 7 years ago by Matthias Köppe

I'm not sure that this would be a good interface. It would allow to add variables, but only variables with default settings (continuous, lower bound 0, no upper bound, no name). I think it's better to raise an error, which could help spot programming mistakes -- at least when there's a dimension mismatch between the two problems. This bound checking should be done by the backends -- see #10232.

Last edited 7 years ago by Matthias Köppe (previous) (diff)

comment:10 in reply to:  9 Changed 7 years ago by Jeroen Demeyer

Replying to mkoeppe:

at least when there's a dimension mismatch between the two problems.

No. It should be always an error, or never an error. If it's only an error "when there's a dimension mismatch between the two problems", that will be more confusing than either extreme.

comment:11 Changed 7 years ago by Matthias Köppe

Then I strongly prefer to always raise an error in this situation. This requires changes to LinearFunction (a class that is I think only used in the context of MixedIntegerLinearProgram), so that it remembers the MIP that it relates to.

The mapping from MIP variables (and their indexed components) to integer indices (designating backend columns) is determined dynamically, adding a backend column when a MIP variable component is accessed. Because of this there's simply no good way to write correct code that interchanges MIP variables between two MixedIntegerLinearPrograms, or to use LinearFunctions directly somehow (without referring to the correct MIP's variables).

Last edited 7 years ago by Matthias Köppe (previous) (diff)

comment:12 Changed 7 years ago by Matthias Köppe

Dependencies: #19525#19525, #20360
Description: modified (diff)

comment:13 Changed 7 years ago by Matthias Köppe

Summary: Adding constraints for the wrong MILP crashes SageRaise an error when constraints are added to the wrong MILP

Since the crashes are now on separate tickets, I have changed the title of this ticket.

comment:14 Changed 6 years ago by Matthias Köppe

See also #15159, which raises a similar question when q started out as a copy of p.

comment:15 Changed 6 years ago by Matthias Köppe

A solution could be to change LinearFunctionsParent etc. so that it not only has remembers the base_ring but also the MIP.

comment:16 Changed 6 years ago by Matthias Köppe

Milestone: sage-6.10sage-7.3

comment:17 Changed 5 years ago by Jeroen Demeyer

Cc: Nathann Cohen removed
Dependencies: #19525, #20360
Description: modified (diff)
Note: See TracTickets for help on using tickets.