コード例 #1
0
ファイル: fixcand.cpp プロジェクト: lncosie/ogdf
void FixCand::fixByRedCost(CutBuffer<Variable, Constraint> *addVarBuffer)
{
	if (candidates_ == nullptr) return;

	Logger::ilout(Logger::LL_MINOR) << endl << "Fixing Variables by Reduced Costs:     ";

	const int nCandidates = candidates_->size();

	ArrayBuffer<int> fixed(nCandidates,false);  // fixed variables
	Variable    *v;                                // variable being fi0xed

	for (int i = 0; i < nCandidates; i++)
		if ((master_->optSense()->max() &&
			((*lhs_)[i] + master_->eps() < master_->primalBound())) ||
			(master_->optSense()->min() &&
			((*lhs_)[i] - master_->eps() > master_->primalBound())))
		{
			v = (Variable *) (*candidates_)[i]->conVar();
			if (v) {
				if (!v->fsVarStat()->fixed())
					master_->newFixed(1);
				v->fsVarStat()->status((*fsVarStat_)[i]);

				// should a fixed inactive variable be activated?
				/* If an inactive variable is fixed to a value different from 0, then
				*  we activate it.
				*/
				if (!v->active()) {
					switch (v->fsVarStat()->status()) {
					case FSVarStat::FixedToLowerBound:
						if (fabs(v->lBound()) > master_->eps())
							addVarBuffer->insert((*candidates_)[i]->slot(), true);
						break;

					case FSVarStat::FixedToUpperBound:
						if (fabs(v->uBound()) > master_->eps())
							addVarBuffer->insert((*candidates_)[i]->slot(), true);
						break;

					case FSVarStat::Fixed:
						if (fabs(v->fsVarStat()->value()) > master_->eps())
							addVarBuffer->insert((*candidates_)[i]->slot(), true);
						break;

					default:
						Logger::ifout() << "FixCand::fixByRedCost(): activated variable not fixed\n";
						OGDF_THROW_PARAM(AlgorithmFailureException, ogdf::afcFixCand);
					}
				}

				fixed.push(i);
			}
		}
		// remove fixed candidates
		/* We delete allocated memory of \a fsVarStat_ for the fixed variables
		*  und remove the fixed variables from the three buffers.
		*/
		const int nFixed = fixed.size();

		for (int i = 0; i < nFixed; i++) {
			delete (*candidates_)[fixed[i]];
			delete (*fsVarStat_)[fixed[i]];
		}

		candidates_->leftShift(fixed);
		fsVarStat_->leftShift(fixed);
		lhs_->leftShift(fixed);

		Logger::ilout(Logger::LL_MINOR) << "\t" << fixed.size() << " variables fixed" << endl;

}