Opened 13 years ago

Closed 20 months ago

## #51 closed defect (migrated)

Reported by: Owned by: nowozin mjs major OsiCpx

### Description

I use COIN-OR Osi 0.98 (checked out from SVN at 5th March 2008) to solve a large linear program. The code works as expected with OsiClp? and OsiMsk? but crashes with OsiVol? and OsiCpx?. I only report the OsiVol? case below but I suspect the bug is the same in OsiCpx?. The code programatically creates the problem in the following way (leaving out some details, but showing the order of calls):

```   OsiSolverInterface* si = new OsiVolSolverInterface;
// use column major in order to cheaply append columns
CoinPackedMatrix* matrix = new CoinPackedMatrix(true, 0, 0);
double* varLB = new double[N];
double* varUB = new double[N];
double* objective = new double[N];
// ... set variable upper/lower bounds and obj coefficients

CoinPackedVector csum;
// ... set some coefficients
matrix->appendRow(csum);

// Generate rows programmatically.  Do this in an extra matrix once instead of appending rows
// to the column-major main matrix
CoinPackedMatrix m_matrix(false, 0, 0);
m_matrix.setDimensions(0, N);
m_matrix.reserve(N * K, 2 * N * K, false);
for (unsigned int n = 0; n < N*K; ++n) {
CoinPackedVector nconstraint;
// ... set some coefficients in nconstraint
m_matrix.appendRow(margin_constraint);
}
matrix->bottomAppendPackedMatrix(m_matrix);

double* rowLB = new double[1 + N*K];
double* rowUB = new double[1 + N*K];
// ... set rowLB/rowUB elements

// Set constraint matrix
si->assignProblem(matrix, varLB, varUB, objective, rowLB, rowUB);
si->setObjSense(1); // minimize

CoinPackedVector col;
// ... setting elements in col
// CRASH upon calling this line with si a OsiVolSolverInterface.
```

My system is a x86 64bit system. Linux mohave 2.6.22-14-generic #1 SMP Tue Feb 12 02:46:46 UTC 2008 x86_64 GNU/Linux

The crash dump looks like this:

```Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 47594371764096 (LWP 8829)]
0x00002b4967434ea0 in CoinDisjointCopyN<bool> () from /opt/coin-osi-0.98/lib/libOsiVol.so.0
(gdb) bt
#0  0x00002b4967434ea0 in CoinDisjointCopyN<bool> ()
from /opt/coin-osi-0.98/lib/libOsiVol.so.0
#1  0x00002b496742dd70 in OsiVolSolverInterface::colRimResize_ ()
from /opt/coin-osi-0.98/lib/libOsiVol.so.0
from /opt/coin-osi-0.98/lib/libOsiVol.so.0
```

If you need further information, please let me know. I would provide an isolated test case but it is considerable work as the solver is just a part of a larger program. If required, I can isolate a piece of code that reproduces the bug.

### comment:1 Changed 13 years ago by nowozin

Small correct, the variable named "margin_constraint" should be "nconstraint".

### Changed 13 years ago by nowozin

Possible fix for assignProblem method in OsiVol?

### comment:2 Changed 13 years ago by nowozin

I added a patch that should fix this problem.

The bug surfaces when OsiVolSolverInterface::colRimResize_ correctly allocates a larger bool array for the continuous/integer flag array and then subsequently tries to copy the old elements over to the new array. Because assignProblem does not initialize continuous_, hence the old continous_ in the call to CoinDisjointCopyN is a NULL pointer at the time of copying.

The patch allocates a properly sized bool array in continous_ when assignProblem is called.

I verified the crash goes away and the solver seems to work, but then figured COIN Vol is not applicable to my problem as it cannot handle ranged rows, so I can not test this patch thoroughly.

### comment:3 Changed 13 years ago by lou

• Component changed from OsiVol to OsiCpx

Patch applied in OsiVolSolverInterfaceIO.cpp, Osi trunk r1201. Allocation of continuous_ placed inside the block protected by if (maxNumcols_ > 0) . I've retargeted the ticket to OsiCpx? (presumably the problem remains there).

### comment:4 Changed 11 years ago by stefan

I cannot reproduce the failure for OsiCpx. I took build.cpp from Osi/examples and replaced the loadProblem call by a assignProblem call, and it worked fine. (anyway, assignProblem just calls loadProblem)