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


C++ Landscape::GetN方法代码示例

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


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

示例1: genJoinedKeys

void JoinedLandscape::genJoinedKeys( Landscape &LJoin )
{
	Keymap tempKeymap(LJoin.GetN(), itsK_two, 0); // create a keymap to add to the other
	unsigned int T_one = pow (2, itsK + 1);
	unsigned int T_two = pow (2, itsK_two );
	vector < vector < string > > tempKeys ( LJoin.GetN() , vector <string>() );
	unsigned int ii, jj, ll;
	for( ii = 0 ; ii < LJoin.GetN() ; ii++ )
	{
		for( jj = 0 ; jj < T_one ; jj++ )
		{
			for( ll = 0 ; ll < T_two ; ll++ )
			{
			// Generate 2^k_2 partial keys and add them to the end of the tempKeymap
			tempKeys[ii].push_back( LJoin.getKey( ii, jj) + tempKeymap.Get( ii, ll) );
			}
		}
   	}
	LJoin.ReplaceKeys(tempKeys);
}
开发者ID:jonblackaz,项目名称:sociology,代码行数:20,代码来源:sim_new_backup.cpp

示例2: pow

/****************************** START OF JOIN ***************************/
JoinedLandscape::JoinedLandscape( Landscape & LOne, Landscape & LTwo, int k_input ) // relate two landscapes payoff structures so that decisions must be made with respect to both
/*    one approach would be to pass references to the two smaller landscapes then use the vectors to create a new one
 *    map < string, Payoff > d
 *    d is the final vector (i: 0 -> 2^n)
 *    vector< vector< Payoff > > payoffs --- a partial contribution for each possible configuration where payoffs[1][i] is the ith config for the 1th choice
 *    vector < vector < string > > key  ---  shows which set of choices matter for a given choice
 *    the best way to accomplish this might be to have one separate array for the cross-landscape choices that matter
 */
{
	cout << "Landscape initialized... working";
	n = LOne.GetN();
	k = k_input;
	string configuration, configuration2, numbuf;  // list of positions, 0 means not considered, 1 means not chosen, 2 means chosen
	int random_choice = 0, i = 0, j = 0, jj = 0, success = 0, MM = 0;
	int T = pow(2,(k+1));
	// buildStructure(T, numbuf, crosskey);
	// fillPartialPayoffs(T);
	// T = pow(2, n);
	// sumPayoffs(n, d, payoffs, T, numbuf);
	bool choices[20] = {0}; 
	string binaryConfig;
	int choices_counter = 0, L = 0, numbufLength = 0, decision = 0, X = 0, Z = 0, cc = 0, kk = 0, ii = 0, ll = 0;
	float randomTemp;
	while (decision < n ){  // i need to change this so that it creates two distinct sets of vectors
		cc = 0;
		while (cc < 21)
			{
			choices[cc] = 0;
			cc++;
			}
		ii = 0; kk = 0; L = 0; choices_counter = 0; X = 0; Z = 0;  numbufLength = 0; binaryConfig.clear(); numbuf.clear();
		while (choices_counter < k) // this loop selects k random decisions
			{
			random_choice = rand() % (n); // random integer from 0 to n-1 as index
			if (choices[random_choice] != 1)
				{
				choices[random_choice] = 1;
				binaryConfig.push_back('0');
				choices_counter++;
				}
			}
		// now that there is an array showing which choices matter, we need keys for each of the 2^(k+1) choices for those values
		key.resize(decision+1);
		key_two.resize(decision+1);
		buildJoined( LOne, k, decision, key, binaryConfig, choices );
		buildJoined( LTwo, k, decision, key_two, binaryConfig, choices );
		decision++;
	}
	fillPartialPayoffs( pow(2, (LOne.GetK()+k+1) ));
	i = 0; int mmm = 0;
/*	while (i < n){ // test loop
 *		mmm = 0;
 *		while (mmm < pow(2, LOne.k + k + 1)){
 *			cout << " " << payoffs[i][mmm].GetFitness() << " ";
 *			mmm++;
 *		}
 *		cout << endl;
 *		i++;
 *	}
 */
	i = 0;  // counter that represents each decision (d_i)
	success = 0;
	int divisor;
	T = pow(2, n);
	string temp, temp2;

/* need to replace with a function ****************** */
	i=0, jj=0, kk=0, ii=0, numbufLength=0, success=0;
	while (i < pow(2,(2*n)))
		{
		configuration.clear();
		ii=0;
		while ( ii < 2*n )
		{
			configuration.push_back('0');
			ii++;
		}
		numbuf.clear();
		binary(i, numbuf);
		numbufLength = numbuf.length();
		configuration.replace(((2*n)-numbufLength),numbufLength,numbuf);
		d.insert( pair<string,Payoff> (configuration, Payoff(configuration, 0)));
		jj=0;
		divisor = 0;
		while (jj < n)
			{
			kk=0;
			while (kk < pow(2, LOne.GetK() + k+ 1))  // this loop goes through each decision kk, goes to the payoff map, and adds up all the vectors with configs that match
				{
				temp = payoffs[jj][kk].GetConfig();
				temp2 = configuration;
				success = maskTest(temp, temp2, (2*n));
				if ( success ) {
					d[configuration].SetFitness( d[configuration].GetFitness() + payoffs[jj][kk].GetFitness() );
					divisor++;
					}
				kk++;
				}
			jj++;
//.........这里部分代码省略.........
开发者ID:jonblackaz,项目名称:sociology,代码行数:101,代码来源:simrewrite3.cpp

示例3: pow

/****************************** START OF JOIN ***************************/
JoinedLandscape::JoinedLandscape( Landscape & LOne, Landscape & LTwo, int k_input ) // relate two landscapes payoff structures so that decisions must be made with respect to both
/*    one approach would be to pass references to the two smaller landscapes then use the vectors to create a new one
 *    vector < Payoff > d
 *    d is the final vector (i: 0 -> 2^n)
 *    vector< vector< Payoff > > payoffs --- a partial contribution for each possible configuration where payoffs[1][i] is the ith config for the 1th choice
 *    vector < vector < string > > key  ---  shows which set of choices matter for a given choice
 *    the best way to accomplish this might be to have one separate array for the cross-landscape choices that matter
 */
{
	n = LOne.GetN();
	k = k_input;
	string configuration, configuration2, numbuf;  // list of positions, 0 means not considered, 1 means not chosen, 2 means chosen
	int random_choice = 0, i = 0, j = 0, jj = 0, success = 0, MM = 0;
	int T = pow(2,(k+1));
	// buildStructure(T, numbuf, crosskey);
	// fillPartialPayoffs(T);
	// T = pow(2, n);
	// sumPayoffs(n, d, payoffs, T, numbuf);
	bool choices[13] = {0}; 
	string binaryConfig;
	int choices_counter = 0, L = 0, numbufLength = 0, decision = 0, X = 0, Z = 0, cc = 0, kk = 0, ii = 0, ll = 0;
	float randomTemp;
	while (decision < n ){  // i need to change this so that it creates two distinct sets of vectors
		cc = 0;
		while (cc < 14)
			{
			choices[cc] = 0;
			cc++;
			}
		ii = 0; kk = 0; L = 0; choices_counter = 0; X = 0; Z = 0;  numbufLength = 0; binaryConfig.clear(); numbuf.clear();
		while (choices_counter < k) // this loop selects k random decisions
			{
			random_choice = rand() % (n); // random integer from 0 to n-1 as index
			if (choices[random_choice] != 1)
				{
				choices[random_choice] = 1;
				binaryConfig.push_back('0');
				choices_counter++;
				}
			}
		// now that there is an array showing which choices matter, we need keys for each of the 2^(k+1) choices for those values
		key.resize(decision+1);
		key_two.resize(decision+1);
		buildJoined( LOne, k, decision, key, binaryConfig, choices );
		buildJoined( LTwo, k, decision, key_two, binaryConfig, choices );
		decision++;
	}
	fillPartialPayoffs( pow(2, (LOne.GetK()+k+1) ));
	i = 0; int mmm = 0;
/*	while (i < n){ // test loop
 *		mmm = 0;
 *		while (mmm < pow(2, LOne.k + k + 1)){
 *			cout << " " << payoffs[i][mmm].GetFitness() << " ";
 *			mmm++;
 *		}
 *		cout << endl;
 *		i++;
 *	}
 */
	i = 0;  // counter that represents each decision (d_i)
	success = 0;
	int divisor;
	T = pow(2, n);
	string temp, temp2;

/* need to replace with a function ****************** */
	i=0, jj=0, kk=0, ii=0, numbufLength=0, success=0;
	while (i < pow(2,(2*n)))
		{
		configuration.clear();
		ii=0;
		while ( ii < 2*n )
		{
			configuration.push_back('0');
			ii++;
		}
		numbuf.clear();
		binary(i, numbuf);
		numbufLength = numbuf.length();
		configuration.replace(((2*n)-numbufLength),numbufLength,numbuf);
		d.push_back(Payoff(configuration, 0));
		jj=0;
		divisor = 0;
		while (jj < n)
			{
			kk=0;
			while (kk < pow(2, LOne.GetK() + k+ 1))  // this loop goes through each decision kk, goes to the payoff map, and adds up all the vectors with configs that match
				{
				temp = payoffs[jj][kk].GetConfig();
				temp2 = configuration;
				success = maskTest(temp, temp2, (2*n));
				if ( success ) {
					d[i].SetFitness( d[i].GetFitness() + payoffs[jj][kk].GetFitness() );
					divisor++;
					}
				kk++;
				}
			jj++;
			}
//.........这里部分代码省略.........
开发者ID:jonblackaz,项目名称:sociology,代码行数:101,代码来源:sim4.cpp


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