[Coin-discuss] OSI - PORTA

Matthew Galati magh at lehigh.edu
Tue Jul 11 14:22:39 EDT 2006


Hi - I wrote a little function to convert an OSI instance to INE format 
(as used by PORTA, azove, ...).

I put it as a method of CoinPackedMatrix for flexibility. Feel free to 
add to CoinUtils. Someone else might also find this useful.


Here is a sample usage:

----------------------------------------------------------------------------
  si->getMatrixByRow()->writeINE("p0033.ine",
                                  si->getRowSense(),
                                  si->getRightHandSide(),
                                  si->getColLower(),
                                  si->getColUpper(),
                                  si->getInfinity());


Here is the code - I have only done very basic testing:

----------------------------------------------------------------------------
void CoinPackedMatrix::writeINE(const char   * filename,
                                const char   * sense,
                                const double * rowRhs,
                                const double * colLB,
                                const double * colUB,
                                const double   infinity) const {

 
  std::ofstream os(filename);
  assert(os);
 
  assert(!isColOrdered());
 
  //assumption: all integer variables
  //format    : b - Ax >= 0

  int i, c, r;
  const int    * ind   = getIndices();
  const int    * beg   = getVectorStarts();
  const double * els   = getElements(); 
  const int      ncols = getNumCols();
  const int      nrows = getNumRows();

  double * denseRow = (double*) calloc(ncols, sizeof(double));
  assert(denseRow);

  //count number of rows (double count E, include column bounds)
  int n_rowCount = 0;
  for(r = 0; r < nrows; r++){
    switch(sense[r]){
    case 'L':
    case 'G':
      n_rowCount++;
      break;
    case 'E':
      n_rowCount+=2;
      break;
    default:
      assert(0);
    }
  }
  for(i = 0; i < ncols; i++){
    if(colLB[i] > -infinity)
      n_rowCount++;
    if(colUB[i] < infinity)
      n_rowCount++;
  }

  //header
  os << "\nH-representation"
     << "\nbegin"
     << "\n" << n_rowCount << " " << ncols+1 << " integer";

  //rows
  for(r = 0; r < nrows; r++){
    switch(sense[r]){
    case 'L':
      //Ax <= b => b - Ax >= 0
      os << "\n" << rowRhs[r] << " ";
      for(i = beg[r]; i < beg[r+1]; i++){
        denseRow[ind[i]] = -els[i];
      }
      break;
    case 'G':
      //Ax >= b => -b + Ax >= 0
      os << "\n" << -rowRhs[r] << " ";
      for(i = beg[r]; i < beg[r+1]; i++){
        denseRow[ind[i]] = els[i];
      }
      break;
    case 'E':
      //Ax <= b => b - Ax >= 0
      os << "\n" << rowRhs[r] << " ";
      for(i = beg[r]; i < beg[r+1]; i++){
        denseRow[ind[i]] = -els[i];
      }     
      //Ax >= b => -b + Ax >= 0
      os << "\n" << -rowRhs[r] << " ";
      for(i = beg[r]; i < beg[r+1]; i++){
        denseRow[ind[i]] = els[i];
      }
      break;
    default:
      assert(0);
    }
   
    for(i = 0; i < ncols; i++)
      os << denseRow[i] << " ";
   
    //refresh
    for(i = beg[r]; i < beg[r+1]; i++){
      denseRow[ind[i]] = 0.0;
    }
  }

  //column bounds
  for(c = 0; c < ncols; c++){
    //x >= b => -b + x >= 0
    if(colLB[c] > -infinity){
      os << "\n" << -colLB[c] << " ";
      denseRow[c] = 1.0;
      for(i = 0; i < ncols; i++)
        os << denseRow[i] << " ";
    }
    denseRow[c] = 0.0;

    //x <= b => b - x >= 0
    if(colUB[c] < infinity){
      os << "\n" << colUB[c] << " ";
      denseRow[c] = -1.0;
      for(i = 0; i < ncols; i++)
        os << denseRow[i] << " ";     
    }
    denseRow[c] = 0.0;   
  } 
  os << "\nend";
  os.close();

  free(denseRow);
}


Cheers,
Matt Galati


----------------------------------------------------------------------------
Mon Mar 17 07:36:41 EST 2003

Hi Coin,

Has anyone tried writing an OSI interface to any available code for
analyzing polyhdera - PORTA, for example? Just wondering if there would
be any interest in this or if there is already work in progress. I was
planning on writing a very simple interface.

Thanks,
Matt





More information about the Coin-discuss mailing list