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


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

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


在下文中一共展示了CConfig::Copy方法的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: SolveConfig


//.........这里部分代码省略.........
	//// sort the matched pair array according to its matchret value	
	for (i=0;i<matchedPairNum-1;i++)
		for (j=i+1;j<matchedPairNum;j++)
		{
			if (arrRetValue[i] > arrRetValue[j])
			{
				k = arrRetValue[i];
				arrRetValue[i] = arrRetValue[j];
				arrRetValue[j] = k;
				
				k = arrMatchedPair[i];
				arrMatchedPair[i] = arrMatchedPair[j];
				arrMatchedPair[j] = k;
			}
		}
	
	//// try the pair one by one		
	// count new length for config
	newlen = pConfig->len+pPCP->offset+MAXLOOPCOUNT*pPCP->offset;
	// create new config
#ifdef USE_CONFIG_POOL
    pNewConfig = newConfig(newlen);
#else
    pNewConfig = new CConfig(newlen);
#endif

    // try all matched pairs
	for (i=0;i<matchedPairNum;i++)
	{
		// the last matched pair and the config can be reused? Jump back!
		if (i+1==matchedPairNum && arrRetValue[i]<=maxlen )
        {

            pConfig->MatchPair(&pPCP->arrPair[arrMatchedPair[i]], arrSelection);
            if (pConfig->up)
                if (pPCP->upmask) continue;
            if (!pConfig->up)
                if (pPCP->downmask) continue;

#ifdef USE_CONFIG_POOL
            deleteConfig(newlen);
#else
            delete pNewConfig; 			
#endif                     
            succ = TryFind(hashTable, pConfig, &pCacheConfig);
                    
            if (succ==1 || succ==2) // this config is in the cache
            { 
                Add_cutoff_node_number();
                //if (succ==2) ret = 0; 
                RETURNANDCLEAR;
            }
            goto DEEP;
		}

        // duplicate pConfig to config
		pNewConfig->Copy(pConfig);

		// match it with the pair
		pNewConfig->MatchPair(&pPCP->arrPair[arrMatchedPair[i]], arrSelection);

		// test masks
		if (pNewConfig->up)
			if (pPCP->upmask) continue;
		if (!pNewConfig->up)
			if (pPCP->downmask) continue;

		// check cache
        succ = TryFind(hashTable, pNewConfig, &pCacheConfig);
		if (succ==1 || succ==2) // this config is in the cache
		{ 
			Add_cutoff_node_number();
			continue; 
		}
      
		// recursively call the SolveConfig routine
		solveret=SolveConfig(pPCP, pNewConfig, newlen);

		// check result
		if (solveret>0) // solve it
        { 
#ifdef USE_CONFIG_POOL
            deleteConfig(newlen);
#else
            delete pNewConfig;  
#endif
            return solveret; 
        }

		if (solveret==0) // cannot solve it to the iterative_depth_threshold
			ret=0; 
	}
#ifdef USE_CONFIG_POOL
    deleteConfig(newlen);
#else
    delete pNewConfig; 			
#endif

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


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