std::set<int> *
CoinPackedVectorBase::indexSet(const char* methodName,
			      const char * className) const
{
   testedDuplicateIndex_ = true;
   if ( indexSetPtr_ == NULL ) {
      // create a set of the indices
      indexSetPtr_ = new std::set<int>;
      const int s = getNumElements();
      const int * inds = getIndices();
      for (int j=0; j < s; ++j) {
	 if (!indexSetPtr_->insert(inds[j]).second) {
	    testedDuplicateIndex_ = false;
	    delete indexSetPtr_;
	    indexSetPtr_ = NULL;
	    if (methodName != NULL) {
	       throw CoinError("Duplicate index found", methodName, className);
	    } else {
	       throw CoinError("Duplicate index found",
			      "indexSet", "CoinPackedVectorBase");
	    }
	 }
      }
   }
   return indexSetPtr_;
}
Пример #2
0
void
CoinPackedVector::truncate( int n )
{
   if ( n > nElements_ ) 
      throw CoinError("n > size()","truncate","CoinPackedVector");
   if ( n < 0 ) 
      throw CoinError("n < 0","truncate","CoinPackedVector");
   nElements_ = n;
   clearBase();
}
Пример #3
0
/** This helper function copies an array to another location. The two arrays
	must not overlap (otherwise an exception is thrown). For speed 8 entries
	are copied at a time. The arrays are given by pointers to their first
	entries and by the size of the source array.

	Note JJF - the speed claim seems to be false on IA32 so I have added
	CoinMemcpyN which can be used for atomic data */
template <class T> inline void
CoinDisjointCopyN(register const T* from, const int size, register T* to)
{
#ifndef _MSC_VER
    if (size == 0 || from == to)
        return;

#ifndef NDEBUG
    if (size < 0)
        throw CoinError("trying to copy negative number of entries",
                        "CoinDisjointCopyN", "");
#endif

#if 0
    /* There is no point to do this test. If to and from are from different
       blocks then dist is undefined, so this can crash correct code. It's
       better to trust the user that the arrays are really disjoint. */
    const long dist = to - from;
    if (-size < dist && dist < size)
        throw CoinError("overlapping arrays", "CoinDisjointCopyN", "");
#endif

    for (register int n = size / 8; n > 0; --n, from += 8, to += 8) {
        to[0] = from[0];
        to[1] = from[1];
        to[2] = from[2];
        to[3] = from[3];
        to[4] = from[4];
        to[5] = from[5];
        to[6] = from[6];
        to[7] = from[7];
    }
    switch (size % 8) {
    case 7:
        to[6] = from[6];
    case 6:
        to[5] = from[5];
    case 5:
        to[4] = from[4];
    case 4:
        to[3] = from[3];
    case 3:
        to[2] = from[2];
    case 2:
        to[1] = from[1];
    case 1:
        to[0] = from[0];
    case 0:
        break;
    }
#else
    CoinCopyN(from, size, to);
#endif
}
Пример #4
0
void
CoinIndexedVector::setElement(int index, double element)
{
#ifndef COIN_FAST_CODE
    if ( index >= nElements_ )
        throw CoinError("index >= size()", "setElement", "CoinIndexedVector");
    if ( index < 0 )
        throw CoinError("index < 0" , "setElement", "CoinIndexedVector");
#endif
    elements_[indices_[index]] = element;
}
Пример #5
0
/** Access the i'th element of the full storage vector.  */
double &
CoinIndexedVector::operator[](int index) const
{
    assert (!packedMode_);
#ifndef COIN_FAST_CODE
    if ( index >= capacity_ )
        throw CoinError("index >= capacity()", "[]", "CoinIndexedVector");
    if ( index < 0 )
        throw CoinError("index < 0" , "[]", "CoinIndexedVector");
#endif
    double * where = elements_ + index;
    return *where;

}
Пример #6
0
void
CoinIndexedVector::append(const CoinPackedVectorBase & caboose)
{
    const int cs = caboose.getNumElements();

    const int * cind = caboose.getIndices();
    const double * celem = caboose.getElements();
    int maxIndex=-1;
    int i;
    for (i=0; i<cs; i++) {
        int indexValue = cind[i];
        if (indexValue<0)
            throw CoinError("negative index", "append", "CoinIndexedVector");
        if (maxIndex<indexValue)
            maxIndex = indexValue;
    }
    reserve(maxIndex+1);
    bool needClean=false;
    int numberDuplicates=0;
    for (i=0; i<cs; i++) {
        int indexValue=cind[i];
        if (elements_[indexValue]) {
            numberDuplicates++;
            elements_[indexValue] += celem[i] ;
            if (fabs(elements_[indexValue])<COIN_INDEXED_TINY_ELEMENT)
                needClean=true; // need to go through again
        } else {
            if (fabs(celem[i])>=COIN_INDEXED_TINY_ELEMENT) {
                elements_[indexValue]=celem[i];
                indices_[nElements_++]=indexValue;
            }
        }
    }
    if (needClean) {
        // go through again
        int size=nElements_;
        nElements_=0;
        for (i=0; i<size; i++) {
            int indexValue=indices_[i];
            double value=elements_[indexValue];
            if (fabs(value)>=COIN_INDEXED_TINY_ELEMENT) {
                indices_[nElements_++]=indexValue;
            } else {
                elements_[indexValue]=0.0;
            }
        }
    }
    if (numberDuplicates)
        throw CoinError("duplicate index", "append", "CoinIndexedVector");
}
Пример #7
0
CoinFileOutput *CoinFileOutput::create (const std::string &fileName,
					Compression compression)
{
  switch (compression)
    {
    case COMPRESS_NONE:
      return new CoinPlainFileOutput (fileName);

    case COMPRESS_GZIP:
#ifdef COIN_HAS_ZLIB
      return new CoinGzipFileOutput (fileName);
#endif
      break;

    case COMPRESS_BZIP2:
#ifdef COIN_HAS_BZLIB
      return new CoinBzip2FileOutput (fileName);
#endif
      break;

    default:
      break;
    }

  throw CoinError ("Unsupported compression selected!",
		   "create",
		   "CoinFileOutput");
}
Пример #8
0
void
CoinPackedVector::assignVector(int size, int*& inds, double*& elems,
                              bool testForDuplicateIndex)
{
  clear();
  // Allocate storage
  if ( size != 0 ) {
		  //reserve(size); //This is a BUG!!!
    nElements_ = size;
    if (indices_ != NULL) delete[] indices_;
    indices_ = inds;    inds = NULL;
    if (elements_ != NULL) delete[] elements_;
    elements_ = elems;  elems = NULL;
    if (origIndices_ != NULL) delete[] origIndices_;
    origIndices_ = new int[size];
    CoinIotaN(origIndices_, size, 0);
    capacity_ = size;
  }
  if (testForDuplicateIndex) {
    try {    
      CoinPackedVectorBase::setTestForDuplicateIndex(testForDuplicateIndex);
    }
    catch (CoinError e) {
    throw CoinError("duplicate index", "assignVector",
		    "CoinPackedVector");
    }
  } else {
    setTestsOff();
  }
}
Пример #9
0
void
CoinPackedVector::append(const CoinPackedVectorBase & caboose)
{
   const int cs = caboose.getNumElements();
   if (cs == 0) {
       return;
   }
   if (testForDuplicateIndex()) {
       // Just to initialize the index heap
       indexSet("append (1st call)", "CoinPackedVector");
   }
   const int s = nElements_;
   // Make sure there is enough room for the caboose
   if ( capacity_ < s + cs)
      reserve(CoinMax(s + cs, 2 * capacity_));

   const int * cind = caboose.getIndices();
   const double * celem = caboose.getElements();
   CoinDisjointCopyN(cind, cs, indices_ + s);
   CoinDisjointCopyN(celem, cs, elements_ + s);
   CoinIotaN(origIndices_ + s, cs, s);
   nElements_ += cs;
   if (testForDuplicateIndex()) {
      std::set<int>& is = *indexSet("append (2nd call)", "CoinPackedVector");
      for (int i = 0; i < cs; ++i) {
	 if (!is.insert(cind[i]).second)
	    throw CoinError("duplicate index", "append", "CoinPackedVector");
      }
   }
}
Пример #10
0
void
CoinIndexedVector::insert( int index, double element )
{
#ifndef COIN_FAST_CODE
    if ( index < 0 )
        throw CoinError("index < 0" , "setElement", "CoinIndexedVector");
#endif
    if (index >= capacity_)
        reserve(index+1);
#ifndef COIN_FAST_CODE
    if (elements_[index])
        throw CoinError("Index already exists", "insert", "CoinIndexedVector");
#endif
    indices_[nElements_++] = index;
    elements_[index] = element;
}
Пример #11
0
    /** The position of the last element (well, one entry <em>past</em> the
        last) in the i'th major-dimension vector. */
    CoinBigIndex getVectorLast(const int i) const {
#ifndef COIN_FAST_CODE
      if (i < 0 || i >= majorDim_)
	throw CoinError("bad index", "vectorLast", "CoinPackedMatrix");
#endif
      return start_[i] + length_[i];
    }
Пример #12
0
void
CoinIndexedVector::reserve(int n)
{
    int i;
    // don't make allocated space smaller but do take off values
    if ( n < capacity_ ) {
#ifndef COIN_FAST_CODE
        if (n<0)
            throw CoinError("negative capacity", "reserve", "CoinIndexedVector");
#endif
        int nNew=0;
        for (i=0; i<nElements_; i++) {
            int indexValue=indices_[i];
            if (indexValue<n) {
                indices_[nNew++]=indexValue;
            } else {
                elements_[indexValue]=0.0;
            }
        }
        nElements_=nNew;
    } else if (n>capacity_) {

        // save pointers to existing data
        int * tempIndices = indices_;
        double * tempElements = elements_;
        double * delTemp = elements_-offset_;

        // allocate new space
        int nPlus;
        if (sizeof(int)==4*sizeof(char))
            nPlus=(n+3)>>2;
        else
Пример #13
0
//===========================================================================//
CoinWarmStartBasis* UtilAlpsDecodeWarmStart(AlpsEncoded&       encoded,
      AlpsReturnStatus* rc)
{
   //rc not used? not checked?
   int numCols;
   int numRows;
   encoded.readRep(numCols);
   encoded.readRep(numRows);
   int tempInt;
   // Structural
   int nint = (numCols + 15) >> 4;
   char* structuralStatus = new char[4 * nint];
   encoded.readRep(structuralStatus, tempInt);
   assert(tempInt == nint * 4);
   // Artificial
   nint = (numRows + 15) >> 4;
   char* artificialStatus = new char[4 * nint];
   encoded.readRep(artificialStatus, tempInt);
   assert(tempInt == nint * 4);
   CoinWarmStartBasis* ws = new CoinWarmStartBasis();

   if (!ws) {
      throw CoinError("Out of memory", "UtilAlpsDecodeWarmStart", "HELP");
   }

   ws->assignBasisStatus(numCols, numRows,
                         structuralStatus, artificialStatus);
   return ws;
}
Пример #14
0
void
OaDecompositionBase::solverManip::restore()
{
  if (initialNumberRows_ >= 0) {
    int nRowsToDelete = si_->getNumRows() - initialNumberRows_;
    int * rowsToDelete = new int[nRowsToDelete];
    for (int i = 0 ; i < nRowsToDelete ; i++) {
      rowsToDelete[i] = i + initialNumberRows_;
    }
    si_->deleteRows(nRowsToDelete, rowsToDelete);
    delete [] rowsToDelete;
    numrows_ = si_->getNumRows() ;
  }

  if (colLower_) {
    si_->setColLower(colLower_);
  }

  if (colUpper_) {
    si_->setColUpper(colUpper_);
  }

  if (cutoff_<COIN_DBL_MAX) {
    si_->setDblParam(OsiDualObjectiveLimit, cutoff_);
  }

  if (warm_) {
    if (si_->setWarmStart(warm_)==false) {
      throw CoinError("Fail restoring the warm start at the end of procedure",
          "restore","OaDecompositionBase::SaveSolverState") ;
    }
  }
  getCached();
}
Пример #15
0
 /** throw if option does not exists.*/
 inline void optionExists(const std::string & option){
   if(!IsValid(GetOption(option))){
     std::string msg = "Try to access option: "+option;
     msg += "\n Option is not registered.\n";
     throw CoinError("Bonmin::RegisteredOption","optionExists",msg);
   }
 }
Пример #16
0
  void 
  RegisteredOptions::fillAmplOptionList(ExtraCategoriesInfo which, Ipopt::AmplOptionsList * amplOptList){
      std::list<int> test;
      std::list< Ipopt::RegisteredOption * > options;
      chooseOptions(which, options);
      for(std::list< Ipopt::RegisteredOption * >::iterator i = options.begin();
           i != options.end() ; i++)
       {
           std::string name = "bonmin.";
           name += (*i)->Name();
           Ipopt::RegisteredOptionType T = (*i)->Type();
           Ipopt::AmplOptionsList::AmplOptionType  type;
           switch(T){
             case Ipopt::OT_Number: type = Ipopt::AmplOptionsList::Number_Option;
                  break;
             case Ipopt::OT_Integer: type = Ipopt::AmplOptionsList::Integer_Option;
                  break;
             case Ipopt::OT_String: type = Ipopt::AmplOptionsList::String_Option;
                  break;
             case Ipopt::OT_Unknown:
             default:
                throw CoinError("RegisteredOptions","fillAmplOptionList","Unknown option type");
           }
           amplOptList->AddAmplOption(name, name, type, (*i)->ShortDescription());
       }
}
Пример #17
0
//------------------------------------------------------------------
std::vector<double*> OsiTestSolverInterface::getPrimalRays(int /*maxNumRays*/) const
{
  // *FIXME* : must write the method -LL
  throw CoinError("method is not yet written", "getPrimalRays",
		 "OsiTestSolverInterface");
  return std::vector<double*>();
}
Пример #18
0
    /** The length of i'th vector. */
    inline int getVectorSize(const int i) const {
#ifndef COIN_FAST_CODE
      if (i < 0 || i >= majorDim_)
	throw CoinError("bad index", "vectorSize", "CoinPackedMatrix");
#endif
      return length_[i];
    }
Пример #19
0
CoinFileInput *CoinFileInput::create (const std::string &fileName)
{
  // first try to open file, and read first bytes
  unsigned char header[4];
  size_t count ; // So stdin will be plain file
  if (fileName!="stdin") {
    FILE *f = fopen (fileName.c_str (), "r");

    if (f == 0)
      throw CoinError ("Could not open file for reading!",
                       "create",
                       "CoinFileInput");
    count = fread (header, 1, 4, f);
    fclose (f);
  } else {
    // Reading from stdin - for moment not compressed
    count=0 ; // So stdin will be plain file
  }
  // gzip files start with the magic numbers 0x1f 0x8b
  if (count >= 2 && header[0] == 0x1f && header[1] == 0x8b)
    {
#ifdef COIN_HAS_ZLIB
      return new CoinGzipFileInput (fileName);
#else
      throw CoinError ("Cannot read gzip'ed file because zlib was "
		       "not compiled into COIN!",
		       "create",
		       "CoinFileInput");
#endif
    }

  // bzip2 files start with the string "BZh"
  if (count >= 3 && header[0] == 'B' && header[1] == 'Z' && header[2] == 'h')
    {
#ifdef COIN_HAS_BZLIB
      return new CoinBzip2FileInput (fileName);
#else
      throw CoinError ("Cannot read bzip2'ed file because bzlib was "
		       "not compiled into COIN!",
		       "create",
		       "CoinFileInput");
#endif
    }

  // fallback: probably plain text file
  return new CoinPlainFileInput (fileName);
}
Пример #20
0
void
CoinPackedVector::swap(int i, int j)
{
   if ( i >= nElements_ ) 
      throw CoinError("index i >= size()","swap","CoinPackedVector");
   if ( i < 0 ) 
      throw CoinError("index i < 0" ,"swap","CoinPackedVector");
   if ( i >= nElements_ ) 
      throw CoinError("index j >= size()","swap","CoinPackedVector");
   if ( i < 0 ) 
      throw CoinError("index j < 0" ,"swap","CoinPackedVector");

   // Swap positions i and j of the
   // indices and elements arrays
   std::swap(indices_[i], indices_[j]);
   std::swap(elements_[i], elements_[j]);
}
Пример #21
0
  CoinGzipFileOutput (const std::string &fileName):
    CoinFileOutput (fileName), gzf_ (0)
  {
    gzf_ = gzopen (fileName.c_str (), "w");
    if (gzf_ == 0)
      throw CoinError ("Could not open file for writing!",
		       "CoinGzipFileOutput",
		       "CoinGzipFileOutput");
  }
Пример #22
0
 /// Set CRITERION_
 inline void setCRITERION_ (int criterion) {
   if ((criterion >= 1) && (criterion <= 3)) {
     CRITERION_ = criterion;
   }
   else {
     throw CoinError("Unallowable value. criterion must be 1, 2 or 3",
                     "gutsOfConstruct","CglMixedIntegerRounding");
   }
 }
Пример #23
0
 //@{
 /// Set MAXAGGR_
 inline void setMAXAGGR_ (int maxaggr) {
   if (maxaggr > 0) {
     MAXAGGR_ = maxaggr;
   }
   else {
     throw CoinError("Unallowable value. maxaggr must be > 0",
                     "gutsOfConstruct","CglMixedIntegerRounding");
   }
 }
Пример #24
0
void
OsiTestSolverInterface::checkData_() const
{
   int i;
   for (i = getNumRows() - 1; i >= 0; --i) {
      if (rowlower_[i] > -1.0e20 &&
	  rowupper_[i] < 1.0e20 &&
	  rowlower_[i] != rowupper_[i])
	 throw CoinError("Volume algorithm is unable to handle ranged rows",
			"checkData_", "OsiTestSolverInterface");
   }

   for (i = getNumCols() - 1; i >= 0; --i)  {
      if (collower_[i] < -1.0e20 || colupper_[i] > 1.0e20)
	 throw CoinError("Volume algorithm is unable to handle infinite bounds",
			"checkData_", "OsiTestSolverInterface");
   }
}
  /** Set the normalization : Either beta=+1 or beta=-1.
      Default value is 1.
  */
  void setBeta(int oneOrMinusOne){
    if (oneOrMinusOne==1 || oneOrMinusOne==-1){
      beta_= static_cast<double>(oneOrMinusOne);
    }
    else {
      throw CoinError("Unallowable value. Beta must be 1 or -1",
		      "cutGeneration","CglLiftAndProject");
    }
  }
Пример #26
0
void
OsiTestSolverInterface::setInteger(int index)
{
  assert(continuous_ != NULL);
  if (index < 0 || index > getNumCols()) {
    throw CoinError("Index out of bound.", "setContinuous",
		   "OsiTestSolverInterface");
  }
  continuous_[index] = false;
}
Пример #27
0
void
CoinIndexedVector::swap(int i, int j)
{
    if ( i >= nElements_ )
        throw CoinError("index i >= size()","swap","CoinIndexedVector");
    if ( i < 0 )
        throw CoinError("index i < 0" ,"swap","CoinIndexedVector");
    if ( j >= nElements_ )
        throw CoinError("index j >= size()","swap","CoinIndexedVector");
    if ( j < 0 )
        throw CoinError("index j < 0" ,"swap","CoinIndexedVector");

    // Swap positions i and j of the
    // indices array

    int isave = indices_[i];
    indices_[i] = indices_[j];
    indices_[j] = isave;
}
Пример #28
0
  CoinGzipFileInput (const std::string &fileName):
    CoinGetslessFileInput (fileName), gzf_ (0)
  {
    readType_="zlib";
    gzf_ = gzopen (fileName.c_str (), "r");
    if (gzf_ == 0)
      throw CoinError ("Could not open file for reading!",
		       "CoinGzipFileInput",
		       "CoinGzipFileInput");
  }
Пример #29
0
    /** Return the i'th vector in matrix. */
    const CoinShallowPackedVector getVector(int i) const {
#ifndef COIN_FAST_CODE
      if (i < 0 || i >= majorDim_)
	throw CoinError("bad index", "vector", "CoinPackedMatrix");
#endif
      return CoinShallowPackedVector(length_[i],
  				    index_ + start_[i],
  				    element_ + start_[i],
  				    false);
    }
Пример #30
0
    inline void setVlbs(const CglFlowVLB& vlb, int i) { 
	if (vlbs_ != 0) 
	    vlbs_[i] = vlb;
	else {
	    std::cout << "ERROR: Should allocate memory for vlbs_ before "
		      << "using it " << std::endl;
	    throw CoinError("Forgot to allocate memory for vlbs_", "setVlbs",
			    "CglFlowCover");
	}
    }