#define MAX_BUFFER 1024 #include #include #include #include #include #include bool haveWrittenNodes = false; /* source: 8 - ? - 8 target: 16 - ? - 16 */ void writeNodes(){ haveWrittenNodes = true; for (int input = 1; input<=16; input++) cout << "node " << input << " 1 1 1" << endl; //bias // cout << "node 17 1 1 3" << endl; for (int output = 17; output <= 32; output++) cout << "node " << output << " 1 0 2" << endl; } void processNode(int node[4]){ if (!haveWrittenNodes) writeNodes(); if (node[3] == 1){ if (node[0] > 8){ cerr << "node problem 1! node[3], node[0]: " << node[3] << " " << node[0] << endl; exit(1); } } // else if (node[3] == 3){ // if (node[0] != 9){ // cerr << "node problem 2! node[3], node[0]: " << node[3] << " " << node[0] << endl; // exit(1); // } //} else if (node[3] == 2){ if (node[0] < 9 || node[0] > 16){ cerr << "node problem 3! node[3], node[0]: " << node[3] << " " << node[0] << endl; exit(1); } } else { if (node[3] != 0){ cerr << "node problem 4! node[3], node[0]: " << node[3] << " " << node[0] << endl; exit(1); } else { cout << "node " << (node[0] + 100) << " " << node[1] << " " << node[2] << " " << node[3] << endl; } } } void processGene(int iGeneNum, int iIn, int iOut, double dWeight, int iEnable){ haveWrittenNodes = false; //setup for next gnome in population int iTransfer[18] = {-1, 1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20, 21, 22, 23, 24}; int iTransfer2[18] = {-1, 9, 10, 11, 12, 13, 14, 15, 16, 25, 26, 27, 28, 29, 30, 31, 32}; int iIn1 = -1, iIn2 = -1, iOut1 = -1, iOut2 = -1; if (iIn < 17){ iIn1 = iTransfer[iIn]; iIn2 = iTransfer2[iIn]; } else { iIn1 = iIn + 100; } if (iOut < 17){ iOut1 = iTransfer[iOut]; iOut2 = iTransfer2[iOut]; } else { iOut1 = iOut + 100; } if (iIn1 == 0 || iIn2 == 0 || iOut1 == 0 || iOut2 == 0) cout << "ERROR: iIn = " << iIn << " iOut = " << iOut << " iIn1 = " << iIn1 << " iIn2 = " << iIn2 << " iOut1 = " << iOut1 << " iOut2 = " << iOut2 << endl; cout << "gene " << iGeneNum << " " << iIn1 << " " << iOut1; cout << " " << (dWeight / 2.0) << " 0 1 " << (dWeight / 2.0) << " " << iEnable << endl; /* if (iIn2 > 0){ cout << "gene " << iGeneNum << " " << iIn2 << " " << iOut1; cout << " " << (dWeight / 2.0) << " 0 1 " << (dWeight / 2.0) << " " << iEnable << endl; } if (iOut2 > 0){ cout << "gene " << iGeneNum << " " << iIn1 << " " << iOut2; cout << " " << (dWeight / 2.0) << " 0 1 " << (dWeight / 2.0) << " " << iEnable << endl; } */ //for rho_rand, only connect up state features and actions that //existed in source task /* if (iIn2 > 0 && iOut2 > 0){ cout << "gene " << iGeneNum << " " << iIn2 << " " << iOut2; cout << " " << (dWeight / 2.0) << " 0 1 " << (dWeight / 2.0) << " " << iEnable << endl; } */ } int main( int argc, char* argv[] ){ char buffer[MAX_BUFFER]; char sFileName[200]; char sType[20]; int n[4]; int iGeneNum, iIn, iOut, iEnable; long double dWt; int iTmp; long double dTmp; if (argc == 1){ cerr << "You must pass in a 3v2 population.gnm file to evaluate." << endl; exit(1); } //argv[0] is executable's name strcpy(sFileName, argv[1]); cerr << "opening file " << sFileName << endl; ifstream iFile(sFileName); if (!iFile.is_open()){ cerr << "Error opening file " << sFileName << endl; exit(1); } // Ignore Header do { iFile.getline( buffer, MAX_BUFFER ); cout << buffer << endl; } while ( buffer[ 0 ] != 'g' ); while ( !iFile.eof() ){ iFile >> sType; if (sType[0] == 'n'){ for (int i=0; i<4; i++){ iFile >> n[i]; } processNode(n); } else if (sType[3] == 'e'){ iFile >> iGeneNum >> iIn >> iOut >> dWt; iFile >> iTmp >> dTmp >> dTmp >> iEnable; processGene(iGeneNum, iIn, iOut, dWt, iEnable); } else { iFile.getline(buffer,MAX_BUFFER); cout << sType << buffer << endl; } } iFile.close(); return 0; }