Exemplo n.º 1
0
int main( int argc, const char* argv[] )
{
    {
        printf("--------------\n");
        TestLinkControl link1(&txBuffer, &n1);
        link1.reset();

        link1.setSeed(0,0);
        link1.dump();
        link1.nextAlias();
        link1.dump();
        link1.nextAlias();
        link1.dump();
        link1.nextAlias();
        link1.dump();
        link1.nextAlias();
        link1.dump();
    }

    {
        printf("--------------\n");
        TestLinkControl link1(&txBuffer, &n1);
        link1.reset();

        link1.setSeed(0x020121,0x000012);
        link1.dump();
        link1.setSeed(0x020112,0x000021);
        link1.dump();
        link1.setSeed(0x020111,0x000022);
        link1.dump();
        link1.setSeed(0x020122,0x000011);
        link1.dump();
    }
}
Exemplo n.º 2
0
int main()
{
	WebLink link1("www.soccer.com");
	const WebLink link2("www.nfl.com");
	Subject football("Football is a great game. Bla bla bla.........");

	football.printText();

	football.setLink(&link1);

	football.printText();

	football.setLink(&link2);

	football.printText();

	const Subject multiplication("The table of multiplying by 10 is:\n 1x10  10\n 2x10  20\n 3x10  30\n 4x10  40\n 5x10  50\n 6x10  60\n 7x10  70\n 8x10  80\n 9x10  90\n10x10 100");

	multiplication.printText();
	std::cout << "This subject has the following link: " << multiplication.getLink() << std::endl << std::endl;

	return 0;
}
Exemplo n.º 3
0
Arquivo: link.c Projeto: AlexJF/eclim
int link3(int n) {
  return link1(n) + link2(n);
}
Exemplo n.º 4
0
Arquivo: link.c Projeto: AlexJF/eclim
int link2(int n) {
  return link1(n);
}
Exemplo n.º 5
0
T_bool blpp_fs_CopyFileBypassW(PT_wstr lpExistingFileName,PT_wstr lpNewFileName,T_bool bFailIfExists)
{
    filePathLinkW link1(lpExistingFileName),link2(lpNewFileName);
    return CopyFileW(link1.getLink().c_str(),link2.getLink().c_str(),bFailIfExists);
}
Exemplo n.º 6
0
T_bool blpp_fs_MoveFileBypassW(PT_wstr lpExistingFileName,PT_wstr lpNewFileName)
{
    filePathLinkW link1(lpExistingFileName),link2(lpNewFileName);
    return MoveFileW(link1.getLink().c_str(),link2.getLink().c_str());
}
Exemplo n.º 7
0
//---------------------------------AddNeuron------------------------------
//
//	this function adds a neuron to the genotype by examining the network, 
//	splitting one of the links and inserting the new neuron.
//------------------------------------------------------------------------
void CGenome::AddNeuron(double MutationRate, CInnovation &innovations, int NumTrysToFindOldLink) {
	//just return dependent on mutation rate
	if (RandFloat() > MutationRate) return;

	//if a valid link is found into which to insert the new neuron
	//this value is set to true.
	bool bDone = false;

	//this will hold the index into m_vecLinks of the chosen link gene
	int  ChosenLink = 0;

	//first a link is chosen to split. If the genome is small the code makes 
	//sure one of the older links is split to ensure a chaining effect does
	//not occur. Here, if the genome contains less than 5 hidden neurons it
	//is considered to be too small to select a link at random
	const int SizeThreshold = m_iNumInputs + m_iNumOutPuts + 10;

	if (m_vecLinks.size() < SizeThreshold)
	{    
		while(NumTrysToFindOldLink--)
		{
			//choose a link with a bias towards the older links in the genome 
			ChosenLink = RandInt(0, NumGenes()-1-(int)sqrt((double)NumGenes()));

			//make sure the link is enabled and that it is not a recurrent link 
			//or has a bias input
			int FromNeuron = m_vecLinks[ChosenLink].FromNeuron;

			if ( (m_vecLinks[ChosenLink].bEnabled)    && 
				(!m_vecLinks[ChosenLink].bRecurrent) &&
				(m_vecNeurons[GetElementPos(FromNeuron)].NeuronType != bias)) 
			{
				bDone = true;

				NumTrysToFindOldLink = 0;
			}
		}

		if (!bDone)
		{
			//failed to find a decent link
			return;
		}
	}

	else
	{
		//the genome is of sufficient size for any link to be acceptable
		while (!bDone)
		{
			ChosenLink = RandInt(0, NumGenes()-1);

			//make sure the link is enabled and that it is not a recurrent link 
			//or has a BIAS input
			int FromNeuron = m_vecLinks[ChosenLink].FromNeuron;

			if ( (m_vecLinks[ChosenLink].bEnabled) && 
				(!m_vecLinks[ChosenLink].bRecurrent) &&
				(m_vecNeurons[GetElementPos(FromNeuron)].NeuronType != bias)) 
			{
				bDone = true;
			}
		}
	}

	// Get the type of the neuron to add - hidden or modulatory
	neuron_type type = hidden;
	if (CParams::bAdaptable && RandFloat() < CParams::dModulatoryChance) {
		type = modulatory;
	}

	//disable this gene
	m_vecLinks[ChosenLink].bEnabled = false;

	//grab the weight from the gene (we want to use this for the weight of
	//one of the new links so that the split does not disturb anything the 
	//NN may have already learned...
	double OriginalWeight = m_vecLinks[ChosenLink].dWeight;

	//identify the neurons this link connects
	int from =  m_vecLinks[ChosenLink].FromNeuron;
	int to   =  m_vecLinks[ChosenLink].ToNeuron;

	//calculate the depth and width of the new neuron. We can use the depth
	//to see if the link feeds backwards or forwards
	double NewDepth = (m_vecNeurons[GetElementPos(from)].dSplitY + 
		m_vecNeurons[GetElementPos(to)].dSplitY) /2;

	double NewWidth = (m_vecNeurons[GetElementPos(from)].dSplitX + 
		m_vecNeurons[GetElementPos(to)].dSplitX) /2;

	//Now to see if this innovation has been created previously by
	//another member of the population
	int id = innovations.CheckInnovation(from,
		to,
		new_neuron);

	/*it is possible for NEAT to repeatedly do the following:

	1. Find a link. Lets say we choose link 1 to 5
	2. Disable the link,
	3. Add a new neuron and two new links
	4. The link disabled in Step 2 may be re-enabled when this genome
	is recombined with a genome that has that link enabled.
	5  etc etc

	Therefore, this function must check to see if a neuron ID is already 
	being used. If it is then the function creates a new innovation
	for the neuron. */
	if (id >= 0)
	{
		int NeuronID = innovations.GetNeuronID(id);

		if (AlreadyHaveThisNeuronID(NeuronID))
		{
			id = -1;
		}
	}

	if (id < 0)
	{
		//add the innovation for the new neuron
		int NewNeuronID = innovations.CreateNewInnovation(from,
			to,
			new_neuron,
			type,
			NewWidth,
			NewDepth);

		//create the new neuron gene and add it.
		m_vecNeurons.push_back(SNeuronGene(type,
			NewNeuronID,
			NewDepth,
			NewWidth));

		//Two new link innovations are required, one for each of the 
		//new links created when this gene is split.

		//-----------------------------------first link

		//get the next innovation ID
		int idLink1 = innovations.NextNumber();

		//create the new innovation
		innovations.CreateNewInnovation(from,
			NewNeuronID,
			new_link);

		//create the new link gene
		SLinkGene link1(from,
			NewNeuronID,
			true,
			idLink1,
			1.0);

		m_vecLinks.push_back(link1);

		//-----------------------------------second link

		//get the next innovation ID
		int idLink2 = innovations.NextNumber();

		//create the new innovation
		innovations.CreateNewInnovation(NewNeuronID,
			to,
			new_link);

		//create the new gene
		SLinkGene link2(NewNeuronID,
			to,
			true,
			idLink2,
			OriginalWeight);

		m_vecLinks.push_back(link2);
	}

	else
	{
		//this innovation has already been created so grab the relevant neuron 
		//and link info from the innovation database
		int NewNeuronID = innovations.GetNeuronID(id);

		//get the innovation IDs for the two new link genes.
		int idLink1 = innovations.CheckInnovation(from, NewNeuronID, new_link);
		int idLink2 = innovations.CheckInnovation(NewNeuronID, to, new_link);

		//this should never happen because the innovations *should* have already 
		//occurred
		if ( (idLink1 < 0) || (idLink2 < 0) )
		{
			MessageBox(NULL, "Error in CGenome::AddNeuron", "Problem!", MB_OK);

			return;
		}

		//now we need to create 2 new genes to represent the new links
		SLinkGene link1(from, NewNeuronID, true, idLink1, 1.0);
		SLinkGene link2(NewNeuronID, to, true, idLink2, OriginalWeight);

		m_vecLinks.push_back(link1);
		m_vecLinks.push_back(link2);

		//create the new neuron
		SNeuronGene NewNeuron(type, NewNeuronID, NewDepth, NewWidth);

		//and add it
		m_vecNeurons.push_back(NewNeuron);		
	}

	return;
}