Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UTF-8 Start genome files #4

Open
Lip651 opened this issue Feb 9, 2020 · 0 comments
Open

UTF-8 Start genome files #4

Lip651 opened this issue Feb 9, 2020 · 0 comments

Comments

@Lip651
Copy link

Lip651 commented Feb 9, 2020

I think one of the huge drawbacks of the package is the lack of interpretability depending on your system. I had huge problems with compiling the examples, just because the input files creating the start genome were not interpretable by my system. I am running on Ubuntu 18.04.04. I had to rewrite the input files in a UTF-8 Format and modify genome such that it would be able to read them.

Here is the code working if you have UTF-8 files:

Genome::Genome(int id, std::ifstream &iFile) {

	char delimiters[] = " \n";
	//int pause;
	genome_id=id;
	wstring line;

  std::wbuffer_convert<std::codecvt_utf8<wchar_t>> conv(iFile.rdbuf());
  std::wistream wf(&conv);

	getline(wf, line);
	char curword[128];

	//Loop until file is finished, parsing each line
	while (getline(wf, line)) {

		int curwordnum = 0;
		wstring ws_line(line);
		string ws_line_str(ws_line.begin(), ws_line.end());
		const char* char_line =  ws_line_str.c_str();
		int wordcount = NEAT::getUnitCount(char_line, delimiters);

		cout << char_line << endl;

    std::stringstream ss(char_line);
		//strcpy(curword, NEAT::getUnit(curline, curwordnum++, delimiters));
    ss >> curword;
		//Check for end of Genome
		if (strcmp(curword,"genomeend")==0) {
			//strcpy(curword, NEAT::getUnit(curline, curwordnum++, delimiters));
            ss >> curword;
			int idcheck = atoi(curword);
			//iFile>>idcheck;
			if (idcheck!=genome_id) printf("ERROR: id mismatch in genome");
		}

		//Ignore genomestart if it hasn't been gobbled yet
		else if (strcmp(curword,"genomestart")==0) {
			++curwordnum;
			cout<<"genomestart"<<endl;
		}

		//Ignore comments surrounded by - they get printed to screen
		else if (strcmp(curword,"/*")==0) {
			//strcpy(curword, NEAT::getUnit(curline, curwordnum++, delimiters));
            ss >> curword;
			while (strcmp(curword,"*/")!=0) {
				//cout<<curword<<" ";
				//strcpy(curword, NEAT::getUnit(curline, curwordnum++, delimiters));
        ss >> curword;
			}
			//cout<<endl;
		}

		//Read in a trait
		else if (strcmp(curword,"trait")==0) {
			Trait *newtrait;

			char argline[1024];
			//strcpy(argline, NEAT::getUnits(curline, curwordnum, wordcount, delimiters));

			curwordnum = wordcount + 1;
			ss.getline(argline, 1024);
			//Allocate the new trait
			newtrait=new Trait(argline);

			//Add trait to vector of traits
			traits.push_back(newtrait);
		}

		//Read in a node
		else if (strcmp(curword,"node")==0) {
			NNode *newnode;

			char argline[1024];
			//strcpy(argline, NEAT::getUnits(curline, curwordnum, wordcount, delimiters));
			curwordnum = wordcount + 1;
			ss.getline(argline, 1024);
			//Allocate the new node
			newnode=new NNode(argline,traits);

			//Add the node to the list of nodes
			nodes.push_back(newnode);
		}

		//Read in a Gene
		else if (strcmp(curword,"gene")==0) {
			Gene *newgene;

			char argline[1024];
			//strcpy(argline, NEAT::getUnits(curline, curwordnum, wordcount, delimiters));
			curwordnum = wordcount + 1;

      ss.getline(argline, 1024);
      //std::cout << "New gene: " << ss.str() << std::endl;
			//Allocate the new Gene
      newgene=new Gene(argline,traits,nodes);

			//Add the gene to the genome
			genes.push_back(newgene);
		 std::cout<<"Added gene " << newgene << std::endl;
		}
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant