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


C++ CConfig::ConfigCmp方法代码示例

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


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

示例1: TryFind

// Search config in the hash table, if it is not there, this config will be 
// inserted. If inserted, *pCacheConfig will point to the location.
// return value
// 0 -- not found or can not be pruned
// 1 -- find a config that can be pruned in the cache
int TryFind(CConfig **arr, CConfig *pConfig, CConfig **pCacheConfig) 
{
	*pCacheConfig = NULL;
    //return 0;

    int index = pConfig->CalHashValue();
    CConfig *p = arr[index];

	if (!p) // the config is not found and insert this pConfig to it
	{ 
       
#ifdef USE_OWN_CACHE
        if (usedconfiglength>=MAXUSEDCONFIGSIZE) return 0;
		CConfig* pNewConfig = newCacheConfig(pConfig->len);
        if (!pNewConfig) return 0; // cache has been used up, just return;
#else
		if (usedconfiglength>=MAXUSEDCONFIGSIZE) return 0;
        CConfig* pNewConfig = new CConfig(pConfig->len);
		assert(pNewConfig);
#endif

        usedconfiglength++;
		pNewConfig->Copy(pConfig);
		arr[index] = pNewConfig;
		*pCacheConfig = pNewConfig;
		return 0;
	}

	if (p->ConfigCmp(pConfig)) return 0;
	
	// now the configs are the same
	if (p->depth <= pConfig->depth) 
	{
		// if a config hits the hash table with length no less than that in the 
		// table, it cannot be on the path of any optimal solutions not found
		// yet. Remember if an optimal solution is found, all configs along
		// the solution path stored in the hash table are released in 
		// Solution_Found() in solver.cpp
		return 1; 
	}
	else 
	{
		p->depth = pConfig->depth;
		*pCacheConfig = p;
		return 0;
	}
}
开发者ID:chrozz,项目名称:PCPSolver,代码行数:52,代码来源:cache.cpp

示例2: Solution_Found

//FILE *errfile=fopen("errfile.txt", "w");
// routine to deal with the situation when one solution is found including 
// record the solution, check the solution, update solving results and search
// parameters.
// return value:
//   >0  should return the length immediately (When only need find one solution
//   =0  continue to find other solutions
int CSolver::Solution_Found(CPCPInstance *pPCP, CConfig *pConfig)
{
	int k;

	// for test, may not be solution, so need not record length and count	
	if (globalStatus == FIND_MASK || globalStatus == EXCLUSION_METHOD)			
		return pConfig->depth;

	// just to find solution
	if (!FindShortestSolution_Flag) 
	{
		solution_length = pConfig->depth;
		solution_count = 1;
		return pConfig->depth;
	}

	// find all solutions
	if (   globalStatus == COMPARE_DIRECTION || globalStatus == ITERATIVE_SEARCH 
		|| globalStatus == DETERMINANT_SEARCH)
	{		
#ifdef SOLVER_OUTPUT
		// print the solution
        //if (pConfig->depth <= solution_length) // for special purposes
		/** BUG FIX 061031
			1. Originally, the first solution (may be optimal) is always omitted.
			   to fix that, now suboptimal solutions can be output as well.
            2. During bidirectioanl probing process, no solution should be output.
		**/
		if (globalStatus != COMPARE_DIRECTION)
			PrintSolution(arrSelection, pConfig->depth);
#endif

		// find all solutions not only including the shortest ones
		if (Iterative_Flag == 0 && FindAllSolutions_Flag == 1) 
			solution_count++;
		// find only all shortest solutions
		else if (pConfig->depth < solution_length || solution_length == 0) 
		{
			solution_length = pConfig->depth;
			solution_count = 1;
			iterative_depth_threshold = solution_length;
		}
		// find one more solution for the length
		else if (pConfig->depth == solution_length) 
			solution_count++;

		// find all configs in the solution path and free them if they are 
		// in the hashtable
		CConfig tempConfig(pConfig->depth * pPCP->offset);
		for (k=1;k<=pConfig->depth;k++)
		{
			// need improvement for exclusion method
			assert( (arrSelection[k]>=1) && (arrSelection[k]<=pPCP->size) ); 

			// add the pair
			tempConfig.MatchPair(&pPCP->arrPair[arrSelection[k]-1], arrSelection); 
			
			tempConfig.ConfigPrintToConsole();
            //tempConfig.ConfigPrint(errfile);
			// make up the visited node count
			node_num--;

			// find in the cache
			int hashvalue = tempConfig.CalHashValue();
			CConfig *p = hashTable[hashvalue];
			if (!p) continue;
			if (p->ConfigCmp(&tempConfig)) continue;

			// update the depth threshold
			p->depth = iterative_depth_threshold;
		}

		assert(tempConfig.len==0); // for debugging
	}

	return 0;
}
开发者ID:chrozz,项目名称:PCPSolver,代码行数:84,代码来源:solver.cpp


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