void ResourcesSynchronizationLibrary::readFromFile( std::ifstream& file )
{
    LOCK
    CommandsFileParser fileParser( unpackingDirPath_ );
    CommandPtr command;

    while( ( command = fileParser.readNextCommand( file ) ) != nullptr ){
        processCommand( *command );
    }
}
Exemple #2
0
Mesh::Mesh(string filename)
{
	checksum = false;
	status_msg = "";

	if (filename == "random" || filename == "random extrude" || filename == "random surfrev") {	
		checksum = true;
		status_msg = "Success!";
		randomMesh(filename);
		generateMesh();
	}
	else if (fileParser(filename)) {		
		checksum = true;
		status_msg = "Success!";
		generateMesh();
	}
}
/**
Parses the configuration file buffer, reading each SQL statement
and processing it.

@param aBuffer Buffer containing the configuration file contents
@param aDbName Logical database name: "main" for the main database or attached database name

@leave KErrNoMemory, if an out of memory condition occurs
*/
void TSqlDbSysSettings::ParseFileL(const TDesC& aBuffer, const TDesC& aDbName)
	{
	TLex fileParser(aBuffer);
	//While not end of file
	while (!fileParser.Eos())
		{
		//Get the next of the SQL statements, which are seperated by semicolons
		fileParser.SkipSpaceAndMark(); // skip any preceding whitespace before the next statement
		while ((!fileParser.Eos()) && (fileParser.Peek() != ';'))
			{
			fileParser.Inc(); // continue to next character
			}
		TPtrC stmt = fileParser.MarkedToken(); // extract the marked token
		fileParser.Inc();  // to skip the terminating ';' for next iteration
	
		//Process this statement
		ProcessStatementL(stmt, aDbName);
		}
	}
void ResourcesSynchronizationLibrary::saveToFile( std::ofstream& file ) const
{
    LOCK
    CommandsFileParser fileParser( unpackingDirPath_ );

    // First pass: write creation commands to file.
    for( const auto& resourceSyncDataPair : resourcesSyncData_ ){
        if( resourceSyncDataPair.second->getCreationCommand() != nullptr ){
            fileParser.writeCommand( *( resourceSyncDataPair.second->getCreationCommand() ),
                                     file );
        }
    }

    // Second pass: write update commands to file.
    for( const auto& resourceSyncDataPair : resourcesSyncData_ ){
        CommandsList updateCommands = resourceSyncDataPair.second->generateUpdateCommands();
        for( const auto& command : updateCommands ){
            fileParser.writeCommand( *command, file );
        }
    }
}
Exemple #5
0
/**
 * the main progrems - calls the diffrent functions to start the orchestras
 * in case of success finding a solution or the best one -  will print it
 * otherwise will print a message
 * @param argc the number of arguments give
 * @param argv the char array that hodls the arguments
 * return 0
 **/
int main(int argc, char* argv[])
{
	atexit(cleanFiles);
	argumentParser(argc, argv);
	int** sudukuTable = NULL;
	sudukuTable = fileParser(sudukuTableFile);
	unsigned int best = ((gTableSize*(1 + gTableSize)) / 2)*gTableSize;
	pNode bestNode = getBest((pNode)sudukuTable, getNodeChildrenSoduku, calculateTableSum, 
							 nodeReleaser, copySudukuTable, best);
	if (bestNode != NULL)
	{
		printSudukuSolution((int**)bestNode, gTableSize);
		nodeReleaser(bestNode);
	}
	else
	{
		printf("no solution!\n");
	}
	
	nodeReleaser(sudukuTable);
	return 0;
}
Exemple #6
0
///=====================================================
/// 
///=====================================================
bool EngineAndrew::Mesh::LoadFromC23File(const std::string& filename, const OpenGLRenderer* renderer){
	BinaryFileParser fileParser(filename);
	if (fileParser.ReadChar() != 'G') return false; //4-cc
	if (fileParser.ReadChar() != 'C') return false;
	if (fileParser.ReadChar() != '2') return false;
	if (fileParser.ReadChar() != '3') return false;
	if (fileParser.ReadChar() != 2) return false; //version
	char subtype = fileParser.ReadChar();
	if (subtype != 2 && subtype != 4) return false; //subversion
	fileParser.ReadString();

	m_indeces.clear();
	m_vertices.clear();

	int numVerts = fileParser.ReadInt();
	m_vertices.reserve(numVerts);

	Vertex_Anim vert;

	for (int i = 0; i < numVerts; ++i){
		vert.m_position = fileParser.ReadVec3();
		vert.m_color = fileParser.ReadRGBAchars();
		vert.m_texCoords = fileParser.ReadVec2();
		
		vert.m_normal = fileParser.ReadVec3();
		vert.m_tangent = fileParser.ReadVec3();
		vert.m_bitangent = fileParser.ReadVec3();

		vert.m_boneIndeces[0] = fileParser.ReadUnsignedChar();
		vert.m_boneIndeces[1] = fileParser.ReadUnsignedChar();
		vert.m_boneIndeces[2] = fileParser.ReadUnsignedChar();
		vert.m_boneIndeces[3] = fileParser.ReadUnsignedChar();

		vert.m_boneWeights = fileParser.ReadVec3();

		m_vertices.push_back(vert);
	}

	int numIndeces = fileParser.ReadInt();
	if (numIndeces > 0){
		m_indeces.reserve(numIndeces);
		for (int i = 0; i < numIndeces; ++i){
			m_indeces.push_back(fileParser.ReadInt());
		}
	}
	else{
		numIndeces = numVerts;
		m_indeces.reserve(numIndeces);
		for (int i = 0; i < numIndeces; ++i){
			m_indeces.push_back(i);
		}
	}

	renderer->GenerateBuffer((GLuint*)&m_vboID);
	renderer->SendVertexDataToBuffer(m_vertices.data(), sizeof(Vertex_Anim) * numVerts, m_vboID);

	renderer->GenerateBuffer((GLuint*)&m_iboID);
	renderer->SendVertexDataToBuffer(m_indeces.data(), sizeof(int) * numIndeces, m_iboID);

	m_vaoID = renderer->CreateVAOBasic();

	return true;
}
int main()
{
    /**
     * Seeding part 1443936225
     */
    auto seed = time(NULL);
    std::cout << "Hello, no seed was defined, so the program will use the default time(NULL) seed." << std::endl <<
    "Your seed is : " + std::to_string(seed) << std::endl;
    srand(seed);

    /**
     * File Opening and reading part
     */
    std::string fileName = "/home/sergio/Copy/UFMG/Graduacao/2015_2/ComputacaoNatural/TP1/tests/SR_div.txt";
    FileParser fileParser(fileName);
    fileParser.getNumberOfVariables();
    std::vector<std::string> file = fileParser.getVectorOfTextFile();

    for (int generation = 0 ; generation < ExecutionParameters::getInstance().getMaxNumberOfGenerations(); generation++)
    {
        /**
         * Individual creation
         */
        std::vector<Individual> individualsList;
        for (int i = 0; i < ExecutionParameters::getInstance().getMaxNumberOfIndividuals(); i++)
        {
            Individual individual;
            individualsList.push_back(individual);
        }

        /**
         * Evaluation part
         */
        ExpressionParser expressionParser; //expressionParser

        Individual bestIndividual, worstIndividual;
        bool noBestIndividual = true;

        std::vector<Individual> updatedIndividualList;
        for (Individual individual : individualsList)
        {
            //std::cout << individual.getGenotype().getMathematicalExpression() << std::endl; debug cout
            expressionParser.setExpression(individual.getGenotype().getMathematicalExpression());

            for (auto line : file)
            {
                if (line == "")
                    continue;

                double variableValues[ExecutionParameters::getInstance().getNumberOfVariables()];
                double functionValue;
                /**
                 * Transform into a function
                 */
                std::istringstream lineStream(line);
                for (int i = 0; i < ExecutionParameters::getInstance().getNumberOfVariables(); i++)
                {
                    lineStream >> variableValues[i];
                    expressionParser.defineVars(variableValues[i]);
                }
                lineStream >> functionValue;
                /**
                 *
                 */

                double resultForIndividual = expressionParser.parse();
                double individualFitnessScore;
                //std::cout << "Results for A = " << variableValues[0] << " :\n\tind: " << resultForIndividual << "\nfun: " << functionValue << std::endl; debug cout

                if (!std::isnan(resultForIndividual)) //check whether it has a valid result
                {
                    /**
                     * The fitness score should be calculated here
                     */
                    double differenceOfFunctionValueAndIndividual = std::fabs(resultForIndividual - functionValue);
                    individualFitnessScore = individual.getFitnessScore() + differenceOfFunctionValueAndIndividual;
                    individual.setFitnessScore(individualFitnessScore);
                }
                else
                {
                    individualFitnessScore = std::nan("");
                    individual.setFitnessScore(
                            individualFitnessScore); //Setting individuals with invalid score to NaN so they won't appear in the worst individuals
                    //One case in which we don't want those individuals is for example the function x^x which can happen, and x can take negative values
                    expressionParser.clearVars();
                    updatedIndividualList.push_back(individual);
                    break;
                }
                expressionParser.clearVars();
            }
            if (noBestIndividual && std::isfinite(individual.getFitnessScore()))
            {
                bestIndividual.Copy(individual);
                worstIndividual.Copy(individual);
                noBestIndividual = false;
            }
            if (bestIndividual.getFitnessScore() > individual.getFitnessScore() &&
                std::isfinite(individual.getFitnessScore()))
                bestIndividual.Copy(individual);
            if (worstIndividual.getFitnessScore() < individual.getFitnessScore() &&
                std::isfinite(individual.getFitnessScore()))
                worstIndividual.Copy(individual);
            updatedIndividualList.push_back(individual);
        }
        individualsList.clear();
        individualsList = updatedIndividualList;

        IndividualsMetrics individualsMetrics(individualsList, 0.0);

        std::cout << "#################\n\tGeneration " << generation << std::endl;
        std::cout << "The best individual was : " << bestIndividual.getGenotype().getMathematicalExpression() <<
        " with a fitness score of : " << bestIndividual.getFitnessScore() << std::endl;
        std::cout << "The worst individual was : " << worstIndividual.getGenotype().getMathematicalExpression() <<
        " with a fitness score of : " << worstIndividual.getFitnessScore() << std::endl;
        std::cout << "The average fitness of this generation was : " << individualsMetrics.getAverageFitness() <<
        std::endl;
        std::cout << "The number of repeated individuals on this generation was : " <<
        individualsMetrics.getRepeatedIndividuals() << std::endl;
        std::cout << "There were " << individualsMetrics.getCrossoverIndividualsWithBetterFitnessThanParents() <<
        " individuals generated by crossover better than parents" << std::endl;
    }
    return 0;
}