当前位置: 首页>>代码示例>>C++>>正文


C++ CoinPackedMatrix::verifyMtx方法代码示例

本文整理汇总了C++中CoinPackedMatrix::verifyMtx方法的典型用法代码示例。如果您正苦于以下问题:C++ CoinPackedMatrix::verifyMtx方法的具体用法?C++ CoinPackedMatrix::verifyMtx怎么用?C++ CoinPackedMatrix::verifyMtx使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CoinPackedMatrix的用法示例。


在下文中一共展示了CoinPackedMatrix::verifyMtx方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CoinPackedMatrix

CbcLagrangeSolver::CbcLagrangeSolver(stochasticInput &input, int scenarioNumber, const vector<double> &lagrangeDiff) {

	absgap = ratio = 0.;
	nvar1 = input.nFirstStageVars();
	int nvar2 = input.nSecondStageVars(scenarioNumber);
	int ncons1 = input.nFirstStageCons();
	int ncons2 = input.nSecondStageCons(scenarioNumber);

	const CoinPackedMatrix &Amat = input.getFirstStageConstraints(),
		&Tmat = input.getLinkingConstraints(scenarioNumber),
		&Wmat = input.getSecondStageConstraints(scenarioNumber);
	
	
	int totalVar = nvar1 + nvar2;
	int totalCons = ncons1 + ncons2;

	CoinBigIndex totalNnz = Amat.getNumElements() + Tmat.getNumElements() + Wmat.getNumElements();

	// CoinPackedMatrix takes ownership of these, so we don't free them
	CoinBigIndex *starts = new CoinBigIndex[totalVar+1];
	double *elts = new double[totalNnz];
	int *rowIdx = new int[totalNnz];
	
	CoinBigIndex nnz = 0, start, end;
	// put first-stage variables first, as is customary
	int const *Aidx = Amat.getIndices();
	double const *Aelts = Amat.getElements();
	int const *Tidx = Tmat.getIndices();
	double const *Telts = Tmat.getElements();

	for (int c = 0; c < nvar1; c++) {
		starts[c] = nnz;
		start = Amat.getVectorFirst(c);
		end = Amat.getVectorLast(c);
		for (CoinBigIndex j = start; j < end; j++) {
			elts[nnz] = Aelts[j];
			rowIdx[nnz++] = Aidx[j];
		}
		start = Tmat.getVectorFirst(c);
		end = Tmat.getVectorLast(c);
		for (CoinBigIndex j = start; j < end; j++) {
			elts[nnz] = Telts[j];
			rowIdx[nnz++] = Tidx[j]+ncons1;
		}
	
	}

	// now W blocks
	int rowOffset = ncons1;
	int colOffset = nvar1;
	int const *Widx = Wmat.getIndices();
	double const *Welts = Wmat.getElements();

	for (int c = 0; c < nvar2; c++) {
		starts[colOffset++] = nnz;
		start = Wmat.getVectorFirst(c);
		end = Wmat.getVectorLast(c);
		for (CoinBigIndex j = start; j < end; j++) {
			elts[nnz] = Welts[j];
			rowIdx[nnz++] = Widx[j]+rowOffset;
		}
	}
	starts[totalVar] = nnz;
	assert(nnz == totalNnz);

	CoinPackedMatrix *constr = new CoinPackedMatrix();
	int *lens = 0;
	constr->assignMatrix(true,totalCons,totalVar,totalNnz,elts,rowIdx,starts,lens);
	constr->verifyMtx(); // debugging

	// OsiClpSolverInterface takes ownership of these
	double *collb = new double[totalVar];
	double *colub = new double[totalVar];
	double *obj = new double[totalVar];
	double *rowlb = new double[totalCons];
	double *rowub = new double[totalCons];

	concatenateOne(input, collb, &stochasticInput::getFirstStageColLB,
			&stochasticInput::getSecondStageColLB, scenarioNumber);
	
	concatenateOne(input, colub, &stochasticInput::getFirstStageColUB,
			&stochasticInput::getSecondStageColUB, scenarioNumber);

	concatenateOne(input, obj, &stochasticInput::getFirstStageObj,
			&stochasticInput::getSecondStageObj, scenarioNumber);
	
	concatenateOne(input, rowlb, &stochasticInput::getFirstStageRowLB,
			&stochasticInput::getSecondStageRowLB, scenarioNumber);

	concatenateOne(input, rowub, &stochasticInput::getFirstStageRowUB,
			&stochasticInput::getSecondStageRowUB, scenarioNumber);

	// rescale first-stage objective
	double scale = input.scenarioProbability(scenarioNumber);
	assert(lagrangeDiff.size() == static_cast<unsigned>(nvar1));
	for (int i = 0; i < nvar1; i++) {
		obj[i] = scale*obj[i] + lagrangeDiff[i];
	}

	m.assignProblem(constr, collb, colub, obj, rowlb, rowub);
//.........这里部分代码省略.........
开发者ID:fqiang,项目名称:PIPS,代码行数:101,代码来源:CbcLagrangeSolver.cpp


注:本文中的CoinPackedMatrix::verifyMtx方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。