コード例 #1
0
ファイル: osiif.cpp プロジェクト: lncosie/ogdf
void OsiIF::loadDummyRow(OsiSolverInterface* s2, const double* lbounds, const double* ubounds, const double* objectives)
{
	CoinPackedVector *coinrow = new CoinPackedVector();
	CoinPackedMatrix *matrix =  new CoinPackedMatrix(false,0,0);
	matrix->setDimensions(0, numCols_);
	ArrayBuffer<int> dummy(1,false);
	dummy.push(0);
	char *senses = new char[1];
	double *rhs = new double[1];
	double *ranges = new double[1];
	coinrow->insert(0, 1.);
	matrix->appendRow(*coinrow);
	senses[0] = 'E';
	rhs[0] = 1.;
	ranges[0] = 0.;

	lpSolverTime_.start();
	s2->loadProblem(*matrix, lbounds, ubounds, objectives, senses, rhs, ranges);
	lpSolverTime_.stop();
	_remRows(dummy);

	delete coinrow;
	delete matrix;
	freeChar(senses);
	freeDouble(rhs);
	freeDouble(ranges);

	return;
}
コード例 #2
0
ファイル: osiif.cpp プロジェクト: lncosie/ogdf
OsiIF::~OsiIF()
{
	delete ws_;
	delete osiLP_;

	freeDouble(xVal_);
	freeDouble(yVal_);
	freeDouble(reco_);
	freeDouble(rowactivity_);
	freeChar(cStat_);
	freeChar(rStat_);
}
コード例 #3
0
ファイル: osiif.cpp プロジェクト: lncosie/ogdf
void OsiIF::_addCols(ArrayBuffer<Column*> &newCols)
{
	CoinPackedVector *newcol = new CoinPackedVector;

	for (int i = 0; i < newCols.size(); i++) {
		int num = newCols[i]->nnz();
		double ub =  newCols[i]->uBound();
		double lb =  newCols[i]->lBound();
		double obj =  newCols[i]->obj();
		int *supports = new int[num]; //!< supports of added rows
		double  *coeffs = new double[num]; //!< coefficients of added rows

		for (int j = 0; j < num; j++) {
			supports[j] = newCols[i]->support(j);
			coeffs[j] = newCols[i]->coeff(j);
		}

		newcol->setVector(num, supports, coeffs);
		lpSolverTime_.start();
		osiLP_->addCol(*newcol, lb, ub, obj);
		lpSolverTime_.stop();

		freeInt(supports);
		freeDouble(coeffs);
	}

	lpSolverTime_.start();
	numCols_ = osiLP_->getNumCols();
	collower_ = osiLP_->getColLower();
	colupper_ = osiLP_->getColUpper();
	objcoeff_ = osiLP_->getObjCoefficients();
	lpSolverTime_.stop();
	delete newcol;
}
コード例 #4
0
ファイル: flotarry.C プロジェクト: JimBrouzoulis/oofem-1
void FloatArray :: hardResize(int n)
// Reallocates the receiver with new size.
{
    int i;
    double *newValues, *p1, *p2;

    // if (n <= allocatedSize) {size = n; return;}

    newValues = allocDouble(n);
#ifdef DEBUG
    if ( !newValues ) {
        OOFEM_FATAL2("FloatArray :: hardResize - Failed in allocating %d doubles", n);
    }

#endif
    p1 = values;
    p2 = newValues;
    i  = min(size, n);
    while ( i-- ) {
        * p2++ = * p1++;
    }

    if ( values ) {
        freeDouble(values);
    }

    values = newValues;
    allocatedSize = size = n;
}
コード例 #5
0
ファイル: skyline.C プロジェクト: MartinFagerstrom/oofem
Skyline :: ~Skyline()
{
    // Destructor.
    if ( this->giveNumberOfRows() ) {
        freeDouble(mtrx);
        delete(adr);
    }
}
コード例 #6
0
RubberBandStretcher::Impl::ChannelData::~ChannelData()
{
    delete resampler;

    freeFloat(resamplebuf);

    delete inbuf;
    delete outbuf;

    freeDouble(mag);
    freeDouble(phase);
    freeDouble(prevPhase);
    freeDouble(prevError);
    freeDouble(unwrappedPhase);
    freeDouble(envelope);
    delete[] freqPeak;
    freeFloat(accumulator);
    freeFloat(windowAccumulator);
    freeFloat(fltbuf);

    for (std::map<size_t, FFT *>::iterator i = ffts.begin();
         i != ffts.end(); ++i) {
        delete i->second;
    }
}
コード例 #7
0
ファイル: skyline.C プロジェクト: MartinFagerstrom/oofem
int Skyline :: setInternalStructure(IntArray *a)
{
    // allocates and built structure according to given
    // array of maximal column heights
    //
    adr = new IntArray(*a);
    int n = a->giveSize();
    nwk = adr->at(n); // check
    if ( mtrx ) {
        freeDouble(mtrx);
    }

    mtrx = allocDouble(nwk);
    nRows = nColumns = n - 1;

    // increment version
    this->version++;
    return true;
}
コード例 #8
0
ファイル: flotarry.C プロジェクト: JimBrouzoulis/oofem-1
void FloatArray :: resize(int n, int allocChunk)
{
    int i;
    double *newValues, *p1, *p2;

#ifdef DEBUG
    if ( allocChunk < 0 ) {
        OOFEM_FATAL2("FloatArray :: resize - allocChunk must be non-negative; %d", allocChunk);
    }

#endif

    if ( n <= allocatedSize ) {
        size = n;
        return;
    }

    newValues = allocDouble(n + allocChunk);
#ifdef DEBUG
    if ( !newValues ) {
        OOFEM_FATAL2("FloatArray :: resize - Failed in allocating %d doubles", n + allocChunk);
    }

#endif
    p1 = values;
    p2 = newValues;
    i  = size;
    while ( i-- ) {
        * p2++ = * p1++;
    }

    if ( values ) {
        freeDouble(values);
    }

    values = newValues;
    allocatedSize = n + allocChunk;
    size = n;
}
コード例 #9
0
ファイル: flotarry.C プロジェクト: JimBrouzoulis/oofem-1
contextIOResultType FloatArray :: restoreYourself(DataStream *stream, ContextMode mode)
// reads receiver from stream
// warning - overwrites existing data!
// returns 0 if file i/o error
//        -1 if id od class id is not correct
{
    // read size
    if ( !stream->read(& size, 1) ) {
        return CIO_IOERR;
    }

    if ( size > allocatedSize ) {
        if ( values != NULL ) {
            freeDouble(values);
        }

        values = allocDouble(size);
#ifdef DEBUG
        if ( !values ) {
            OOFEM_FATAL2("FloatArray :: restoreYourself - Failed in allocating %d doubles", size);
        }

#endif
        allocatedSize = size;
    }

    // read raw data
    if ( size ) {
        if ( !stream->read(values, size) ) {
            return CIO_IOERR;
        }
    }

    // return result back
    return CIO_OK;
}
コード例 #10
0
ファイル: skyline.C プロジェクト: MartinFagerstrom/oofem
int Skyline :: buildInternalStructure(EngngModel *eModel, int di, EquationID ut, const UnknownNumberingScheme &s)
{
    // first create array of
    // maximal column height for assembled characteristics matrix
    //

    int j, js, ieq, maxle;
    int i, ac1;
    int neq;
    if ( s.isDefault() ) {
        neq = eModel->giveNumberOfDomainEquations(di, ut);
    } else {
        neq = s.giveRequiredNumberOfDomainEquation();
        if ( neq == 0 ) {
            OOFEM_ERROR("Undefined Required number of domain equations");
        }
    }

    IntArray loc;
    IntArray *mht = new IntArray(neq);
    Domain *domain = eModel->giveDomain(di);

    for ( j = 1; j <= neq; j++ ) {
        mht->at(j) = j; // initialize column height, maximum is line number (since it only stores upper triangular)
    }

    int nelem = domain->giveNumberOfElements();

    // loop over elements code numbers
    for ( i = 1; i <= nelem; i++ ) {
        domain->giveElement(i)->giveLocationArray(loc, ut, s);
        js = loc.giveSize();
        maxle = INT_MAX;
        for ( j = 1; j <= js; j++ ) {
            ieq = loc.at(j);
            if ( ieq != 0 ) {
                maxle = min(maxle, ieq);
            }
        }

        for ( j = 1; j <= js; j++ ) {
            ieq = loc.at(j);
            if ( ieq != 0 ) {
                mht->at(ieq) = min( maxle, mht->at(ieq) );
            }
        }
    }

    // NOTE
    // add there call to eModel if any possible additional equation added by
    // eModel
    // currently not supported

    // increases number of columns according to size of mht
    // mht is array containing minimal equation number per column
    // This method also increases column height.


    if ( this->adr ) {
        delete adr;
    }

    adr = new IntArray(neq + 1);

    ac1 = 1;
    for ( i = 1; i <= neq; i++ ) {
        adr->at(i) = ac1;
        ac1 += ( i - mht->at(i) + 1 );
    }

    adr->at(neq + 1) = ac1;
    nRows = nColumns = neq;
    nwk  = ac1;
    if ( mtrx ) {
        freeDouble(mtrx);
    }

    mtrx = allocDouble(ac1);

    delete mht;

    // increment version
    this->version++;
    return true;
}
コード例 #11
0
ファイル: osiif.cpp プロジェクト: lncosie/ogdf
void OsiIF::_initialize(
	OptSense sense,
	int nRow,
	int maxRow,
	int nCol,
	int maxCol,
	Array<double> &obj,
	Array<double> &lBound,
	Array<double> &uBound,
	Array<Row*> &rows)
{
	osiLP_ = getDefaultInterface();
	currentSolverType_ = Exact;

	// switch off output from the solver
	// can be reset in setSolverParameters
	osiLP_->setHintParam(OsiDoReducePrint, true, OsiHintDo);
	osiLP_->messageHandler()->setLogLevel(0);
	master_->setSolverParameters(osiLP_, currentSolverType() == Approx);

	numRows_ = nRow;
	numCols_ = nCol;
	double *lbounds = new double[numCols_];
	double *ubounds = new double[numCols_];
	double *objectives = new double[numCols_];

	CoinPackedVector *coinrow = new CoinPackedVector();
	CoinPackedMatrix *matrix =  new CoinPackedMatrix(false,0,0);
	matrix->setDimensions(0, numCols_);

	for (int i = 0; i < numCols_; i++){
		lbounds[i] = lBound[i];
		ubounds[i] = uBound[i];
		objectives[i] = obj[i];
	}

	if (currentSolverType() == Exact && numRows_ == 0 && master_->defaultLpSolver() == Master::CPLEX) {
		loadDummyRow(osiLP_, lbounds, ubounds, objectives);
	}
	else {
		char *senses = new char[numRows_];
		double *rhs = new double[numRows_];
		double *ranges = new double[numRows_];

		for (int i = 0; i < numRows_; i++){
			coinrow->clear();
			for (int j = 0; j < rows[i]->nnz(); j++){
				coinrow->insert(rows[i]->support(j), rows[i]->coeff(j));
			}
			matrix->appendRow(*coinrow);
			senses[i] = csense2osi(rows[i]->sense());
			rhs[i] = rows[i]->rhs();
			ranges[i] = 0.0;
		}
		lpSolverTime_.start();
		osiLP_->loadProblem(*matrix, lbounds, ubounds, objectives, senses, rhs, ranges);
		lpSolverTime_.stop();

		freeChar(senses);
		freeDouble(rhs);
		freeDouble(ranges);
	}

	// set the sense of the optimization
	_sense(sense);

	// get the pointers to the solution, reduced costs etc.
	lpSolverTime_.start();
	numRows_ = osiLP_->getNumRows();
	numCols_ = osiLP_->getNumCols();
	rhs_ = osiLP_->getRightHandSide();
	rowsense_ = osiLP_->getRowSense();
	colupper_ = osiLP_->getColUpper();
	collower_ = osiLP_->getColLower();
	objcoeff_ = osiLP_->getObjCoefficients();
	if( ws_ != nullptr )
		delete ws_;
	//ws_ = dynamic_cast<CoinWarmStartBasis *>(osiLP_->getWarmStart());
	ws_=nullptr;

	xValStatus_ = recoStatus_ = yValStatus_ = slackStatus_ = basisStatus_ = Missing;
	lpSolverTime_.stop();

	delete coinrow;
	delete matrix;
	freeDouble(lbounds);
	freeDouble(ubounds);
	freeDouble(objectives);
}
コード例 #12
0
ファイル: flotarry.C プロジェクト: JimBrouzoulis/oofem-1
FloatArray :: ~FloatArray()
{
    if ( values ) {
        freeDouble(values);
    }
}