Changeset 2061 for trunk/Clp/src


Ignore:
Timestamp:
Sep 8, 2014 5:21:22 AM (5 years ago)
Author:
forrest
Message:

allow for SOS in lp files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Clp/src/OsiClp/OsiClpSolverInterface.cpp

    r2048 r2061  
    50025002  }
    50035003  modelPtr_->copyNames(rowNames,columnNames);
     5004  if (m.numberSets()) {
     5005    // SOS
     5006    numberSOS_=m.numberSets();
     5007    setInfo_ = new CoinSet[numberSOS_];
     5008    CoinSet ** sets = m.setInformation();
     5009    for (int i=0;i<numberSOS_;i++)
     5010      setInfo_[i]=*sets[i];
     5011  }
    50045012  return(0);
    50055013}
     
    50085016   maximization objective and +1.0 to write a minimization one.
    50095017   If 0.0 then solver can do what it wants.
    5010    This version calls writeLpNative with names */
     5018    */
    50115019void
    50125020OsiClpSolverInterface::writeLp(const char *filename,
     
    50275035    fullname = f;
    50285036  }
    5029   // get names
    5030   const char * const * const rowNames = modelPtr_->rowNamesAsChar();
    5031   const char * const * const columnNames = modelPtr_->columnNamesAsChar();
    5032   // Fall back on Osi version - possibly with names
    5033   OsiSolverInterface::writeLpNative(fullname.c_str(),
    5034                                     rowNames,columnNames, epsilon, numberAcross,
    5035                                     decimals, objSense,changeNameOnRange);
    5036   if (rowNames) {
    5037     modelPtr_->deleteNamesAsChar(rowNames, modelPtr_->numberRows_+1);
    5038     modelPtr_->deleteNamesAsChar(columnNames, modelPtr_->numberColumns_);
    5039   }
     5037  FILE *fp = NULL;
     5038  fp = fopen(fullname.c_str(),"w");
     5039  if (!fp) {
     5040    printf("### ERROR: in OsiSolverInterface::writeLpNative(): unable to open file %s\n",
     5041           fullname.c_str());
     5042    exit(1);
     5043  }
     5044  writeLp(fp, epsilon, numberAcross,
     5045          decimals, objSense,changeNameOnRange);
    50405046}
    50415047void
     
    50505056  const char * const * const rowNames = modelPtr_->rowNamesAsChar();
    50515057  const char * const * const columnNames = modelPtr_->columnNamesAsChar();
    5052   // Fall back on Osi version - possibly with names
    5053   OsiSolverInterface::writeLpNative(fp,
    5054                                     rowNames,columnNames, epsilon, numberAcross,
    5055                                     decimals, objSense,changeNameOnRange);
     5058  if (!numberSOS_) {
     5059    // Fall back on Osi version - possibly with names
     5060    OsiSolverInterface::writeLpNative(fp,
     5061                                      rowNames,columnNames, epsilon, numberAcross,
     5062                                      decimals, objSense,changeNameOnRange);
     5063  } else {
     5064    // need own version
     5065   const int numcols = getNumCols();
     5066   char *integrality = new char[numcols];
     5067   bool hasInteger = false;
     5068
     5069   for (int i=0; i<numcols; i++) {
     5070     if (isInteger(i)) {
     5071       integrality[i] = 1;
     5072       hasInteger = true;
     5073     } else {
     5074       integrality[i] = 0;
     5075     }
     5076   }
     5077
     5078   // Get multiplier for objective function - default 1.0
     5079   double *objective = new double[numcols];
     5080   const double *curr_obj = getObjCoefficients();
     5081
     5082   //if(getObjSense() * objSense < 0.0) {
     5083   double locObjSense = (objSense == 0 ? 1 : objSense);
     5084   if(getObjSense() * locObjSense < 0.0) {
     5085     for (int i=0; i<numcols; i++) {
     5086       objective[i] = - curr_obj[i];
     5087     }
     5088   }
     5089   else {
     5090     for (int i=0; i<numcols; i++) {
     5091       objective[i] = curr_obj[i];
     5092     }
     5093   }
     5094
     5095   CoinLpIO writer;
     5096   writer.setInfinity(getInfinity());
     5097   writer.setEpsilon(epsilon);
     5098   writer.setNumberAcross(numberAcross);
     5099   writer.setDecimals(decimals);
     5100
     5101   writer.setLpDataWithoutRowAndColNames(*getMatrixByRow(),
     5102                     getColLower(), getColUpper(),
     5103                     objective, hasInteger ? integrality : 0,
     5104                     getRowLower(), getRowUpper());
     5105
     5106   writer.setLpDataRowAndColNames(rowNames, columnNames);
     5107
     5108   //writer.print();
     5109   delete [] objective;
     5110   delete[] integrality;
     5111   // do SOS
     5112   writer.loadSOS(numberSOS_,setInfo_);
     5113   writer.writeLp(fp, epsilon, numberAcross, decimals,
     5114                         changeNameOnRange);
     5115  }
    50565116  if (rowNames) {
    50575117    modelPtr_->deleteNamesAsChar(rowNames, modelPtr_->numberRows_+1);
Note: See TracChangeset for help on using the changeset viewer.