// Parses input string from UI and extracts object specification parameters SpecificationParametersStruct PDFTools::getAllSpecificationParametersFromString(const std::string specificationString) { SpecificationParametersStruct result; result.ObjectName = getSpecificParameterFromString(specificationString, "<ObjectName>", "Object"); result.GroupPath = normalizeGroupPath(getSpecificParameterFromString(specificationString, "<GroupPath>")); result.Color = getSpecificParameterFromString(specificationString, "<Color>"); result.SpecularColor = getSpecificParameterFromString(specificationString, "<SpecularColor>"); result.Opacity = getSpecificParameterFromString(specificationString, "<Opacity>"); result.GlyphText = getSpecificParameterFromString(specificationString, "<GlyphText>"); // U3D Glyphs are not supported by Acrobat... :-( result.MetaDataKey = getSpecificParameterFromString(specificationString, "<MetaDataKey>"); result.MetaDataValue = getSpecificParameterFromString(specificationString, "<MetaDataValue>"); result.ModelVisibility = getSpecificParameterFromString(specificationString, "<ModelVisibility>", "3"); result.WEMLabel = getSpecificParameterFromString(specificationString, "<WEMLabel>"); result.PositionTypes = getSpecificParameterFromString(specificationString, "<PositionTypes>", "all"); result.ConnectionTypes = getSpecificParameterFromString(specificationString, "<ConnectionTypes>", "simple"); result.PointSize = stringToDouble(getSpecificParameterFromString(specificationString, "<PointSize>", "3")); result.LineWidth = stringToDouble(getSpecificParameterFromString(specificationString, "<LineWidth>", "1")); return result; }
void AnimationMgr::handleInput( string type, string input ) { if( type == "sheet=" ) { sheets.push_back( AnimationSheet() ); sheets[ sheets.size() - 1 ].insertSheetName( input ); } else if( type == "sheetWidth=" ) sheets[ sheets.size() - 1 ].insertSheetWidth( stringToDouble( input ) ); else if( type == "sheetHeight=" ) sheets[ sheets.size() - 1 ].insertSheetHeight( stringToDouble( input ) ); else if( type == "state=" ) sheets[ sheets.size() - 1 ].insertState( input ); else if( type == "frames=" ) sheets[ sheets.size() - 1 ].insertNumFrames( stringToInt( input ) ); else if( type == "xBegin=" ) sheets[ sheets.size() - 1 ].insertXBegin( stringToDouble( input ) ); else if( type == "yBegin=" ) sheets[ sheets.size() - 1 ].insertYBegin( stringToDouble( input ) ); else if( type == "width=" ) sheets[ sheets.size() - 1 ].insertFrameWidth( stringToDouble( input ) ); else if( type == "height=" ) sheets[ sheets.size() - 1 ].insertFrameHeight( stringToDouble( input ) ); else if( type == "fps=" ) sheets[ sheets.size() - 1 ].insertFps( stringToInt( input ) ); else if( type == "defaultState" ) sheets[ sheets.size() - 1 ].insertDefaultState( input ); }
//-------------------------------------------------------------- void ofxStreetViewCollector::loadPoints(string path){ ofXml xml; // points.clear(); if (xml.load(path)) { if(xml.exists("SVPoint")){ xml.setTo("SVPoint[0]"); do { if(xml.getName() == "SVPoint"){ SVPoint point; point.ID = xml.getValue("id"); string pos = xml.getValue("pos"); vector<string>p = ofSplitString(pos, ", "); point.setPos(stringToDouble(p[0]), stringToDouble(p[1]), stringToDouble(p[2])); if (xml.exists("links")) { xml.setTo("links[0]"); if (xml.getName() == "links") { if (xml.exists("link")) { xml.setTo("link[0]"); do { if (xml.getName() == "link") { point.links.push_back(xml.getValue()); } } while(xml.setToSibling()); } } xml.setToParent(); xml.setToParent(); } if(points.count(point.ID) == 0){ savePoint(point); points[point.ID] = point; } } } while( xml.setToSibling() ); } } }
// read a column of double numbers and save them into a vector // NOTE: IT DOESN'T WORK void read_double_column(std::string filename, int column, std::vector<double>& array) { std::ifstream ifs; ifs.open(filename.c_str()); std::string line; std::string token; while (!ifs.eof()) { getline(ifs, line); if (line[0]!='#' && !line.empty()) { // ignore comments starting with "#" std::istringstream iss(line); for (int i=0; i<column; ++i){ iss >> token; } array.push_back(stringToDouble(token)); } }
std::vector<double> readSdfValues( char * filename ) { std::vector<double> values ; std::ifstream input(filename) ; if (!input) { std::cerr << "Error when opening input file" << std::endl ; return values ; // empty } std::string word ; int isData = 0 ; // Read only the second column while(input >> word) { if (isData) { values.push_back(stringToDouble(word)) ; } isData = 1 - isData ; } return values ; }
ClassifierOutput* ClassifierConfiguration::handleOutput(){ logln("Handle output:" + outputFilename); ClassifierOutput *co = new ClassifierOutput(); std::regex rxAccuracy("accuracy: (.*)"); std::regex rxPosPrecision("pos precision: (.*)"); std::regex rxPosRecall("pos recall: (.*)"); std::regex rxNegPrecision("neg precision: (.*)"); std::regex rxNegRecall("neg recall: (.*)"); std::regex rxTrainingTime("classified evaluation set in (.*) seconds"); std::regex rxStartTime("start time: (.*)"); std::regex rxStopTime("stop time: (.*)"); ifstream input(outputFilename); std::string line; while(std::getline(input, line)){ std::cmatch res; if(regex_search(line.c_str(), res, rxAccuracy)){ co->accuracy = stringToDouble(res[1]); } if(regex_search(line.c_str(), res, rxNegPrecision)){ co->negPrecision = stringToDouble(res[1]); } if(regex_search(line.c_str(), res, rxNegRecall)){ co->negRecall = stringToDouble(res[1]); } if(regex_search(line.c_str(), res, rxPosPrecision)){ co->posPrecision = stringToDouble(res[1]); } if(regex_search(line.c_str(), res, rxPosRecall)){ co->posRecall = stringToDouble(res[1]); } if(regex_search(line.c_str(), res, rxStartTime)){ co->startTime = stringToInt(res[1]); } if(regex_search(line.c_str(), res, rxStopTime)){ co->stopTime = stringToInt(res[1]); } if(regex_search(line.c_str(), res, rxTrainingTime)){ co->traininngTime = stringToDouble(res[1]); } } input.close(); return co; }
bool parseSphere(Sphere &s, TiXmlElement *c) { s.clear(); s.type = Geometry::SPHERE; if (!c->Attribute("radius")) { logError("Sphere shape must have a radius attribute"); return false; } if( !stringToDouble(c->Attribute("radius"),s.radius) ) { std::stringstream stm; stm << "radius [" << c->Attribute("radius") << "] is not a valid float: "; logError(stm.str().c_str()); return false; } return true; }
void ConfigMgr::loadCarrierMapObjectTypes(const std::string& configFilePath) { rapidxml::file<> xmlFile(configFilePath.c_str()); rapidxml::xml_document<>* xmlDocument = new rapidxml::xml_document<>(); xmlDocument->parse<0>(xmlFile.data()); rapidxml::xml_node<>* carriersNode = xmlDocument->first_node("carriers", 8, true); for (rapidxml::xml_node<>* node = carriersNode->first_node(); node != nullptr; node = node->next_sibling()) { std::string name = std::string(node->first_attribute("name", 4, true)->value()); MapObjectType& mapObjectType = mapObjectTypesMap[name]; mapObjectType.name = name; // Knoten-Typ const char* nodeName = node->name(); if (std::strcmp(nodeName, "carrier") != 0) { throw ErrorInConfigException(string_sprintf(_("Illegal node '%s'."), nodeName)); } mapObjectType.type = MapObjectTypeClass::CARRIER; // Basics rapidxml::xml_node<>* capacityNode = node->first_node("capacity", 8, true); mapObjectType.carrier.capacity = (unsigned char) stringToUnsignedLong(capacityNode->value()); rapidxml::xml_node<>* secondsToProduceNode = node->first_node("seconds-to-produce", 18, true); if (secondsToProduceNode != nullptr) { mapObjectType.secondsToProduce = stringToDouble(secondsToProduceNode->value()); } rapidxml::xml_node<>* graphicSetNode = node->first_node("graphic-set", 11, true); mapObjectType.graphicSetName = std::string(graphicSetNode->first_attribute("name", 4, true)->value()); // TODO Animations Log::info(_("Loaded carrier mapObjectType '%s'."), mapObjectType.name.c_str()); } delete xmlDocument; }
Vector4 getColorVec4(std::string colorString, const Vector4 defaultColor) { Vector4 result = defaultColor; size_t cutPos; StringVector parts; while( (cutPos = colorString.find_first_of(" ")) != colorString.npos ) { if (cutPos > 0) { parts.push_back(colorString.substr(0,cutPos)); } colorString = colorString.substr(cutPos+1); } if (colorString.length() > 0) { parts.push_back(colorString); } if ( (parts.size() == 3) || (parts.size() == 4) ) { for (size_t i = 0; i < parts.size(); i++) { result[i] = stringToDouble(parts[i]); } if (parts.size() == 3) { result[3] = 1; // Set alpha value to default = 1 if only color triplet was given } } return result; }
void CSVreader::readData( const string &filename, const string &csvdelimiter, vector< vector<double> > &sarr, int numY, int numX ) { numY++; numX; ifstream fin(filename.c_str()); string s; vector<string> selements; vector<double> delements; int x = 0; while ( !fin.eof() ) { getline(fin, s); if ( !s.empty() ) { splitString(s, selements, csvdelimiter); for ( int i=0; i<selements.size(); i++ ) { delements.push_back(stringToDouble(selements[i])); if (i>=numX) break; } sarr.push_back(delements); selements.clear(); delements.clear(); } x++; if (x>=numY) break; } fin.close(); }
bool TCPMessageUser::parsePlayersData(std::string& playersList) { players.clear(); std::vector<std::string> tokens; split(playersList, '#', tokens); std::cout << "Size of vector: " << tokens.size() << std::endl; for (auto& i : tokens) { std::vector<std::string> tmp; split(i, ' ', tmp); if (tmp.size() != 7) return false; int key = stringToInt(tmp[0]); std::string name = tmp[1]; int wins = stringToInt(tmp[2]); int looses = stringToInt(tmp[3]); int played = stringToInt(tmp[4]); int ratio = stringToDouble(tmp[5]); bool loggedin; try { loggedin = boost::lexical_cast<bool>(tmp[6]); } catch (std::exception& e) { std::cerr << "Error casting string " << tmp[6] << " to bool: " << e.what() << std::endl; } std::shared_ptr<data::IPlayer> p(factory.getPlayer(name, "")); p->setAllData(key, wins, looses, played, ratio, loggedin); players[p->getKey()] = p; } return true; }
/* ========================================================================== */ static stringToComplexError ParseComplexValue(const char *tx, BOOL bConvertByNAN, double *real, double *imag) { stringToDoubleError ierrDouble = STRINGTODOUBLE_NO_ERROR; stringToComplexError ierr = STRINGTOCOMPLEX_NO_ERROR; char *rnum_string = NULL; char *inum_string = NULL; size_t lnum = 0; BOOL haveImagI = FALSE; char *modifiedTxt = NULL; *real = stringToDouble(tx, FALSE, &ierrDouble); *imag = 0; /* test on strlen(tx) > 1 to remove case 'e' */ if ((int)strlen(tx) < 2) { if (ierrDouble == STRINGTODOUBLE_NO_ERROR) { ierr = (stringToComplexError) ierrDouble; } else { if (bConvertByNAN) { ierrDouble = STRINGTODOUBLE_NOT_A_NUMBER; *real = returnNAN(); *imag = 0; } else { *real = 0; *imag = 0; ierr = (stringToComplexError) ierrDouble; } } } else if (ierrDouble != STRINGTODOUBLE_NO_ERROR) { modifiedTxt = csv_strsubst(tx, ComplexScilab, ComplexI); lnum = ParseNumber(modifiedTxt); if (lnum <= 1) { /* manages special cases nan + nani, ... */ if (strnicmp(modifiedTxt, NanString, strlen(NanString)) == 0) { lnum = strlen(NanString); } else if (strnicmp(modifiedTxt, InfString, strlen(InfString)) == 0) { lnum = strlen(InfString); } else if (strnicmp(modifiedTxt, NegInfString, strlen(NegInfString)) == 0) { lnum = strlen(NegInfString); } else if (strnicmp(modifiedTxt, PosInfString, strlen(PosInfString)) == 0) { lnum = strlen(PosInfString); } else if (strnicmp(modifiedTxt, NegNanString, strlen(NegNanString)) == 0) { lnum = strlen(NegNanString); } else if (strnicmp(modifiedTxt, PosNanString, strlen(PosNanString)) == 0) { lnum = strlen(PosNanString); } } inum_string = midstring(modifiedTxt, lnum, -1); if ((inum_string[strlen(inum_string) - 1] == 'i') || (inum_string[strlen(inum_string) - 1] == 'j')) { inum_string[strlen(inum_string) - 1] = 0; if (inum_string[strlen(inum_string) - 1] == '*') { inum_string[strlen(inum_string) - 1] = 0; } if (strcmp(inum_string, "+") == 0) { FREE(inum_string); inum_string = strdup("+1"); } if (strcmp(inum_string, "-") == 0) { FREE(inum_string); inum_string = strdup("-1"); } haveImagI = TRUE; } else { haveImagI = FALSE; } rnum_string = leftstring(modifiedTxt, lnum); if (strcmp(inum_string, "") == 0) { *imag = stringToDouble(rnum_string, bConvertByNAN, &ierrDouble); ierr = (stringToComplexError)(ierrDouble); *real = 0.; } else { double dReal = 0.; double dImag = 0.; stringToDoubleError ierrReal = STRINGTODOUBLE_NO_ERROR; stringToDoubleError ierrImag = STRINGTODOUBLE_NO_ERROR; dReal = stringToDouble(rnum_string, FALSE, &ierrReal); dImag = stringToDouble(inum_string, FALSE, &ierrImag); if ((ierrReal == STRINGTODOUBLE_NO_ERROR) && (ierrImag == STRINGTODOUBLE_NO_ERROR)) { if (!haveImagI) { if (bConvertByNAN) { ierr = STRINGTOCOMPLEX_NO_ERROR; *real = returnNAN(); *imag = 0.; } else { ierr = STRINGTOCOMPLEX_ERROR; } } else { ierr = STRINGTOCOMPLEX_NO_ERROR; *real = dReal; *imag = dImag; } } else { if (bConvertByNAN) { ierr = STRINGTOCOMPLEX_NO_ERROR; *real = returnNAN(); *imag = 0.; } else { ierr = STRINGTOCOMPLEX_ERROR; } } } if (rnum_string) { FREE(rnum_string); rnum_string = NULL; } if (inum_string) { FREE(inum_string); inum_string = NULL; } if (modifiedTxt) { FREE(modifiedTxt); modifiedTxt = NULL; } } return ierr; }
void getUnit(ifstream& input,vector<Unit>& vecUnit) { if(!input) return; string str; while(1) { str.clear(); getline(input,str); if(str=="<Unit::nx type=全数>") {//需要先读取很多行无用信息才能找到目标行,检索方法可以考虑改进 str.clear(); getline(input,str); vector<string> vecUnitHeader=split(str); int UnitEqColumn(0);//识别表头 int UnitV_RateColumn(0); int UnitP_RateColumn(0); int UnitTopoNodeColumn(0); int UnitPColumn(0); int UnitQColumn(0); int UnitUeColumn(0); int UnitAngColumn(0); int UnitOffColumn(0); int UnitP_HColumn(0); int UnitP_LColumn(0); int UnitQ_HColumn(0); int UnitQ_LColumn(0); int UnitVoltColumn(0); for(size_t t=0;t<vecUnitHeader.size();++t) {//考虑switch,更清晰 if(vecUnitHeader[t]=="Eq") { UnitEqColumn=t; } else if(vecUnitHeader[t]=="V_Rate") { UnitV_RateColumn=t; } else if(vecUnitHeader[t]=="P_Rate") { UnitP_RateColumn=t; } else if(vecUnitHeader[t]=="node") { UnitTopoNodeColumn=t; } else if(vecUnitHeader[t]=="P") { UnitPColumn=t; } else if(vecUnitHeader[t]=="Q") { UnitQColumn=t; } else if(vecUnitHeader[t]=="Ue") { UnitUeColumn=t; } else if(vecUnitHeader[t]=="Ang") { UnitAngColumn=t; } else if(vecUnitHeader[t]=="off") { UnitOffColumn=t; } else if(vecUnitHeader[t]=="P_H") { UnitP_HColumn=t; } else if(vecUnitHeader[t]=="P_L") { UnitP_LColumn=t; } else if(vecUnitHeader[t]=="Q_H") { UnitQ_HColumn=t; } else if(vecUnitHeader[t]=="Q_L") { UnitQ_LColumn=t; } else if(vecUnitHeader[t]=="Volt") { UnitVoltColumn=t; } else continue; } const int UnitEqColumnConst=UnitEqColumn;//识别表头 const int UnitV_RateColumnConst=UnitV_RateColumn; const int UnitP_RateColumnConst=UnitP_RateColumn; const int UnitTopoNodeColumnConst=UnitTopoNodeColumn; const int UnitPColumnConst=UnitPColumn; const int UnitQColumnConst=UnitQColumn; const int UnitUeColumnConst=UnitUeColumn; const int UnitAngColumnConst=UnitAngColumn; const int UnitOffColumnConst=UnitOffColumn; const int UnitP_HColumnConst=UnitP_HColumn; const int UnitP_LColumnConst=UnitP_LColumn; const int UnitQ_HColumnConst=UnitQ_HColumn; const int UnitQ_LColumnConst=UnitQ_LColumn; const int UnitVoltColumnConst=UnitVoltColumn; //记录所需要行列的位置 str.clear();//其中一行数据是不需要的,先清除一行数据 getline(input,str); str.clear(); getline(input,str); while(str!="</Unit::nx>") { vector<string> vec=split(str); //所有数据都已经存放在vec中,接下来是选出有用数据,对数所进行转换 bool eq=stringToBool(vec[UnitEqColumnConst]); double v_Rate=stringToDouble(vec[UnitV_RateColumnConst]); double p_Rate=stringToDouble(vec[UnitP_RateColumnConst]); string topoNode=vec[UnitTopoNodeColumnConst]; double p=stringToDouble(vec[UnitPColumnConst]); double q=stringToDouble(vec[UnitQColumnConst]); double ue=stringToDouble(vec[UnitUeColumnConst]); double ang=stringToDouble(vec[UnitAngColumnConst]); bool off=stringToBool(vec[UnitOffColumnConst]); double p_H=stringToDouble(vec[UnitP_HColumnConst]); double p_L=stringToDouble(vec[UnitP_LColumnConst]); double q_H=stringToDouble(vec[UnitQ_HColumnConst]); double q_L=stringToDouble(vec[UnitQ_LColumnConst]); int volt=stringToInt(vec[UnitVoltColumnConst]); //在bus表中找到对应的节点才创建ACline对象 Unit unit=createUnit(eq,v_Rate,p_Rate,topoNode,p,q,ue,ang,off, p_H,p_L,q_H,q_L,volt); vecUnit.push_back(unit); str.clear(); getline(input,str); } } if(str=="</Unit::nx>") break; } }
AStruct WolframCAMesh::generateMesh(std::vector<std::string> params) { AStruct astruct; int ruleSet = 1; int caSize = 50; int iterations = 50; int numColors = 2; int initialState = 1; float scale = 1; Ogre::Vector3 offset(0, 0, 0); for(int i = 0; i < params.size(); ++i) { switch(i) { case CARuleSet: ruleSet = stringToDouble(params[i]); break; case CASize: caSize = stringToDouble(params[i]); break; case CAIterations: iterations = stringToDouble(params[i]); break; case CANumColors: numColors = stringToDouble(params[i]); break; case CAInitialState: initialState = stringToDouble(params[i]); case CAScale: scale = stringToDouble(params[i]); break; } } offset.x -= (caSize * scale); offset.y -= (iterations * scale); offset.z -= ((numColors - 1) * scale); Automata automata; WolframCA ca(ruleSet, numColors, initialState, caSize); for(int i = 0; i < iterations; ++i) { automata.history.push_back(ca.getCurrentState()); ca.advance(); } for(int y = 0; y < automata.history.size(); ++y) { for(int x = 0; x < automata.history[y].size(); ++x) { unsigned int color = automata.history[y][x]; if(color > 0) Degenerator::cube(Ogre::Vector3((x * scale * 2), y * scale * 2, color * scale * 2) + offset, scale, astruct); } } astruct.mode = TriangleList; return astruct; }
AStruct WolframCA3DMesh::generateMesh(std::vector<std::string> params) { AStruct astruct; int ruleSet = 1; int width = 50; int depth = 50; int iterations = 50; int initIterations = 0; int numColors = 2; int initialState = 1; float scale = 1; bool randInit = false; Ogre::Vector3 offset(0, 0, 0); for(int i = 0; i < params.size(); ++i) { switch(i) { case CA3DRuleSet: ruleSet = stringToDouble(params[i]); break; case CA3DWidth: width = stringToDouble(params[i]); break; case CA3DDepth: depth = stringToDouble(params[i]); break; case CA3DIterations: iterations = stringToDouble(params[i]); break; case CA3DInitIterations: initIterations = stringToDouble(params[i]); break; case CA3DNumColors: numColors = stringToDouble(params[i]); break; case CA3DInitialState: initialState = stringToDouble(params[i]); break; case CA3DScale: scale = stringToDouble(params[i]); break; case CA3DRandInit: if(params[i].compare("true") == 0 || params[i].compare(" true") == 0) randInit = true; break; } } offset.x -= ((width * scale) / 2.0); offset.y -= ((iterations * scale) / 2.0); offset.z -= ((depth * scale) / 2.0); std::vector<slice_t> grid; WolframCA3D ca(ruleSet, numColors, initialState, width, depth); if(randInit) ca.randomizeCurrentState(); for(int i = 0; i < initIterations; ++i) { ca.advance(); } for(int i = 0; i < iterations; ++i) { grid.push_back(ca.getCurrentState()); ca.advance(); } for(int y = 0; y < grid.size(); ++y) { for(int z = 0; z < grid[y].size(); ++z) { for(int x = 0; x < grid[y][z].size(); ++x) { unsigned int color = grid[y][z][x]; if(color > 0) { Degenerator::cube(Ogre::Vector3(x * scale, y * scale, z * scale) + offset, scale, astruct); } } } } astruct.mode = TriangleList; return astruct; }
template<> double stringTo(const std::string& s) { return stringToDouble(s); }
ZLDoubleOption::ZLDoubleOption(const ZLCategoryKey &category, const std::string &groupName, const std::string &optionName, double defaultValue) : ZLOption(category, groupName, optionName), myDefaultValue(stringToDouble(getDefaultConfigValue(), defaultValue)) { }
Counts getThisVariantCounts(const std::vector<std::string>& fields) { Counts thisVariantCounts; bool hasGQ = false; bool hasDP = false; bool hasSGB = false; thisVariantCounts.individualsWithVariant.assign((fields.size()-NUM_NON_GENOTYPE_COLUMNS),0); thisVariantCounts.haplotypesWithVariant.assign((fields.size()-NUM_NON_GENOTYPE_COLUMNS)*2,0); //std::cerr << "Fields: " << (fields.size()-NUM_NON_GENOTYPE_COLUMNS) << std::endl; // Find the position of DP (per sample read depth) in the genotypeData vector below std::vector<std::string> format = split(fields[8], ':'); std::vector<std::string>::iterator DPit; int DPi = std::numeric_limits<int>::min(); DPit = find (format.begin(), format.end(), "DP"); if (DPit == format.end()) { // std::cerr << "This variant hasn't got associated per-sample DP info" << std::endl; } else { DPi = (int)std::distance( format.begin(), DPit ); hasDP = true; } // Find the position of GQ (genotype quality) in the genotypeData vector below std::vector<std::string>::iterator GQit; int GQi = std::numeric_limits<int>::min(); GQit = find (format.begin(), format.end(), "GQ"); if (GQit == format.end()) { // std::cerr << "This variant hasn't got associated per-sample GQ info" << std::endl; } else { GQi = (int)std::distance( format.begin(), GQit ); hasGQ = true; } if (fields[NUM_NON_GENOTYPE_COLUMNS][1] == '|') { thisVariantCounts.bPhased = true; } for (std::vector<std::string>::size_type i = NUM_NON_GENOTYPE_COLUMNS; i != fields.size(); i++) { char v1 = fields[i][0]; char v2 = fields[i][2]; if (thisVariantCounts.bPhased == false) { if ((v1 == '0' && v2 == '1') || (v1 == '1' && v2 == '0')) { double r = ((double) rand() / (RAND_MAX)); if (r > 0.5) { v1 = '0'; v2 = '1'; } else { v1 = '1'; v2 = '0'; } } } if (v1 == '1') { thisVariantCounts.overall++; thisVariantCounts.individualsWithVariant[i- NUM_NON_GENOTYPE_COLUMNS]++; thisVariantCounts.haplotypesWithVariant[2*(i-NUM_NON_GENOTYPE_COLUMNS)]++; } if (v2 == '1') { thisVariantCounts.overall++; thisVariantCounts.individualsWithVariant[i-NUM_NON_GENOTYPE_COLUMNS]++; thisVariantCounts.haplotypesWithVariant[2*(i-NUM_NON_GENOTYPE_COLUMNS)+1]++; } std::vector<std::string> genotypeData = split(fields[i], ':'); // read depth at the variant site per individual if (hasDP && fields[i][0] != '.') { if (atoi(genotypeData[DPi].c_str()) < thisVariantCounts.minimumDepthInAnIndividual) { thisVariantCounts.minimumDepthInAnIndividual = atoi(genotypeData[DPi].c_str()); } thisVariantCounts.depthPerIndividual.push_back(atoi(genotypeData[DPi].c_str())); } // genotype quality at the variant site per individual if (hasGQ && fields[i][0] != '.') { thisVariantCounts.genotypeQualitiesPerIndividual.push_back(atoi(genotypeData[GQi].c_str())); } } // Also get overall depth for this variant std::vector<std::string> info = split(fields[7], ';'); std::vector<std::string>::iterator overallDPit; int overallDPi = std::numeric_limits<int>::min(); overallDPit = find_if(info.begin(), info.end(), isDPinfo); if (overallDPit == info.end()) { // std::cerr << "This variant hasn't got associated overall DP info" << std::endl; thisVariantCounts.overallDepth = 0; } else { overallDPi = (int)std::distance( info.begin(), overallDPit ); std::vector<std::string> overallDP = split(info[overallDPi], '='); thisVariantCounts.overallDepth = atoi((overallDP.back()).c_str()); } // Find the position of SGB (Segregation based metric) in the genotypeData vector below std::vector<std::string>::iterator SGBit; int SGBi = std::numeric_limits<int>::min(); SGBit = find_if(format.begin(), format.end(), isSGBinfo); if (SGBit != format.end()) { // std::cerr << "This variant hasn't got associated per-sample GQ info" << std::endl; } else { SGBi = (int)std::distance( format.begin(), SGBit ); std::vector<std::string> overallSGB = split(info[SGBi], '='); thisVariantCounts.SGB = stringToDouble(overallSGB.back()); } // And get FS (phred-scaled strand-bias p-val) for this variant std::vector<std::string>::iterator FSit; int FSi = std::numeric_limits<int>::min(); FSit = find_if(info.begin(), info.end(), isFSinfo); if (FSit == info.end()) { // Or at least MQSB: Mann-Whitney U test of Mapping Quality vs Strand Bias FSit = find_if(info.begin(), info.end(), isMQSBinfo); if (FSit != info.end()) { FSi = (int)std::distance( info.begin(), FSit ); std::vector<std::string> overallFS = split(info[FSi], '='); thisVariantCounts.MQSBpval = overallFS.back(); } else { // std::cerr << "This variant hasn't got associated FS (strand-bias) info" << std::endl; } } else { FSi = (int)std::distance( info.begin(), FSit ); std::vector<std::string> overallFS = split(info[FSi], '='); thisVariantCounts.FSpval = overallFS.back(); } // And the inbreeding coefficient thisVariantCounts.inbreedingCoefficient = calculateInbreedingCoefficient(thisVariantCounts.individualsWithVariant); return thisVariantCounts; }
//!Parse the stringList from model import bool transitionFuncParam::parse(stringList& lst, tracks& trcks, weights* wts, StateFuncs* funcs) { size_t idx; //FUNCTION NAME (REQUIRED) if (lst.contains("FUNCTION")) { idx=lst.indexOf("FUNCTION"); idx++; transFuncName = lst[idx]; if (funcs!=NULL) { transFunc = funcs->getTransitionFunction(transFuncName); } } else { std::cerr << "Tag was parsed but contains no FUNCTION: . Please check the formatting of the tags\n" << std::endl; return false; //errorInfo(sCantParseLine, "Tag was parsed but contains no FUNCTION: . Please check the formatting of the tags\n"); } //Implement Which track to pass to function if (lst.contains("TRACK")) { idx=lst.indexOf("TRACK"); idx++; trackName=lst[idx]; transFuncTrack = trcks.getTrack(trackName); } else { std::cerr << "Tag was parsed but contains no TRACK: . Please check the formatting of the tags\n" << std::endl; return false; //errorInfo(sCantParseLine, "Tag was parsed but contains no TRACK: . Please check the formatting of the tags\n"); } if (lst.contains("SCALE")) { idx=lst.indexOf("SCALE"); idx++; if (isNumeric(lst[idx])) { transFuncScaling = new(std::nothrow) weight; if (transFuncScaling==NULL) { std::cerr << "OUT OF MEMORY\nFile" << __FILE__ << "Line:\t"<< __LINE__ << std::endl; exit(1); } double tempValue; if (!stringToDouble(lst[idx], tempValue)) { std::cerr << "Ambiguous Value couldn't be parsed: "<< lst[idx] << std::endl; return false; } transFuncScaling->setAbsolute(tempValue); } else { std::string weightName=lst[idx]; if (wts->count(weightName)) { transFuncScaling = (*wts)[weightName]; } } } //Process Traceback Commands //Parse the TO Traceback Labels in the function tag const std::string tbLabels[]= {"TO_LABEL","TB->LABEL","TO_GFF","TB->GFF","TO_STATE","TB->STATE","TO_START","TB->START","DIFF_STATE"}; const tracebackIdentifier typs[]= {STATE_LABEL,STATE_LABEL,STATE_GFF,STATE_GFF,STATE_NAME,STATE_NAME,START_INIT,START_INIT,DIFF_STATE}; for(int i=0; i<9; i++) { if (lst.contains(tbLabels[i])) { transFuncTraceback=true; idx=lst.indexOf(tbLabels[i]); transFuncTracebackIdentifier=typs[i]; if (typs[i]!=START_INIT || typs[i]!=DIFF_STATE) { transFuncTracebackString=lst[idx+1]; } } } // Parse the Combine tags if (transFuncTraceback) { //Process Traceback Combining Commands std::string combineLabels[] = {"COMBINE_LABEL","COMBINE_GFF","COMBINE_STATE", "NO_COMBINE"}; const combineIdentifier comtyps[] = {STATELABEL,STATEGFF,STATENAME,FULL}; bool combineTypeProvided=false; for(int i=0; i<4; i++) { if (lst.contains(combineLabels[i])) { idx=lst.indexOf(combineLabels[i]); transFuncCombineIdentifier=comtyps[i]; transFuncCombineString=lst[idx+1]; combineTypeProvided=true; } } if (!combineTypeProvided) { std::cerr << "Transition Function tag with a traceback was called, but no CombineType was provided. If no traceback is needed then please remove traceback command. \n" << std::endl; return false; //errorInfo(sTagIncorrect, "Transition Function tag with a traceback was called, but no CombineType was provided. If no traceback is needed then please remove traceback command. \n"); } } return true; }
void getBusData(ifstream& input,vector<Bus>& vecBus) {//读取所有节点信息 if(!input) return; string str; while(1) { str.clear(); getline(input,str); if(str=="<Bus::nx type=全数>") { int i=0; str.clear(); getline(input,str); vector<string> vecBusHeader=split(str); int busNameColumn(0);//识别表头 int busVoltColumn(0); int busVColumn(0); int busAngColumn(0); int busOffColumn(0); int busV_maxColumn(0); int busV_minColumn(0); for(size_t t=0;t<vecBusHeader.size();++t) { if(vecBusHeader[t]=="node") { busNameColumn=t; } else if(vecBusHeader[t]=="volt") { busVoltColumn=t; } else if(vecBusHeader[t]=="V") { busVColumn=t; } else if(vecBusHeader[t]=="Ang") { busAngColumn=t; } else if(vecBusHeader[t]=="off") { busOffColumn=t; } else if(vecBusHeader[t]=="v_max") { busV_maxColumn=t; } else if(vecBusHeader[t]=="v_min") { busV_minColumn=t; } else continue; } const int busNameColumnConst=busNameColumn; const int busVoltColumnConst=busVoltColumn; const int busVColumnConst=busVColumn; const int busAngColumnConst=busAngColumn; const int busOffColumnConst=busOffColumn; const int busV_maxColumnConst=busV_maxColumn; const int busV_minColumnConst=busV_minColumn; //记录所需要行列的位置 str.clear();//其中一行数据是不需要的,先清除一行数据 getline(input,str); str.clear(); getline(input,str); while(str!="</Bus::nx>") { vector<string> vec=split(str); //所有数据都已经存放在vec中,接下来是选出有用数据,对数所进行转换 int volt=stringToInt(vec[busVoltColumnConst]); double v=stringToDouble(vec[busVColumnConst]); double ang=stringToDouble(vec[busAngColumnConst]); bool off=stringToBool(vec[busOffColumnConst]); double V_max=stringToDouble(vec[busV_maxColumnConst]); double V_min=stringToDouble(vec[busV_minColumnConst]); Bus bus=createBus(i,vec[busNameColumnConst],volt,v,ang,off,V_max,V_min); size_t t=0; for(;t<vecBus.size();++t) { if(vecBus[t]==bus) { str.clear(); getline(input,str); break; } } if(t<vecBus.size())continue; vecBus.push_back(bus); i++; str.clear(); getline(input,str); } } if(str=="</Bus::nx>") break; } }
void getLoadData(ifstream& input,vector<Load>& vecLoad) {//读取所有节点或其他信息函数 if(!input) return; string str; while(1) { str.clear(); getline(input,str); if(str=="<Load::nx type=全数>") { str.clear(); getline(input,str); vector<string> vecLoadHeader=split(str); int loadVoltColumn(0);//识别表头 int loadEqColumn(0); int loadNodeColumn(0); int loadPColumn(0); int loadQColumn(0); int loadOffColumn(0); for(size_t t=0;t<vecLoadHeader.size();++t) { if(vecLoadHeader[t]=="volt") { loadVoltColumn=t; } else if(vecLoadHeader[t]=="Eq") { loadEqColumn=t; } else if(vecLoadHeader[t]=="node") { loadNodeColumn=t; } else if(vecLoadHeader[t]=="P") { loadPColumn=t; } else if(vecLoadHeader[t]=="Q") { loadQColumn=t; } else if(vecLoadHeader[t]=="off") { loadOffColumn=t; } else continue; } const int loadVoltColumnConst=loadVoltColumn; const int loadEqColumnConst=loadEqColumn; const int loadNodeColumnConst=loadNodeColumn; const int loadPColumnConst=loadPColumn; const int loadQColumnConst=loadQColumn; const int loadOffColumnConst=loadOffColumn; //记录所需要行列的位置 str.clear();//其中一行数据是不需要的,先清除一行数据 getline(input,str); str.clear(); getline(input,str); while(str!="</Load::nx>") { vector<string> vec=split(str); //所有数据都已经存放在vec中,接下来是选出有用数据,对数所进行转换 int volt=stringToInt(vec[loadVoltColumnConst]); int eq=stringToInt(vec[loadEqColumnConst]); string node=vec[loadNodeColumnConst]; double p=stringToDouble(vec[loadPColumnConst]); double q=stringToDouble(vec[loadQColumnConst]); bool off=stringToBool(vec[loadOffColumnConst]); Load load=createLoad(volt,eq,node,p,q,off); /*size_t t=0; for(;t<vecLoad.size();++t) { if(vecLoad[t]==load) { str.clear(); getline(input,str); break; } } if(t<vecLoad.size())continue;*/ vecLoad.push_back(load); str.clear(); getline(input,str); } } if(str=="</Load::nx>") break; } }
void ConfigMgr::loadPopulationTiers(const std::string& configFilePath) { rapidxml::file<> xmlFile(configFilePath.c_str()); rapidxml::xml_document<>* xmlDocument = new rapidxml::xml_document<>(); xmlDocument->parse<0>(xmlFile.data()); rapidxml::xml_node<>* populationTiersNode = xmlDocument->first_node("population-tiers", 16, true); // Bevölkerungsgruppen unsigned char index = 1; for (rapidxml::xml_node<>* node = populationTiersNode->first_node("population-tier", 15, true); node != nullptr; node = node->next_sibling("population-tier", 15, true)) { PopulationTier populationTier; populationTier.index = index++; populationTier.name = std::string(node->first_attribute("name", 4, true)->value()); // <advancement> rapidxml::xml_node<>* advancementNode = node->first_node("advancement", 11, true); rapidxml::xml_node<>* advancementMissingGoodsOkNode = advancementNode->first_node("missing-goods-ok", 16, true); if (advancementMissingGoodsOkNode != nullptr) { populationTier.advancementMissingGoodsOk = (unsigned char) stringToUnsignedLong(advancementMissingGoodsOkNode->value()); } rapidxml::xml_node<>* advancementCostsNode = advancementNode->first_node("costs", 5, true); readBuildingCosts(populationTier.advancementCosts, advancementCostsNode); // <needs> rapidxml::xml_node<>* needsNode = node->first_node("needs", 5, true); if (needsNode != nullptr) { // <good> for (rapidxml::xml_node<>* goodNode = needsNode->first_node("good", 4, true); goodNode != nullptr; goodNode = goodNode->next_sibling("good", 4, true)) { std::string goodName = std::string(goodNode->first_attribute("name", 4, true)->value()); NeededGood neededGood; neededGood.good = getGood(goodName); neededGood.consumePerCycle = stringToDouble( goodNode->first_attribute("consume-per-cycle", 17, true)->value()); populationTier.needsGoods.push_back(neededGood); } // <public-building> for (rapidxml::xml_node<>* publicBuildingNode = needsNode->first_node("public-building", 15, true); publicBuildingNode != nullptr; publicBuildingNode = publicBuildingNode->next_sibling("public-building", 15, true)) { std::string mapObjectTypeName = std::string(publicBuildingNode->first_attribute("name", 4, true)->value()); const MapObjectType* mapObjectType = getMapObjectType(mapObjectTypeName); populationTier.needsPublicBuildings.push_back(mapObjectType); } } // sonstige Tags populationTier.maxPopulationPerHouse = (unsigned char) stringToUnsignedLong( node->first_node("max-population-per-house", 24, true)->value()); populationTier.taxesPerInhabitant = stringToDouble( node->first_node("taxes-per-inhabitant", 20, true)->value()); populationTiers.insert(populationTier); Log::info(_("Loaded populationTier '%s'."), populationTier.name.c_str()); } // Nahrungsbedürfnis rapidxml::xml_node<>* foodGoodNode = populationTiersNode->first_node("food-good", 9, true); std::string foodGoodName = std::string(foodGoodNode->first_attribute("name", 4, true)->value()); foodGood.good = getGood(foodGoodName); foodGood.consumePerCycle = stringToDouble( foodGoodNode->first_attribute("consume-per-cycle", 17, true)->value()); // XML-Datei schließen delete xmlDocument; // Jetzt sind alle PopulationTiers geladen. Wir ordnen diese nun den MapObjectTypes zu. for (auto iter = mapObjectTypeToPopulationTierName.cbegin(); iter != mapObjectTypeToPopulationTierName.cend(); iter++) { MapObjectType* mapObjectType = iter->first; const std::string& populationTierString = iter->second; const PopulationTier* populationTier = getPopulationTier(populationTierString); if (populationTier == nullptr) { throw ErrorInConfigException(string_sprintf( _("Illegal value '%s' for populationTier."), populationTierString.c_str())); } mapObjectType->populationTier = populationTier; } mapObjectTypeToPopulationTierName.clear(); // Daten wegräumen, brauchen wir nicht mehr }
bool parseInertial(Inertial &i, TiXmlElement *config) { i.clear(); // Origin TiXmlElement *o = config->FirstChildElement("origin"); if (o) { if (!parsePose(i.origin, o)) return false; } TiXmlElement *mass_xml = config->FirstChildElement("mass"); if (!mass_xml) { logError("Inertial element must have a mass element"); return false; } if (!mass_xml->Attribute("value")) { logError("Inertial: mass element must have value attribute"); return false; } if( !stringToDouble(mass_xml->Attribute("value"),i.mass) ) { std::stringstream stm; stm << "Inertial: mass [" << mass_xml->Attribute("value") << "] is not a float"; logError(stm.str().c_str()); return false; } TiXmlElement *inertia_xml = config->FirstChildElement("inertia"); if (!inertia_xml) { logError("Inertial element must have inertia element"); return false; } if (!(inertia_xml->Attribute("ixx") && inertia_xml->Attribute("ixy") && inertia_xml->Attribute("ixz") && inertia_xml->Attribute("iyy") && inertia_xml->Attribute("iyz") && inertia_xml->Attribute("izz"))) { logError("Inertial: inertia element must have ixx,ixy,ixz,iyy,iyz,izz attributes"); return false; } if( !stringToDouble(inertia_xml->Attribute("ixx"),i.ixx) || !stringToDouble(inertia_xml->Attribute("ixy"),i.ixy) || !stringToDouble(inertia_xml->Attribute("ixz"),i.ixz) || !stringToDouble(inertia_xml->Attribute("iyy"),i.iyy) || !stringToDouble(inertia_xml->Attribute("iyz"),i.iyz) || !stringToDouble(inertia_xml->Attribute("izz"),i.izz) ) { std::stringstream stm; stm << "Inertial: one of the inertia elements is not a valid double:" << " ixx [" << inertia_xml->Attribute("ixx") << "]" << " ixy [" << inertia_xml->Attribute("ixy") << "]" << " ixz [" << inertia_xml->Attribute("ixz") << "]" << " iyy [" << inertia_xml->Attribute("iyy") << "]" << " iyz [" << inertia_xml->Attribute("iyz") << "]" << " izz [" << inertia_xml->Attribute("izz") << "]"; logError(stm.str().c_str()); return false; } return true; }
bool UnlabelledClassificationData::loadDatasetFromCSVFile(string filename){ fstream file; string value; UINT numFeatures = 0; datasetName = "NOT_SET"; infoText = ""; //Clear any previous data clear(); //Try and open the file file.open( filename.c_str(), std::ios::in ); if( !file.is_open() ){ errorLog << "loadDatasetFromCSVFile(string filename) - Failed to open file!" << endl; return false; } //Read the first line to work out how many features are in the data getline( file, value ); for(UINT i=0; i<value.size(); i++){ if( value[i] == ',' ){ numFeatures++; } } //There will be one more feature at the end so add this numFeatures++; //If there are no commas in the first line then the data is not in the correct format if( numFeatures == 0 ){ errorLog << "loadDatasetFromCSVFile(string filename) - Failed to find any features in the file - there appear to be no commas in the first row!" << endl; return false; } cout << "NUM FEATURES: " << numFeatures << endl; //Setup the labelled classification data setNumDimensions( numFeatures ); //Reset the file to read from the start file.seekg( ios_base::beg ); //Read the data UINT lineCounter = 0; vector< double > sample(numFeatures,0); while ( file.good() ) { //Read the value getline( file, value, ',' ); sample[ lineCounter ] = stringToDouble( value ); if( ++lineCounter == numFeatures+1 ){ lineCounter = 0; addSample(sample); } } file.close(); return true; }
void getAClineData(ifstream& input,vector<ACline>& vecACline) {//读取所有ACline if(!input) return; string str; while(1) { str.clear(); getline(input,str); if(str=="<ACline::nx type=全数>") {//需要先读取很多行无用信息才能找到目标行,检索方法可以考虑改进 int i=0; str.clear(); getline(input,str); vector<string> vecAClineHeader=split(str); int AClineNameColumn(0);//识别表头 int AClineVoltColumn(0); int AClineRColumn(0); int AClineXColumn(0); int AClineBColumn(0); int AClineI_nodeColumn(0); int AClineJ_nodeColumn(0); int AClineI_PColumn(0); int AClineI_QColumn(0); int AClineJ_PColumn(0); int AClineJ_QColumn(0); int AClineImaxColumn(0); int AClineAreaColumn(0); int AClineI_offColumn(0); int AClineJ_offColumn(0); for(size_t t=0;t<vecAClineHeader.size();++t) {//考虑用枚举替换,更清晰 if(vecAClineHeader[t]=="name") { AClineNameColumn=t; } else if(vecAClineHeader[t]=="volt") { AClineVoltColumn=t; } else if(vecAClineHeader[t]=="R") { AClineRColumn=t; } else if(vecAClineHeader[t]=="X") { AClineXColumn=t; } else if(vecAClineHeader[t]=="B") { AClineBColumn=t; } else if(vecAClineHeader[t]=="I_node") { AClineI_nodeColumn=t; } else if(vecAClineHeader[t]=="J_node") { AClineJ_nodeColumn=t; } else if(vecAClineHeader[t]=="I_P") { AClineI_PColumn=t; } else if(vecAClineHeader[t]=="I_Q") { AClineI_QColumn=t; } else if(vecAClineHeader[t]=="J_P") { AClineJ_PColumn=t; } else if(vecAClineHeader[t]=="J_Q") { AClineJ_QColumn=t; } else if(vecAClineHeader[t]=="Imax") { AClineImaxColumn=t; } else if(vecAClineHeader[t]=="area") { AClineAreaColumn=t; } else if(vecAClineHeader[t]=="I_off") { AClineI_offColumn=t; } else if(vecAClineHeader[t]=="J_off") { AClineJ_offColumn=t; } else continue; } const int AClineNameColumnConst=AClineNameColumn; const int AClineVoltColumnConst=AClineVoltColumn; const int AClineRColumnConst=AClineRColumn; const int AClineXColumnConst=AClineXColumn; const int AClineBColumnConst=AClineBColumn; const int AClineI_nodeColumnConst=AClineI_nodeColumn; const int AClineJ_nodeColumnConst=AClineJ_nodeColumn; const int AClineI_PColumnConst=AClineI_PColumn; const int AClineI_QColumnConst=AClineI_QColumn; const int AClineJ_PColumnConst=AClineJ_PColumn; const int AClineJ_QColumnConst=AClineJ_QColumn; const int AClineImaxColumnConst=AClineImaxColumn; const int AClineAreaColumnConst=AClineAreaColumn; const int AClineI_offColumnConst=AClineI_offColumn; const int AClineJ_offColumnConst=AClineJ_offColumn; //记录所需要行列的位置 str.clear();//其中一行数据是不需要的,先清除一行数据 getline(input,str); str.clear(); getline(input,str); while(str!="</ACline::nx>") { vector<string> vec=split(str); //所有数据都已经存放在vec中,接下来是选出有用数据,对数所进行转换 int volt=stringToInt(vec[AClineVoltColumnConst]); string name=vec[AClineNameColumnConst]; double r=stringToDouble(vec[AClineRColumnConst]); double x=stringToDouble(vec[AClineXColumnConst]); double b=stringToDouble(vec[AClineBColumnConst]); string i_nodename=vec[AClineI_nodeColumnConst]; string j_nodename=vec[AClineJ_nodeColumnConst]; double i_p=stringToDouble(vec[AClineI_PColumnConst]); double i_q=stringToDouble(vec[AClineI_QColumnConst]); double j_p=stringToDouble(vec[AClineJ_PColumnConst]); double j_q=stringToDouble(vec[AClineJ_QColumnConst]); double imax=stringToDouble(vec[AClineImaxColumnConst]); string area=vec[AClineAreaColumnConst]; bool iOff=stringToBool(vec[AClineI_offColumnConst]); bool jOff=stringToBool(vec[AClineJ_offColumnConst]); //判断ACline两端节点是否都在Bus表内,并找到对应的拓扑节点编号,满足则为有用信息 /*int i_node=0; int j_node=0;//拓扑节点编号 //理论上是不可能存在相同节点的 if(i_nodename==j_nodename)continue; for(vector<Bus>::iterator iter=vecBus.begin();iter!=vecBus.end();++iter) { if(i_nodename==iter->getBusName()) i_node=iter->getBusCode(); else if(j_nodename==iter->getBusName()) j_node=iter->getBusCode(); }*/ //在bus表中找到对应的节点才创建ACline对象 ACline acline=createACline(i,name,volt,r,x,b,i_nodename,j_nodename, i_p,i_q,j_p,j_q,imax,area,iOff,jOff); size_t t=0; for(;t<vecACline.size();++t) {//判断是否存在相同支路,其实没必要检索整个容器,只需检索前若干个 //其实没必要判断,不会出现相同支路 if(vecACline[t]==acline) { str.clear(); getline(input,str); break; } } if(t<vecACline.size())continue; vecACline.push_back(acline); i++; str.clear(); getline(input,str); } } if(str=="</ACline::nx>") break; } }
//!Parse the stringList from model import bool emissionFuncParam::parse(stringList& lst, tracks& trcks, weights* wts, StateFuncs* funcs) { size_t idx; //FUNCTION NAME (REQUIRED) if (lst.contains("FUNCTION")) { idx=lst.indexOf("FUNCTION"); idx++; emissionFuncName = lst[idx]; if (funcs!=NULL) { emissionFunction = funcs->getEmissionFunction(emissionFuncName); } } else { std::cerr << "Tag was parsed but contains no FUNCTION: . Please check the formatting of the tags\n" << std::endl; return false; //errorInfo(sCantParseLine, "Tag was parsed but contains no FUNCTION: . Please check the formatting of the tags\n"); } //Implement Which track to pass to function if (lst.contains("TRACK")) { idx=lst.indexOf("TRACK"); idx++; trackName=lst[idx]; emissionFuncTrack = trcks.getTrack(trackName); trackNumber = emissionFuncTrack->getIndex(); } else { std::cerr << "Tag was parsed but contains no TRACK: . Please check the formatting of the tags\n" << std::endl; return false; //errorInfo(sCantParseLine, "Tag was parsed but contains no TRACK: . Please check the formatting of the tags\n"); } if (lst.contains("SCALE")) { idx=lst.indexOf("SCALE"); idx++; if (isNumeric(lst[idx])) { emissionFuncScaling = new(std::nothrow) weight; if (emissionFuncScaling==NULL) { std::cerr << "OUT OF MEMORY\nFile" << __FILE__ << "Line:\t"<< __LINE__ << std::endl; exit(1); } double tempValue; if (!stringToDouble(lst[idx], tempValue)) { std::cerr << "SCALE value could not be converted to numerical value: "<< lst[idx] << std::endl; return false; } emissionFuncScaling->setAbsolute(tempValue); } else { std::string weightName=lst[idx]; if (wts->count(weightName)) { emissionFuncScaling = (*wts)[weightName]; } } } return true; }
void getTopoNode(ifstream& input,vector<TopoNode>& vecTopoNode) {//读取所有ACline if(!input) return; string str; while(1) { str.clear(); getline(input,str); if(str=="<TopoNode::nx type=全数>") {//需要先读取很多行无用信息才能找到目标行,检索方法可以考虑改进 str.clear(); getline(input,str); vector<string> vecTopoNodeHeader=split(str); int TopoNodeNameColumn(0);//识别表头 int TopoNodeVColumn(0); int TopoNodeAngColumn(0); int TopoNodeVbaseColumn(0); for(size_t t=0;t<vecTopoNodeHeader.size();++t) {//考虑switch,更清晰 if(vecTopoNodeHeader[t]=="name") { TopoNodeNameColumn=t; } else if(vecTopoNodeHeader[t]=="v") { TopoNodeVColumn=t; } else if(vecTopoNodeHeader[t]=="ang") { TopoNodeAngColumn=t; } else if(vecTopoNodeHeader[t]=="vbase") { TopoNodeVbaseColumn=t; } else continue; } const int TopoNodeNameColumnConst=TopoNodeNameColumn; const int TopoNodeVColumnConst=TopoNodeVColumn; const int TopoNodeAngColumnConst=TopoNodeAngColumn; const int TopoNodeVbaseColumnConst=TopoNodeVbaseColumn; //记录所需要行列的位置 str.clear();//其中一行数据是不需要的,先清除一行数据 getline(input,str); str.clear(); getline(input,str); while(str!="</TopoNode::nx>") { vector<string> vec=split(str); //所有数据都已经存放在vec中,接下来是选出有用数据,对数所进行转换 string name=vec[TopoNodeNameColumnConst]; double v=stringToDouble(vec[TopoNodeVColumnConst]); double ang=stringToDouble(vec[TopoNodeAngColumnConst]); double vbase=stringToDouble(vec[TopoNodeVbaseColumnConst]); //在bus表中找到对应的节点才创建ACline对象 TopoNode topoNode=createTopoNode(name,v,ang,vbase); size_t t=0; for(;t<vecTopoNode.size();++t) {//判断是否存在相同支路,其实没必要检索整个容器,只需检索前若干个 if(vecTopoNode[t]==topoNode) { str.clear(); getline(input,str); break; } } if(t<vecTopoNode.size())continue; vecTopoNode.push_back(topoNode); str.clear(); getline(input,str); } } if(str=="</TopoNode::nx>") break; } }
void scannerFillToken(Token *token) { ScannerState state = SS_Empty; int32_t symbol = 0; char hexCode = 0; char hexCodeBackup = 0; String *tokenStr = &(token->str); while (1) { if (charStreamSwitch) { symbol = getc(source); } else { symbol = lastChar; charStreamSwitch = 1; } switch (state) { case SS_Empty: { if ((symbol >= 'a' && symbol <= 'z') || (symbol >= 'A' && symbol <= 'Z') || (symbol == '_')) { state = SS_Identifier; initString(tokenStr); stringPush(tokenStr,symbol); } else if (symbol >= '0' && symbol <= '9') { state = SS_Number; initString(tokenStr); stringPush(tokenStr,symbol); } else if (isspace(symbol)) { ; } else if (symbol == EOF) { token->type = STT_EOF; return; } else { switch (symbol) { case '"': state = SS_String; initString(tokenStr); break; case '/': state = SS_Divide; break; case '!': state = SS_Exclamation; break; case ';': token->type = STT_Semicolon; return; case '{': token->type = STT_LeftCurlyBracket; return; case '}': token->type = STT_RightCurlyBracket; return; case '*': token->type = STT_Multiply; return; case '+': token->type = STT_Plus; return; case '-': token->type = STT_Minus; return; case '(': token->type = STT_LeftBracket; return; case ')': token->type = STT_RightBracket; return; case ',': token->type = STT_Comma; return; case '.': token->type = STT_Dot; return; case '>': state = SS_Greater; break; case '<': state = SS_Less; break; case '=': state = SS_Assignment; break; case '$': state = SS_Dollar; break; case '&': state = SS_And; break; case '|': state = SS_Or; break; default: setError(ERR_LexFile); return; } } break; } case SS_Greater: { if (symbol == '=') { token->type = STT_GreaterEqual; return; } else { lastChar = symbol; charStreamSwitch = 0; token->type = STT_Greater; return; } } case SS_Less: { if (symbol == '=') { token->type = STT_LessEqual; return; } else if (symbol == '?') { state = SS_Php_0; } else { lastChar = symbol; charStreamSwitch = 0; token->type = STT_Less; return; } break; } case SS_Assignment: { if (symbol == '=') { state = SS_Equal; } else { lastChar = symbol; charStreamSwitch = 0; token->type = STT_Assignment; return; } break; } case SS_Dollar: { if ((symbol >= 'a' && symbol <= 'z') || (symbol >= 'A' && symbol <= 'Z') || (symbol == '_')) { state = SS_Variable; initString(tokenStr); stringPush(tokenStr, symbol); break; } else { setError(ERR_LexFile); return; } break; } case SS_Variable: { if ((symbol >= 'a' && symbol <= 'z') || (symbol >= 'A' && symbol <= 'Z') || (symbol == '_') || (symbol >= '0' && symbol <= '9')) { stringPush(tokenStr, symbol); state = SS_Variable; } else { lastChar = symbol; charStreamSwitch = 0; token->type = STT_Variable; return; } break; } case SS_Number: { if (symbol >= '0' && symbol <= '9') { state = SS_Number; stringPush(tokenStr, symbol); } else if (symbol == '.') { state = SS_DoubleDecPoint; stringPush(tokenStr, symbol); } else if ((symbol == 'e') || (symbol == 'E')) { state = SS_DoubleExponent; stringPush(tokenStr, symbol); } else { lastChar = symbol; charStreamSwitch = 0; int n = stringToInt(tokenStr); deleteString(tokenStr); token->n = n; token->type = STT_Number; return; } break; } case SS_DoubleDecPoint: { if (symbol >= '0' && symbol <= '9') { state = SS_DoubleDecPart; stringPush(tokenStr, symbol); } else { deleteString(tokenStr); setError(ERR_LexFile); return; } break; } case SS_DoubleExponent: { if (symbol >= '0' && symbol <= '9') { state = SS_DoubleExpPart; stringPush(tokenStr, symbol); } else if ((symbol == '+') || (symbol == '-')) { state = SS_DoubleExpSign; stringPush(tokenStr, symbol); } else { deleteString(tokenStr); setError(ERR_LexFile); return; } break; } case SS_DoubleExpSign: { if (symbol >= '0' && symbol <= '9') { state = SS_DoubleExpPart; stringPush(tokenStr, symbol); } else { deleteString(tokenStr); setError(ERR_LexFile); return; } break; } case SS_Identifier: { if ((symbol == '_') || (symbol >= 'a' && symbol <= 'z') || (symbol >= 'A' && symbol <= 'Z') || (symbol >= '0' && symbol <= '9')) { stringPush(tokenStr, symbol); state = SS_Identifier; } else { lastChar = symbol; charStreamSwitch = 0; KeywordTokenType keywordType = strToKeyword(tokenStr); // FUNCTION CHECKS IF IDENTIFIER, WHICH HAS BEEN FOUND AINT A RESERVED ( KEYWORD ) WORD if (keywordType == KTT_None) { token->type = STT_Identifier; return; } else { deleteString(tokenStr); if (keywordType == KTT_True) { token->type = STT_Bool; token->n = 1; } else if (keywordType == KTT_False) { token->type = STT_Bool; token->n = 0; } else if (keywordType == KTT_Null) { token->type = STT_Null; } else if (keywordType == KTT_And) { token->type = STT_AndLow; } else if (keywordType == KTT_Or) { token->type = STT_OrLow; } else { token->type = STT_Keyword; token->keywordType = keywordType; } return; } } break; } case SS_DoubleDecPart: { if (symbol >= '0' && symbol <= '9') { state = SS_DoubleDecPart; stringPush(tokenStr, symbol); } else if (symbol == 'e' || symbol == 'E') { state = SS_DoubleExponent; stringPush(tokenStr, symbol); } else { lastChar = symbol; charStreamSwitch = 0; double d = stringToDouble(tokenStr); deleteString(tokenStr); token->d = d; token->type = STT_Double; return; } break; } case SS_DoubleExpPart: { if (symbol >= '0' && symbol <= '9') { state = SS_DoubleExpPart; stringPush(tokenStr, symbol); } else { lastChar = symbol; charStreamSwitch = 0; double d = stringToDouble(tokenStr); deleteString(tokenStr); token->d = d; token->type = STT_Double; return; } break; } case SS_Divide: { if (symbol == '*') { state = SS_BlockComment; } else if (symbol == '/') { state = SS_Comment; } else { lastChar = symbol; charStreamSwitch = 0; token->type = STT_Divide; return; } break; } case SS_BlockComment: { if (symbol == '*') { state = SS_BlockCommentFinish; } else if (symbol == EOF) { setError(ERR_LexFile); return; } else { state = SS_BlockComment; } break; } case SS_BlockCommentFinish: { if (symbol == '/') { state = SS_Empty; } else if (symbol == EOF) { setError(ERR_LexFile); return; } else { state = SS_BlockComment; lastChar = symbol; charStreamSwitch = 0; } break; } case SS_Comment: { if (symbol == '\n') { state = SS_Empty; } else if (symbol == EOF) { token->type = STT_EOF; return; } else { state = SS_Comment; } break; } case SS_Equal: { if (symbol == '=') { token->type = STT_Equal; return; } else { lastChar = symbol; charStreamSwitch = 0; setError(ERR_LexFile); return; } } case SS_Exclamation: { if (symbol == '=') { state = SS_NotEqual; } else { lastChar = symbol; charStreamSwitch = 0; token->type = STT_Not; return; } break; } case SS_NotEqual: { if (symbol == '=') { token->type = STT_NotEqual; return; } else { lastChar = symbol; charStreamSwitch = 0; setError(ERR_LexFile); return; } } case SS_String: { if (symbol == '"') { token->type = STT_String; return; } else if (symbol == EOF) { deleteString(tokenStr); setError(ERR_LexFile); return; } else { if (symbol >= MIN_STRING_CHAR_ASCII && symbol != '$') { if (symbol == '\\') { state = SS_StringEscape; } else { state = SS_String; stringPush(tokenStr, symbol); } } else { deleteString(tokenStr); setError(ERR_LexFile); return; } } break; } case SS_StringEscape: { switch (symbol) { case 'x': { state = SS_StringEscapeHex0; break; } case '$': { state = SS_String; stringPush(tokenStr, symbol); break; } case 'n': { state = SS_String; stringPush(tokenStr, '\n'); break; } case 't': { state = SS_String; stringPush(tokenStr, '\t'); break; } case '\"': { state = SS_String; stringPush(tokenStr, '\"'); break; } case '\\': { state = SS_String; stringPush(tokenStr, '\\'); break; } default: { if (symbol < MIN_STRING_CHAR_ASCII) { setError(ERR_LexFile); return; } state = SS_String; stringPush(tokenStr, '\\'); stringPush(tokenStr, symbol); break; } } break; } case SS_StringEscapeHex0: { if (symbol >= '0' && symbol <= '9') { hexCode = symbol - '0'; state = SS_StringEscapeHex1; } else if (symbol >= 'A' && symbol <= 'F') { hexCode = symbol - 'A' + 10; state = SS_StringEscapeHex1; } else if (symbol >= 'a' && symbol <= 'f') { hexCode = symbol - 'a' + 10; state = SS_StringEscapeHex1; } else { stringPush(tokenStr, '\\'); stringPush(tokenStr, 'x'); lastChar = symbol; charStreamSwitch = 0; state = SS_String; } hexCodeBackup = symbol; break; } case SS_StringEscapeHex1: { if (symbol >= '0' && symbol <= '9') { hexCode = (hexCode << 4) + (symbol - '0'); stringPush(tokenStr, hexCode); state = SS_String; } else if (symbol >= 'A' && symbol <= 'F') { hexCode = (hexCode << 4) + (symbol - 'A' + 10); stringPush(tokenStr, hexCode); state = SS_String; } else if (symbol >= 'a' && symbol <= 'f') { hexCode = (hexCode << 4) + (symbol - 'a' + 10); stringPush(tokenStr, hexCode); state = SS_String; } else { stringPush(tokenStr, '\\'); stringPush(tokenStr, 'x'); stringPush(tokenStr, hexCodeBackup); lastChar = symbol; charStreamSwitch = 0; state = SS_String; } break; } case SS_Php_0: { if (symbol == 'p') { state = SS_Php_1; } else { setError(ERR_Syntax); return; } break; } case SS_Php_1: { if (symbol == 'h') { state = SS_Php_2; } else { setError(ERR_Syntax); return; } break; } case SS_Php_2: { if (symbol == 'p') { state = SS_Php_3; } else { setError(ERR_Syntax); return; } break; } case SS_Php_3: { if (isspace(symbol)) { token->type = STT_Php; return; } else { setError(ERR_Syntax); return; } } case SS_And: if (symbol != '&') { setError(ERR_LexFile); return; } token->type = STT_And; return; case SS_Or: if (symbol != '|') { setError(ERR_LexFile); return; } token->type = STT_Or; return; } } }
void getTransData(ifstream& input,vector<Transformer>& vecTrans) {//读取所有节点或其他信息函数 if(!input) return; string str; while(1) { str.clear(); getline(input,str); if(str=="<Transformer::nx type=全数>") { str.clear(); getline(input,str); vector<string> vecTransHeader=split(str); //识别表头 int transCodeColumn(0); int transTypeColumn(0); int transI_VolColumn(0); int transK_VolColumn(0); int transJ_VolColumn(0); int transI_SColumn(0); int transK_SColumn(0); int transJ_SColumn(0); int transItap_HColumn(0); int transItap_LColumn(0); int transItap_EColumn(0); int transItap_CColumn(0); int transItap_VColumn(0); int transKtap_HColumn(0); int transKtap_LColumn(0); int transKtap_EColumn(0); int transKtap_CColumn(0); int transKtap_VColumn(0); int transJtap_VColumn(0); int transRiColumn(0); int transXiColumn(0); int transRkColumn(0); int transXkColumn(0); int transRjColumn(0); int transXjColumn(0); int transI_nodeColumn(0); int transK_nodeColumn(0); int transJ_nodeColumn(0); int transI_PColumn(0); int transI_QColumn(0); int transK_PColumn(0); int transK_QColumn(0); int transJ_PColumn(0); int transJ_QColumn(0); int transI_tapColumn(0); int transK_tapColumn(0); int transI_offColumn(0); int transK_offColumn(0); int transJ_offColumn(0); for(size_t t=0;t<vecTransHeader.size();++t) { if(vecTransHeader[t]=="id") { transCodeColumn=t; } else if(vecTransHeader[t]=="type") { transTypeColumn=t; } else if(vecTransHeader[t]=="I_Vol") { transI_VolColumn=t; } else if(vecTransHeader[t]=="K_Vol") { transK_VolColumn=t; } else if(vecTransHeader[t]=="J_Vol") { transJ_VolColumn=t; } else if(vecTransHeader[t]=="I_S") { transI_SColumn=t; } else if(vecTransHeader[t]=="K_S") { transK_SColumn=t; } else if(vecTransHeader[t]=="J_S") { transJ_SColumn=t; } else if(vecTransHeader[t]=="Itap_H") { transItap_HColumn=t; } else if(vecTransHeader[t]=="Itap_L") { transItap_LColumn=t; } else if(vecTransHeader[t]=="Itap_E") { transItap_EColumn=t; } else if(vecTransHeader[t]=="Itap_C") { transItap_CColumn=t; } else if(vecTransHeader[t]=="Itap_V") { transItap_VColumn=t; } else if(vecTransHeader[t]=="Ktap_H") { transKtap_HColumn=t; } else if(vecTransHeader[t]=="Ktap_L") { transKtap_LColumn=t; } else if(vecTransHeader[t]=="Ktap_E") { transKtap_EColumn=t; } else if(vecTransHeader[t]=="Ktap_C") { transKtap_CColumn=t; } else if(vecTransHeader[t]=="Ktap_V") { transKtap_VColumn=t; } else if(vecTransHeader[t]=="Jtap_V") { transJtap_VColumn=t; } else if(vecTransHeader[t]=="Ri") { transRiColumn=t; } else if(vecTransHeader[t]=="Xi") { transXiColumn=t; } else if(vecTransHeader[t]=="Rk") { transRkColumn=t; } else if(vecTransHeader[t]=="Xk") { transXkColumn=t; } else if(vecTransHeader[t]=="Rj") { transRjColumn=t; } else if(vecTransHeader[t]=="Xj") { transXjColumn=t; } else if(vecTransHeader[t]=="I_node") { transI_nodeColumn=t; } else if(vecTransHeader[t]=="K_node") { transK_nodeColumn=t; } else if(vecTransHeader[t]=="J_node") { transJ_nodeColumn=t; } else if(vecTransHeader[t]=="I_P") { transI_PColumn=t; } else if(vecTransHeader[t]=="I_Q") { transI_QColumn=t; } else if(vecTransHeader[t]=="K_P") { transK_PColumn=t; } else if(vecTransHeader[t]=="K_Q") { transK_QColumn=t; } else if(vecTransHeader[t]=="J_P") { transJ_PColumn=t; } else if(vecTransHeader[t]=="J_Q") { transJ_QColumn=t; } else if(vecTransHeader[t]=="I_tap") { transI_tapColumn=t; } else if(vecTransHeader[t]=="K_tap") { transK_tapColumn=t; } else if(vecTransHeader[t]=="I_off") { transI_offColumn=t; } else if(vecTransHeader[t]=="K_off") { transK_offColumn=t; } else if(vecTransHeader[t]=="J_off") { transJ_offColumn=t; } else continue; } const int transCodeColumnConst=transCodeColumn; const int transTypeColumnConst=transTypeColumn; const int transI_VolColumnConst=transI_VolColumn; const int transK_VolColumnConst=transK_VolColumn; const int transJ_VolColumnConst=transJ_VolColumn; const int transI_SColumnConst=transI_SColumn; const int transK_SColumnConst=transK_SColumn; const int transJ_SColumnConst=transJ_SColumn; const int transItap_HColumnConst=transItap_HColumn; const int transItap_LColumnConst=transItap_LColumn; const int transItap_EColumnConst=transItap_EColumn; const int transItap_CColumnConst=transItap_CColumn; const int transItap_VColumnConst=transItap_VColumn; const int transKtap_HColumnConst=transKtap_HColumn; const int transKtap_LColumnConst=transKtap_LColumn; const int transKtap_EColumnConst=transKtap_EColumn; const int transKtap_CColumnConst=transKtap_CColumn; const int transKtap_VColumnConst=transKtap_VColumn; const int transJtap_VColumnConst=transJtap_VColumn; const int transRiColumnConst=transRiColumn; const int transXiColumnConst=transXiColumn; const int transRkColumnConst=transRkColumn; const int transXkColumnConst=transXkColumn; const int transRjColumnConst=transRjColumn; const int transXjColumnConst=transXjColumn; const int transI_nodeColumnConst=transI_nodeColumn; const int transK_nodeColumnConst=transK_nodeColumn; const int transJ_nodeColumnConst=transJ_nodeColumn; const int transI_PColumnConst=transI_PColumn; const int transI_QColumnConst=transI_QColumn; const int transK_PColumnConst=transK_PColumn; const int transK_QColumnConst=transK_QColumn; const int transJ_PColumnConst=transJ_PColumn; const int transJ_QColumnConst=transJ_QColumn; const int transI_tapColumnConst=transI_tapColumn; const int transK_tapColumnConst=transK_tapColumn; const int transI_offColumnConst=transI_offColumn; const int transK_offColumnConst=transK_offColumn; const int transJ_offColumnConst=transJ_offColumn; //记录所需要行列的位置 str.clear();//其中一行数据是不需要的,先清除一行数据 getline(input,str); str.clear(); getline(input,str); while(str!="</Transformer::nx>") { vector<string> vec=split(str); //所有数据都已经存放在vec中,接下来是选出有用数据,对数所进行转换 int code=stringToInt(vec[transCodeColumnConst]); int type=stringToInt(vec[transTypeColumnConst]); int i_vol=stringToInt(vec[transI_VolColumnConst]); int k_vol=stringToInt(vec[transK_VolColumnConst]); int j_vol=stringToInt(vec[transJ_VolColumnConst]); int i_s=stringToInt(vec[transI_SColumnConst]); int k_s=stringToInt(vec[transK_SColumnConst]); int j_s=stringToInt(vec[transJ_SColumnConst]); int itap_h=stringToInt(vec[transItap_HColumnConst]); int itap_l=stringToInt(vec[transItap_LColumnConst]); int itap_e=stringToInt(vec[transItap_EColumnConst]); double itap_c=stringToDouble(vec[transItap_CColumnConst]); int itap_v=stringToInt(vec[transItap_VColumnConst]); int ktap_h=stringToInt(vec[transKtap_HColumnConst]); int ktap_l=stringToInt(vec[transKtap_LColumnConst]); int ktap_e=stringToInt(vec[transKtap_EColumnConst]); double ktap_c=stringToDouble(vec[transKtap_CColumnConst]); int ktap_v=stringToInt(vec[transKtap_VColumnConst]); int jtap_v=stringToInt(vec[transJtap_VColumnConst]); double ri=stringToDouble(vec[transRiColumnConst]); double xi=stringToDouble(vec[transXiColumnConst]); double rk=stringToDouble(vec[transRkColumnConst]); double xk=stringToDouble(vec[transXkColumnConst]); double rj=stringToDouble(vec[transRjColumnConst]); double xj=stringToDouble(vec[transXjColumnConst]); string i_node=vec[transI_nodeColumnConst]; // string i_node="abcefdfdfaf"; string k_node=vec[transK_nodeColumnConst]; string j_node=vec[transJ_nodeColumnConst]; double i_p=stringToDouble(vec[transI_PColumnConst]); double i_q=stringToDouble(vec[transI_QColumnConst]); double k_p=stringToDouble(vec[transK_PColumnConst]); double k_q=stringToDouble(vec[transK_QColumnConst]); double j_p=stringToDouble(vec[transJ_PColumnConst]); double j_q=stringToDouble(vec[transJ_QColumnConst]); int i_tap=stringToInt(vec[transI_tapColumnConst]); int k_tap=stringToInt(vec[transK_tapColumnConst]); bool iOff=stringToBool(vec[transI_offColumnConst]); bool kOff=stringToBool(vec[transK_offColumnConst]); bool jOff=stringToBool(vec[transJ_offColumnConst]); //判断Transformer两端节点是否都在Bus表内,并找到对应的拓扑节点编号,满足则为有用信息 /*int i_node=0; int j_node=0;//拓扑节点编号 for(vector<Bus>::iterator iter=vecBus.begin();iter!=vecBus.end();++iter) { if( i_nodename==(*iter).getBusName() ) i_node=(*iter).getBusCode(); if( j_nodename==(*iter).getBusName() ) j_node=(*iter).getBusCode(); }*/ Transformer trans=createTransformer( code, type, i_vol, k_vol, j_vol, i_s, k_s, j_s, itap_h, itap_l, itap_e, itap_c, itap_v, ktap_h, ktap_l, ktap_e, ktap_c, ktap_v, jtap_v, ri, xi, rk, xk, rj, xj, i_node, k_node, j_node, i_p, i_q, k_p, k_q, j_p, j_q, i_tap, k_tap , iOff, kOff, jOff); /*size_t t=0; for(;t<vecTrans.size();++t) { if(vecTrans[t]==trans) { str.clear(); getline(input,str); break; } } if(t<vecTrans.size())continue;*/ vecTrans.push_back(trans); str.clear(); getline(input,str); } } if(str=="</Transformer::nx>") break; } }
/** * Get result and related info * @param bott Original Bott info * @return Result Bott file */ Bott *CCJudger::getStatus(Bott * bott) { time_t begin_time = time(NULL); Bott *result_bott; while (true) { // check wait time if (time(NULL) - begin_time > info->GetMax_wait_time()) { throw Exception ("Failed to get current result, judge time out."); } prepareCurl(); curl_easy_setopt(curl, CURLOPT_URL, ((string) "http://www.codechef.com/get_submission_status/" + bott-> Getremote_runid()).c_str ()); performCurl(); string html = loadAllFromFile(tmpfilename); string result, time_used, memory_used; // get result if (!RE2::PartialMatch (html, "\"result_code\":\"(.*?)\"", &result)) { throw Exception("Failed to get current result."); } result = convertResult(result); if (isFinalResult(result)) { // if result if final, get details if (!RE2::PartialMatch(html, "(?s)\"time\":\"(.*?)\"", &time_used)) { throw Exception ("Failed to parse details from status row."); } int time_ms = stringToDouble(time_used) * 1000 + 0.001; int memory_kb; result_bott = new Bott; result_bott->Settype(RESULT_REPORT); result_bott->Setresult(result); result_bott->Settime_used(intToString(time_ms)); if (result != "Compile Error") { // CodeChef will update Memory usage later in submission table // Weird... why don't they put in get_submission_status api... memory_used = "0"; prepareCurl(); curl_easy_setopt(curl, CURLOPT_URL, ((string) "http://www.codechef.com/submissions?handle=" + escapeURL (info-> GetUsername ()) + "&pcode=" + escapeURL (bott->Getvid ())). c_str()); performCurl(); html = loadAllFromFile(tmpfilename); string status; if (!RE2::PartialMatch(html, "(?s)(<tr class=\"kol.*?<td width=\"60\">" + bott->Getremote_runid() + "</td>.*?</tr>)", &status)) { // Status row is not updated in time... log("Memory data not ready yet... Never mind, use 0 instead."); memory_used = "0"; } else if (!RE2::PartialMatch (status, ">([0-9\\.]*)M", &memory_used)) { memory_used = "0"; } memory_kb = stringToDouble(memory_used) * 1024 + 0.001; } result_bott->Setmemory_used(intToString(memory_kb)); result_bott->Setremote_runid(bott->Getremote_runid()); break; } } return result_bott; }