[Osi] Add setCoeff method to set the coefficient of a column within a given row?

Jan-Willem Goossens jhmgoossens at hotmail.com
Tue Nov 29 14:41:35 EST 2011


Hi,

For years I've always added a setCoeff function to the
OsiSolverInterface to set the coefficient of a column within a given
row after the problem was already built. To me, it seems like this
might be useful to others as well.

What about extending OsiSolverInterface to include such a method,
similar to setObjCoeff?

In case this is approved, please find below my donated code changes to
OsiSolverInterface, OsiClpSolverInterface, OsiCbcSolverInterface and
OsiCpxSolverInterface to implement setCoeff.

Regards,

Jan-Willem Goossens

------------------------------------
//OsiSolverInterface.hpp
/** Set a coefficient of a column within a given row.*/
virtual void setCoeff(int rowIndex, int columnIndex, double
elementValue) { throw; };

//--------------------------------
//OsiCbcSolverInterface.hpp
/** Set the coefficient of a column within a given row */
virtual void setCoeff(int rowIndex, int columnIndex, double elementValue);

//OsiCbcSolverInterface.cpp
/** Set a coefficient of a column in a row */
void OsiCbcSolverInterface::setCoeff(int rowIndex, int columnIndex,
double elementValue)
{
	modelPtr_->solver()->setCoeff(rowIndex, columnIndex, elementValue);
}

//--------------------------------
//OsiClpSolverInterface.hpp
/** Set the coefficient of a column within a given row */
virtual void setCoeff(int rowIndex, int columnIndex, double elementValue);

//OsiClpSolverInterface.cpp
/* Set a coefficient of a column in a row */
void OsiClpSolverInterface::setCoeff(int rowIndex, int columnIndex,
double elementValue)
{
#ifndef NDEBUG
	int n = modelPtr_->numberColumns();
	if (columnIndex<0||columnIndex>=n) {
		indexError(columnIndex,"setCoeff");
	}
	int m = modelPtr_->numberRows();
	if (rowIndex<0||rowIndex>=m) {
		indexError(rowIndex,"setCoeff");
	}
#endif
	modifyCoefficient(rowIndex, columnIndex, elementValue, false);	//
last argument is keepZero
}

//--------------------------------
//OsiCpxSolverInterface.hpp
/** Set the coefficient of a column within a given row */
virtual void setCoeff(int rowIndex, int columnIndex, double elementValue);

//OsiCpxSolverInterface.cpp
/* Set a coefficient of a column in a row */
void OsiCpxSolverInterface::setCoeff(int rowIndex, int columnIndex,
double elementValue)
{
  debugMessage("OsiCpxSolverInterface::setCoeff(%d, %d, %g)\n",
rowIndex, columnIndex, elementValue);

  int err = CPXchgcoef( env_, getMutableLpPtr(), rowIndex,
columnIndex, elementValue);

  checkCPXerror( err, "CPXchgcoef", "setCoeff" );
}


More information about the Osi mailing list