coin-or / coin-or/CyLP

Incorrect basis inverse after solving small LP

Open
#20 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
JetBrains MPS
Stars
192
Forks
70
PR merge metrics
No merged PRs in 30d

Description

I've encountered a small LP for which the the basis inverse (lp.basisInverse) automatically calculated by CyLP seems to be wrong (along with associated data attrictures lp.tableau and lp.rhs). However, if I calculate the basis inverse myself using getBinvACol, it is correct. Could this have something to do with scaling? Is the basis inverse computed by CyLP with respect to a scaled version of the matrix rather than the original?

```
import numpy as np
from cylp.cy import CyClpSimplex
from cylp.py.modeling import CyLPArray

A = [[ -8, 30], [ -2, -4], [-14, 8], [ 2, -36], [30, -8], [10, 10]]
b = [115, -5, 1, -5, 191, 127]
c = [1, -1]

lp = CyClpSimplex()
A = np.matrix(A)
b = CyLPArray(b)
c = CyLPArray(c)

x = lp.addVariable('x', 2)

lp += x >= 0
lp += A * x <= b
lp.objective = -c * x if sense[0] == 'Max' else c * x
lp.primal(startFinishOptions = 'x')
Binv = np.zeros(shape = (lp.nConstraints, lp.nConstraints))
for i in range(lp.nVariables, lp.nVariables+lp.nConstraints):
lp.getBInvACol(i, Binv[i-lp.nVariables,:])
print 'Correct basis inverse:')
print Binv
print 'Incorrect basis inverse:')
print lp.basisInverse
print 'Correct RHS:')
np.dot(lp.basisInverse, myb)
print 'Incorrect RHS:')
print lp.rhs
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.