Example #1
0
File: link.c Project: AlexJF/eclim
int link3(int n) {
  return link1(n) + link2(n);
}
Example #2
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);
}
Example #3
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;
}
Example #4
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());
}
Example #5
0
// AssignmentTest
void
SymLinkTest::AssignmentTest()
{
	const char *dirLink = dirLinkname;
	const char *fileLink = fileLinkname;
	// 1. copy constructor
	// uninitialized
	NextSubTest();
	{
		BSymLink link;
		CPPUNIT_ASSERT( link.InitCheck() == B_NO_INIT );
		BSymLink link2(link);
		// R5 returns B_BAD_VALUE instead of B_NO_INIT
		CPPUNIT_ASSERT( equals(link2.InitCheck(), B_BAD_VALUE, B_NO_INIT) );
	}
	// existing dir link
	NextSubTest();
	{
		BSymLink link(dirLink);
		CPPUNIT_ASSERT( link.InitCheck() == B_OK );
		BSymLink link2(link);
		CPPUNIT_ASSERT( link2.InitCheck() == B_OK );
	}
	// existing file link
	NextSubTest();
	{
		BSymLink link(fileLink);
		CPPUNIT_ASSERT( link.InitCheck() == B_OK );
		BSymLink link2(link);
		CPPUNIT_ASSERT( link2.InitCheck() == B_OK );
	}

	// 2. assignment operator
	// uninitialized
	NextSubTest();
	{
		BSymLink link;
		BSymLink link2;
		link2 = link;
		// R5 returns B_BAD_VALUE instead of B_NO_INIT
		CPPUNIT_ASSERT( equals(link2.InitCheck(), B_BAD_VALUE, B_NO_INIT) );
	}
	NextSubTest();
	{
		BSymLink link;
		BSymLink link2(dirLink);
		link2 = link;
		// R5 returns B_BAD_VALUE instead of B_NO_INIT
		CPPUNIT_ASSERT( equals(link2.InitCheck(), B_BAD_VALUE, B_NO_INIT) );
	}
	// existing dir link
	NextSubTest();
	{
		BSymLink link(dirLink);
		BSymLink link2;
		link2 = link;
		CPPUNIT_ASSERT( link2.InitCheck() == B_OK );
	}
	// existing file link
	NextSubTest();
	{
		BSymLink link(fileLink);
		BSymLink link2;
		link2 = link;
		CPPUNIT_ASSERT( link2.InitCheck() == B_OK );
	}
}