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


C++ CVariable::sameVarPrevEqu方法代码示例

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


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

示例1: excludeVariables

int CEquSystem::excludeVariables(CVariableMapping *pVarValue, int adj, bool exclude, size_t numVar, const CEquArray *pEquations, bool addToAllEquation)
{
	// the return value is the number of added mappings 
	auto iMax = equNumb();
	if (!iMax)
		return 0;   // Empty system of equations

	size_t idx;

	// The number of variables in the main loop we need to process, BEFORE we will need to go to the next pEquUsed 
	// (Will be used only when pEquations != NULL)
	size_t nVarToProcess = 0;

	// Iterating in different orders over the elements from pVarValue
	int step = -2;
	int jTo = 0;
	int jFrom = pVarValue->nElement() << 1;

	CEquation *pEquUsed = NULL;
	if (!exclude) {
		if (pEquations) {
			pEquUsed = pEquations->GetAt(idx = pEquations->GetSize() - 1);
			nVarToProcess = pEquUsed->numDefinedVar();
		}
	} 
	else {
		equArray()->RemoveAll(); // reset the array of used equations
		pVarValue->setMapBoundaries(numVar ? numVar : pVarValue->nElement());
	}

	const bool setDefFlag = adj > 0;
	bool addVariable = false;
	int varDefined = exclude ? 1 : 0;
	int nAddedVarTotal = 0;
	auto pMapping = pVarValue->getMappingPntr();
	bool checkFlg = false;
	int retVal;
	size_t i = 0;
/*
	if (exclude)
	{
		step = -2;
		jTo = 0;
		jFrom = pVarValue->nElement() << 1;
	} else {
		step = 2;
		jTo = (pVarValue->nElement() << 1) - 2;
		jFrom = numVar? jTo - (numVar << 1) : -2;
	}
*/
	bool reOrderMapping = false;

	for (int j = jFrom; j != jTo && (!numVar || i < numVar); i++) {
		j += step;
		const auto varIdx = *(pMapping + j);
		CVariable *pVar = variable(varIdx);
		if (!pVar)
			continue;		// Variable is not in the system
		
		if (setDefFlag)		// we are here to exclude variables and not just to adjust right parts
			setVarDefined(varIdx, varDefined);	// Mark the variable as defined

		// Value of variable - varMin:
		const auto varVal = *(pMapping + j + 1);

		// For all equations, containing pVar variable
		auto pVarCurr = pVar;
		do {
			CEquation *pEquCurr = equation(pVarCurr);
			CVariable *pRemovedVar = NULL;
			if (exclude) {
				if (!pEquCurr->solved()) {
					const size_t nTotal = pVarValue->nElement();
					printAddEquationVariable(pEquCurr, varIdx, varVal, false);
					/*const auto */retVal = pEquCurr->removeVariable(varVal, varDefinedPtr(), pVarValue, getDefEquationPntr(), adj);
					if (retVal == -2) {
						// Some equation could not be solved
						if (nAddedVarTotal) {
							// Some variables got their values here
							// We need to add these variables to the equations from which their values were defined
							excludeVariables(pVarValue, 1, false, nAddedVarTotal, equArray());
							pVarValue->removeLastMapping(nAddedVarTotal);
						}

						// We need to run this loop over the equations for current varIdx 
						// and add this variable to all equations where it was just removed
						// Define the boundaries for the loop:
						auto *pTmp = pVar->sameVarPrevEqu();
						pVar = pVarCurr;
						pVarCurr = pTmp;
						exclude = false;
						addVariable = true;
					} else
					if (retVal >= 0) {
						const size_t nAddedVar = pVarValue->nElement() - nTotal;
						if (nAddedVar) {
							nAddedVarTotal += nAddedVar;
							equArray()->Add(pEquCurr);
						}
					}
//.........这里部分代码省略.........
开发者ID:andrei5055,项目名称:Incidence-System-Enumeration,代码行数:101,代码来源:EquSystem.cpp


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