Exemplo n.º 1
0
void 
OsiTestSolverInterface::deleteRows(const int num, const int * rowIndices)
{
  if (num > 0) {
    int * delPos = new int[num];
    CoinDisjointCopyN(rowIndices, num, delPos);
    std::sort(delPos, delPos + num);
    const int delNum = 
        static_cast<int>(std::unique(delPos, delPos + num) - delPos);

    const int rownum = getNumRows();
    CoinDeleteEntriesFromArray(rowlower_, rowlower_ + rownum,
			       delPos, delPos + delNum);
    CoinDeleteEntriesFromArray(rowupper_, rowupper_ + rownum,
			       delPos, delPos + delNum);
    CoinDeleteEntriesFromArray(rowsense_, rowsense_ + rownum,
			       delPos, delPos + delNum);
    CoinDeleteEntriesFromArray(rowrange_, rowrange_ + rownum,
			       delPos, delPos + delNum);
    CoinDeleteEntriesFromArray(rhs_, rhs_ + rownum,
			       delPos, delPos + delNum);
    CoinDeleteEntriesFromArray(rowprice_, rowprice_ + rownum,
			       delPos, delPos + delNum);
    CoinDeleteEntriesFromArray(lhs_, lhs_ + rownum,
			       delPos, delPos + delNum);

    updateRowMatrix_();
    rowMatrix_.deleteRows(delNum, delPos);
    colMatrixCurrent_ = false;

    delete[] delPos;
  }
}
Exemplo n.º 2
0
void
OsiTestSolverInterface::applyRowCut(const OsiRowCut& rc)
{
   const int rownum = getNumRows();
   const double lb = rc.lb();
   const double ub = rc.ub();
   rowRimResize_(rownum + 1);
   rowprice_[rownum] = 0.0;
   rowlower_[rownum] = lb;
   rowupper_[rownum] = ub;
   convertBoundToSense(lb, ub,
		       rowsense_[rownum], rhs_[rownum], rowrange_[rownum]);

   updateRowMatrix_();
   rowMatrix_.appendRow(rc.row());
   colMatrixCurrent_ = false;
}
Exemplo n.º 3
0
void 
OsiTestSolverInterface::addRow(const CoinPackedVectorBase& vec,
			      const double rowlb, const double rowub)
{
  const int rownum = getNumRows();
  rowRimResize_(rownum + 1);
  rowlower_[rownum] = rowlb;
  rowupper_[rownum] = rowub;
  convertBoundToSense(rowlb, rowub,
		      rowsense_[rownum], rhs_[rownum], rowrange_[rownum]);
  rowprice_[rownum] = 0.0;
  lhs_[rownum] = 0.0;

  updateRowMatrix_();
  rowMatrix_.appendRow(vec);
  colMatrixCurrent_ = false;
}
Exemplo n.º 4
0
void 
OsiVolSolverInterface::addRow(const CoinPackedVectorBase& vec,
			      const char rowsen, const double rowrhs,   
			      const double rowrng)
{
  const int rownum = getNumRows();
  rowRimResize_(rownum + 1);
  rowsense_[rownum] = rowsen;
  rhs_[rownum] = rowrhs;
  rowrange_[rownum] = rowrng;
  convertSenseToBound(rowsen, rowrhs, rowrng,
		      rowlower_[rownum], rowupper_[rownum]);
  rowprice_[rownum] = 0.0;
  lhs_[rownum] = 0.0;

  updateRowMatrix_();
  rowMatrix_.appendRow(vec);
  colMatrixCurrent_ = false;
}
Exemplo n.º 5
0
void 
OsiTestSolverInterface::addRows(const int numrows,
			       const CoinPackedVectorBase * const * rows,
			       const double* rowlb, const double* rowub)
{
  if (numrows > 0) {
    const int rownum = getNumRows();
    rowRimResize_(rownum + numrows);
    CoinDisjointCopyN(rowlb, numrows, rowlower_ + rownum);
    CoinDisjointCopyN(rowub, numrows, rowupper_ + rownum);
    for (int i = rownum + numrows - 1; i >= rownum; --i) {
      convertBoundToSense(rowlower_[i], rowupper_[i],
			  rowsense_[i], rhs_[i], rowrange_[i]);
    }
    CoinFillN(rowprice_ + rownum, numrows, 0.0);
    CoinFillN(lhs_      + rownum, numrows, 0.0);

    updateRowMatrix_();
    rowMatrix_.appendRows(numrows, rows);
    colMatrixCurrent_ = false;
  }
}
Exemplo n.º 6
0
const CoinPackedMatrix *
OsiTestSolverInterface::getMatrixByRow() const {
   updateRowMatrix_();
   return &rowMatrix_;
}
Exemplo n.º 7
0
void 
OsiTestSolverInterface::resolve()
{
  int i;
  
  checkData_();

  // Only one of these can do any work
  updateRowMatrix_();
  updateColMatrix_();

  const int dsize = getNumRows();
  const int psize = getNumCols();

  // Negate the objective coefficients if necessary
  if (objsense_ < 0) {
    std::transform(objcoeffs_, objcoeffs_+psize, objcoeffs_,
		   std::negate<double>());
  }

  // Set the lb/ub on the duals
  volprob_.dual_lb.allocate(dsize);
  volprob_.dual_ub.allocate(dsize);
  double * dlb = volprob_.dual_lb.v;
  double * dub = volprob_.dual_ub.v;
  for (i = 0; i < dsize; ++i) {
    dlb[i] = rowupper_[i] <  getInfinity() ? -1.0e31 : 0.0;
    dub[i] = rowlower_[i] > -getInfinity() ?  1.0e31 : 0.0;
  }
  volprob_.dsize = dsize;
  volprob_.psize = psize;
  
  // Set the dual starting point
  VOL_dvector& dsol = volprob_.dsol;
  dsol.allocate(dsize);
  std::transform(rowprice_, rowprice_+dsize, dsol.v,
		 std::bind2nd(std::multiplies<double>(), objsense_));

  // adjust the dual vector (if necessary) to be sure it's feasible
  double * dv = dsol.v;
  for (i = 0; i < dsize; ++i) {
    if (dv[i] < dlb[i]) {
      dv[i] = dlb[i];
    } else if (dv[i] > dub[i]) {
      dv[i] = dub[i];
    }
  }

  // If requested, check whether the matrix contains anything but 0/1/-1
#if 0
  isZeroOneMinusOne_ = false;
#else
  isZeroOneMinusOne_ = test_zero_one_minusone_(colMatrix_);
  if (isZeroOneMinusOne_) {
    colMatrixOneMinusOne_ = new OsiVolMatrixOneMinusOne_(colMatrix_);
    rowMatrixOneMinusOne_ = new OsiVolMatrixOneMinusOne_(rowMatrix_);
  }
#endif

  volprob_.solve(*this, true);

  // extract the solution

  // the lower bound on the objective value
  lagrangeanCost_ = objsense_ * volprob_.value;
  // the primal solution
  CoinDisjointCopyN(volprob_.psol.v, psize, colsol_);

  // Reset the objective coefficients if necessary
  if (objsense_ < 0) {
    std::transform(objcoeffs_, objcoeffs_ + psize, objcoeffs_,
		   std::negate<double>());
    // also, multiply the dual solution by -1
    std::transform(volprob_.dsol.v, volprob_.dsol.v+dsize, rowprice_,
		   std::negate<double>());
  } else {
    // now we just have to copy the dual
    CoinDisjointCopyN(volprob_.dsol.v, dsize, rowprice_);
  }

  // Compute the reduced costs
  compute_rc_(rowprice_, rc_);

  // Compute the left hand side (row activity levels)
  if (isZeroOneMinusOne_) {
    colMatrixOneMinusOne_->timesMajor(colsol_, lhs_);
  } else {
    colMatrix_.times(colsol_, lhs_);
  }

  if (isZeroOneMinusOne_) {
    delete colMatrixOneMinusOne_;
    colMatrixOneMinusOne_ = NULL;
    delete rowMatrixOneMinusOne_;
    rowMatrixOneMinusOne_ = NULL;
  }
}