/* $Id$ * * Name: OsiLinear2MatrVec.cpp * Author: Pietro Belotti * Purpose: turn OsiSolverInterface objects into coefficient matrix and rhs vector * * (C) Carnegie-Mellon University, 2008. * This file is licensed under the Eclipse Public License (EPL) */ #include "CouenneDisjCuts.hpp" #include "OsiSolverInterface.hpp" #include "CoinPackedVector.hpp" #include "CoinPackedMatrix.hpp" #include "CoinHelperFunctions.hpp" #include "CouennePrecisions.hpp" #include "CouenneCutGenerator.hpp" #include "CouenneProblem.hpp" #include "CouenneExprVar.hpp" using namespace Ipopt; using namespace Couenne; // construct reduced, standard form matrix M from coefficient matrix of si void CouenneDisjCuts::OsiSI2MatrVec (CoinPackedMatrix &M, CoinPackedVector &r, OsiSolverInterface &si) const { // the coefficient matrix const CoinPackedMatrix *A = si.getMatrixByRow (); int nrows = A -> getMajorDim (), ncols = A -> getMinorDim (), nel = A -> getNumElements (); const char *sen = si.getRowSense (); const double *rac = si.getRowActivity (), *x = si.getColSolution (), *rlb = si.getRowLower (), *rub = si.getRowUpper (), *clb = si.getColLower (), *cub = si.getColUpper (), *el = A -> getElements (); const int *len = A -> getVectorLengths (), *start = A -> getVectorStarts (), *ind = A -> getIndices (); /////////////////// count rows that will have to be duplicated int ndupEl = 0, // count nonzero elements ndupRows = 0; // count rows for (int i=0; i ProduceOutput (J_MATRIX, J_DISJCUTS)) { printf ("matrix A (%d %d) %d elements:\n", nrows, ncols, nel); printf ("start: "); for (int i=0; i <= nrows; i++) printf ("%d ", start [i]); printf ("\nlen: "); for (int i=0; i < nrows; i++) printf ("%d ", len [i]); printf ("\nElements:\n"); for (int i=0, j=0; i *rlb + COUENNE_EPS)) continue; if (*sen != 'G') { *mSt++ = curM; *mLe++ = *len; CoinCopyN (ind + curA, *len, mIn + curM); CoinCopyN (el + curA, *len, mEl + curM); curM += *len; if (*rub != 0.) r.insert (mRows, *rub); mRows++; } if (*sen != 'L') { *mSt++ = curM; *mLe++ = *len; CoinCopyN (ind + curA, *len, mIn + curM); CoinInvN (el + curA, *len, mEl + curM); // invert contents curM += *len; if (*rlb != 0.) r.insert (mRows, -*rlb); // invert bound mRows++; } } // Variables //////////////////////////////////// for (int i=0; i *clb + COUENNE_EPS)) || (couenneCG_ -> Problem () -> Var (i) -> Multiplicity () <= 0)) continue; if (*clb > -COUENNE_INFINITY) { // has lower bound -- invert! *mSt++ = curM; *mLe++ = 1; mIn [curM] = i; mEl [curM++] = -1.; if (*clb != 0.) r.insert (mRows, -*clb); // invert bound so x >= b becomes -x <= -b mRows++; } if (*cub < COUENNE_INFINITY) { // has upper bound *mSt++ = curM; *mLe++ = 1; mIn [curM] = i; mEl [curM++] = 1.; if (*cub != 0.) r.insert (mRows, *cub); mRows++; } } *mSt = curM; mSt -= mRows; mLe -= mRows; if (jnlst_ -> ProduceOutput (J_MATRIX, J_DISJCUTS)) { printf ("matrix (%d %d) %d elements:\n", mRows, ncols, curM); printf ("start: "); for (int i=0; i<=mRows; i++) printf ("%d ", mSt [i]); printf ("\nlen: "); for (int i=0; i