[Coin-discuss] addCol / resolve problem with OsiClpSolverInterface?

Stefan R0pke sropke at diku.dk
Thu Mar 16 16:13:56 EST 2006


Hello,

I ran into a problem when using OsiClpSolverInterface. To illustrate the 
problem, consider the following LP:

Minimize
  68 x0 + 8 x1 + 7 x2 + 6 x3
Subject To
     x0 +   x1                = 1
     x0 +          x2         = 1
     x0 +                 x3  = 1
Bounds
  0 <= x0 <= 1
  0 <= x1 <= 1
  0 <= x2 <= 1
  0 <= x3 <= 1
End

I solve the problem using OsiClpSolverInterface and get the solution 
x1 = x2 = x3 = 1 as expected. Then I add an extra variable (x4) to the 
problem to get

Minimize
  68 x0 + 8 x1 + 7 x2 + 6 x3 + 10 x4
Subject To
     x0 +   x1               +    x4  = 1
     x0 +          x2        +    x4  = 1
     x0 +                 x3          = 1

I do this with the addCol method on OsiClpSolverInterface. After calling 
resolve on OsiClpSolverInterface I get the expected solution x3=x4=1 but 
the reduced costs and dual variables appear to be wrong. 
OsiClpSolverInterface reports that the reduced cost of x4 is -5 (I had 
expected it to be zero) and the dual variables are 8, 7 and 6 which 
doesn't add up to 16 as I expected.
  If I try to resolve the problem from scratch then I get the expected 
values.
  Am I doing something wrong?

Below is sample code to illustrate the problem

Best regards,
Stefan

----------- main.cpp -----------

#include <OsiClpSolverInterface.hpp>
#include <CoinPackedVector.hpp>

using namespace std;

void printVector(const string &strHeader, const string &strVarName, const 
double *pVec, int iNElements)
{
 	int i;
 	cout << strHeader << ": ";
 	for (i=0; i < iNElements; i++)
 		cout << strVarName << i << "=" << pVec[i] << "  ";
 	cout << endl;
}

void printSolution(const OsiSolverInterface &osiSolver)
{
 	cout << "LP value: " << osiSolver.getObjValue() << endl;
 	printVector("Solution", "x", osiSolver.getColSolution(), 
osiSolver.getNumCols());
 	printVector("Reduced cost", "r", osiSolver.getReducedCost(), 
osiSolver.getNumCols());
 	printVector("Dual variables", "d", osiSolver.getRowPrice(), 
osiSolver.getNumRows());
}

int main(void)
{
 	OsiClpSolverInterface osiSolver;

 	// read LP
 	osiSolver.readLp("test.lp");
 	osiSolver.setObjSense(1);
 	osiSolver.initialSolve();
 	cout << "**** Initial problem: ****" << endl;
 	printSolution(osiSolver);

 	// Add a column with cost 10, covering row 0 and 1.
 	CoinPackedVector column;
 	column.insert(0,1);
 	column.insert(1,1);
 	osiSolver.addCol(column, 0, 1, 10);
 	osiSolver.resolve();
 	cout << "**** After adding column and resolve: ****" << endl;
 	printSolution(osiSolver);

 	// Solve from scratch:
 	CoinWarmStart *pWarmStart = osiSolver.getEmptyWarmStart();
 	osiSolver.setWarmStart(pWarmStart);
 	delete pWarmStart;
 	osiSolver.resolve();
 	cout << "**** Solved from scratch: ****" << endl;
 	printSolution(osiSolver);
 	return 0;
}

----------- test.lp -----------

Minimize
  68 x0 + 8 x1 + 7 x2 + 6 x3
Subject To
  x0 + x1 = 1
  x0 + x2 = 1
  x0 + x3 = 1
Bounds
  0 <= x0 <= 1
  0 <= x1 <= 1
  0 <= x2 <= 1
  0 <= x3 <= 1
End





More information about the Coin-discuss mailing list