Esempio n. 1
0
string Entity::checkVicinity_all( map< string , Payoff > & d, map< string , Payoff > & d_two)
/* this version, once complete, will consider both landscapes and make the move that provides the biggest average */
{
	Payoff Move;
	string tempConfig = itsPayoff.GetConfig();
	string tempConfig_two;
	unsigned short int i;
	unsigned short int strLength;
	vector <Payoff> averages;
	double tempAverage;
	strLength = tempConfig.length();
	for ( i = 0 ; i < strLength ; i++)
	{
		tempConfig = itsPayoff.GetConfig();
		if ( tempConfig[i] == '0' ) { tempConfig[i] = '1'; }
		else { tempConfig[i] = '0'; }
		tempConfig_two = flipConfigString( tempConfig );
		tempAverage = (d[tempConfig].GetFitness() + d_two[tempConfig_two].GetFitness()) / (double) 2;
		averages.push_back ( Payoff(tempConfig,tempAverage) );
	}
	Move.SetFitness(0);
	vector <Payoff>::iterator IT;
	for ( IT = averages.begin() ; IT != averages.end() ; IT++)
	{
		if (Move.GetFitness() < (*IT).GetFitness() )
			{
			Move.SetConfig( (*IT).GetConfig() );
			Move.SetFitness( (*IT).GetFitness() );
			}
	}
	if ( Move.GetFitness() <= itsPayoff.GetFitness() ) { return "EMPTY"; }
	return Move.GetConfig();
} 
Esempio n. 2
0
string Search::checkVicinityBlind( JoinedLandscape & thisLandscape, Entity & thisEntity, bool Sequential, int WhichLandscape )
/* randomly selects one move */
{
	tempPayoff.SetConfig ( thisEntity.GetConfig() );
	if ( !thisEntity.IsAlive() ) { return "EMPTY"; }
	string tempConfig = tempPayoff.GetConfig();
	unsigned short int i, j;
	unsigned short int strLength;
	double tempFitness;
	strLength = tempConfig.length();
	i = rand() % (strLength);
	if ( tempConfig[i] == '0' ) { tempConfig[i] = '1'; }
	else { tempConfig[i] = '0'; };

	switch (WhichLandscape)
	{
		case 0: pLandscape = &thisLandscape;

			break;
		case 1: pLandscape = &thisLandscape.LOne;

			break;
		case 2: pLandscape = &thisLandscape.LTwo;

			break;
	}

	tempFitness = thisLandscape.d[tempConfig].GetFitness();
	if ( tempPayoff.GetFitness() <= thisLandscape.d[ thisEntity.GetConfig() ].GetFitness() ) { return "EMPTY"; }
	return tempPayoff.GetConfig();
}
Esempio n. 3
0
void Entity::Reset( Landscape & LJoined )
{
	map <string, Payoff >::iterator IT;
	IT = LJoined.d.begin(); 
	itsPayoff.SetConfig( (*IT).second.GetConfig() );
	itsPayoff.SetFitness( (*IT).second.GetFitness() );
}
Esempio n. 4
0
void Entity::Reset( map< string , Payoff > & d, map< string , Payoff > & d_two )
{
	map <string, Payoff >::iterator IT;
	IT = d.begin(); 
	map <string, Payoff >::iterator IT_TWO;
	IT_TWO = d_two.begin();
	itsPayoff.SetConfig( (*IT).second.GetConfig() );
	itsPayoff.SetFitness( ((*IT).second.GetFitness() + (*IT_TWO).second.GetFitness()) / (double) 2 );
}
Esempio n. 5
0
string Search::checkVicinityNonrandom( JoinedLandscape & thisLandscape, Entity & thisEntity, bool Sequential, int WhichLandscape )
/* this version finds the move with the greatest improvement choices constant */
{
	tempPayoff.SetConfig ( thisEntity.GetConfig() ); // tempPayoff is current value for thisEntity
	if ( !thisEntity.IsAlive() ) { return "EMPTY"; }
	string configuration = tempPayoff.GetConfig(); // configuration is a temporary string to be returned as the potential move
	unsigned short int i, j, strLength, searchLength;
	double tempAverage = 0;
	vector <Payoff> averages;
	strLength = configuration.length();

	switch (WhichLandscape)
	{
		case 0: pLandscape = &thisLandscape;
			searchLength = strLength;
			break;
		case 1: pLandscape = &thisLandscape.LOne;
			searchLength = strLength / 2;
			break;
		case 2: pLandscape = &thisLandscape.LTwo;
			configuration = flipConfigString( configuration );
			tempPayoff.SetConfig ( flipConfigString ( tempPayoff.GetConfig() ) );
			searchLength = strLength / 2;
			break;
	}
	tempPayoff.SetFitness ( (*pLandscape).d[configuration].GetFitness() );
	for ( i = 0 ; i < searchLength ; i++)
	{
		configuration = tempPayoff.GetConfig(); // reset configuration
		if ( configuration[i] == '0' ) { configuration[i] = '1'; } // flip one decision
		else { configuration[i] = '0'; };	
		tempAverage = (*pLandscape).d[configuration].GetFitness(); // get the new value for the flipped string
		averages.push_back ( Payoff(configuration, tempAverage) ); // add to the list of possibilties
	}

	configuration = tempPayoff.GetConfig(); // resetting configuration to the Entity's current value
	if (WhichLandscape == 2) { configuration = flipConfigString (configuration); } // ugly hack to make the second landscape work
	tempAverage = tempPayoff.GetFitness(); // resetting fitness to the Entity's current value

	vector <Payoff>::iterator IT;
	for ( IT = averages.begin() ; IT != averages.end() ; IT++ )
	{
		if ( tempAverage < (*IT).GetFitness() ) // if one of the averages is greater
			{
			configuration = (*IT).GetConfig(); // set the move information
			tempAverage = (*IT).GetFitness(); // similar
			}
	} // the move information should be the greatest possible
	if ( tempAverage <= tempPayoff.GetFitness() ) { return "EMPTY"; } // if less, don't recommend a move
	if ( isEqual (tempAverage, tempPayoff.GetFitness() ) ) { return "EMPTY"; } // if equal, no reason to move
	if ( WhichLandscape == 2 ) { return flipConfigString ( configuration ); } // flip the string back for the potential move
	return configuration;
}
Esempio n. 6
0
bool Entity::Move( string destination, Landscape & LJoined )
{
	if ( destination == "EMPTY" ) { return 0; }
	string previous = itsPayoff.GetConfig();
	LJoined.SubFromDistribution( previous );
	// cout << "Move from " << itsPayoff.GetConfig() << ":" << itsPayoff.GetFitness() << " to ";
	itsPayoff.SetConfig( destination );
	itsPayoff.SetFitness( LJoined.d[destination].GetFitness() ) ;
	// cout << "to " << itsPayoff.GetConfig() << ":" << itsPayoff.GetFitness() << endl;
	LJoined.AddToDistribution( destination );
	movesTaken++;
	return 1;
}
Esempio n. 7
0
bool Entity::Move( string Move, map< string , Payoff > & d, map< string , Payoff > & d_two )
{
	if ( Move == "EMPTY" ) { return 0; }
	cout << "Move from " << itsPayoff.GetConfig() << ":" << itsPayoff.GetFitness() << " to ";
	itsPayoff.SetConfig( Move );
	itsPayoff.SetFitness( (d[Move].GetFitness() + d_two[ flipConfigString(Move) ].GetFitness()) / (double) 2 );
	cout << itsPayoff.GetConfig() << ":" << itsPayoff.GetFitness() << " is successful." << endl;
	return 1;
}
Esempio n. 8
0
string Search::checkVicinityDist( JoinedLandscape & thisLandscape, Entity & thisEntity, bool Sequential, int WhichLandscape )
/* randomly selects one move weighted by distribution */
{
	tempPayoff.SetConfig ( thisEntity.GetConfig() );
	if ( !thisEntity.IsAlive() ) { return "EMPTY"; }
	string tempConfig = tempPayoff.GetConfig();
	int i, j;
	unsigned short int strLength;
	double tempFitness;
	map <string,int> chance;
	vector <string> Configs;
	strLength = tempConfig.length();
	Configs.push_back( tempConfig );
	for ( i = 0 ; i < strLength; i++ )
	{
		tempConfig = tempPayoff.GetConfig();
		if ( tempConfig[i] == '0' ) { tempConfig[i] = '1'; }
		else { tempConfig[i] = '0'; }
		Configs.push_back( tempConfig );
	}	
	unsigned int total = 0;

	switch (WhichLandscape)
	{
		case 0: pLandscape = &thisLandscape;

			break;
		case 1: pLandscape = &thisLandscape.LOne;

			break;
		case 2: pLandscape = &thisLandscape.LTwo;

			break;
	}

	vector <string>::iterator IT;
	for ( IT = Configs.begin() ; IT != Configs.end() ; IT++ )
	{
		chance.insert( pair<string,int> ( (*IT), thisLandscape.d[(*IT)].GiveDistribution() ) );
		total += thisLandscape.d[(*IT)].GiveDistribution();
	}
	i = rand() % total;
	map <string,int>::reverse_iterator IT_TWO;
	for ( IT_TWO = chance.rbegin() ; IT_TWO != chance.rend() ; IT_TWO++ ) // this random number might be 1 off
	{
		i = i-(*IT_TWO).second;
		tempConfig = (*IT_TWO).first;
		if (i < 0) { break; }
	}
	tempFitness = thisLandscape.d[tempConfig].GetFitness();
	tempPayoff.SetConfig( tempConfig );
	tempPayoff.SetFitness( tempFitness );
	// if ( Move.GetFitness() <= d[ itsPayoff.GetConfig() ].GetFitness() ) { return "EMPTY"; }
	return tempPayoff.GetConfig();
}
Esempio n. 9
0
/* ********************************************* BLIND ************************ */
string Entity::checkVicinity_one_blind( map< string , Payoff > & d, map< string , Payoff > & d_two, unsigned short int maxN )
/* this version keeps landscape 2 choices constant */
{
	Payoff Move;
	string tempConfig = itsPayoff.GetConfig();
	unsigned short int i, j;
	unsigned short int strLength;
	double tempFitness;
	strLength = tempConfig.length();
	tempConfig = itsPayoff.GetConfig();
	i = rand() % (maxN);
	if ( tempConfig[i] == '0' ) { tempConfig[i] = '1'; }
	else { tempConfig[i] = '0'; };
	tempFitness = d[tempConfig].GetFitness();
	Move.SetConfig( tempConfig );
	Move.SetFitness( tempFitness );
	if ( Move.GetFitness() <= d[ itsPayoff.GetConfig() ].GetFitness() ) { return "EMPTY"; }
	return Move.GetConfig();
}
 void BlackCalculator::Calculator::visit(Payoff& p) {
     QL_FAIL("unsupported payoff type: " << p.name());
 }
Esempio n. 11
0
string Entity::checkVicinity_two( map< string , Payoff > & d, map< string , Payoff > & d_two, unsigned short int maxN)
/* this version keeps landscape 2 choices constant */
{
	Payoff Move;
	string tempConfig = itsPayoff.GetConfig(), tempBinary, tempConfig_two;
	double currentAverage = (d[ itsPayoff.GetConfig() ].GetFitness() + d_two[ flipConfigString(itsPayoff.GetConfig()) ].GetFitness()) / (double) 2;
	unsigned short int i, j;
	unsigned short int strLength;
	vector <Payoff> averages;
	double tempAverage;
	strLength = tempConfig.length();
	for ( i = maxN ; i < 2*maxN ; i++)
	{
		tempConfig = itsPayoff.GetConfig();
		if ( tempConfig[i] == '0' ) { tempConfig[i] = '1'; }
		else { tempConfig[i] = '0'; };
		tempConfig_two = flipConfigString( tempConfig );	
		tempAverage = (d[tempConfig].GetFitness() + d_two[tempConfig_two].GetFitness()) / (double) 2;
		averages.push_back ( Payoff(tempConfig,tempAverage) );
	}
	Move.SetFitness(0);
	vector <Payoff>::iterator IT;
	for ( IT = averages.begin() ; IT != averages.end() ; IT++ )
	{			
		if ( Move.GetFitness() < (*IT).GetFitness() )
			{
			Move.SetConfig( (*IT).GetConfig() );
			Move.SetFitness( (*IT).GetFitness() );
			}
	}
	if ( Move.GetFitness() <= itsPayoff.GetFitness() ) { return "EMPTY"; }
	return Move.GetConfig();
}
Esempio n. 12
0
	PayforSum(Payoff& optpay)
	{
		OptPay = optpay.clone();
	}
Esempio n. 13
0
PayoffBridge::PayoffBridge(const Payoff& innerPayoff)
{
	ThePayoffPtr = innerPayoff.clone();
}