Maintenance at Wednesday, 30. June 2021, from 7:30 to 9:30
Some of the planned changes may require user action

Verified Commit a33375a4 authored by Mohcine Chraibi's avatar Mohcine Chraibi
Browse files

refactoring parse header and fixing CI

parent 7bb3233c
Pipeline #22079 passed with stages
in 23 minutes and 56 seconds
......@@ -134,16 +134,131 @@ bool IniFileParser::Parse(std::string iniFile)
//check the structure of inifile
if (xMainNode->FirstChild("header")) {
//logfile
TiXmlNode* xHeader = xMainNode->FirstChild("header");
ParseHeader(xHeader);
}//if header
else {
ParseHeader(xMainNode);
}//else header
// JPSfire
// -------------------------------------
// read walkingspeed
#ifdef JPSFIRE
std::shared_ptr<WalkingSpeed> W( new WalkingSpeed(iniFile) );
_config->SetWalkingSpeed(W);
// read ToxicityAnalysis
std::shared_ptr<ToxicityAnalysis> T( new ToxicityAnalysis(iniFile, _config->GetFps()));
_config->SetToxicityAnalysis(T);
#endif
// -------------------------------------
//pick up which model to use
//get the wanted ped model id
_model = xmltoi(xMainNode->FirstChildElement("agents")->Attribute("operational_model_id"), -1);
if (_model==-1) {
Log->Write("ERROR: \tmissing operational_model_id attribute in the agent section.");
Log->Write("ERROR: \tplease specify the model id to use");
return false;
}
bool parsingModelSuccessful = false;
for (TiXmlElement* xModel = xMainNode->FirstChild("operational_models")->FirstChildElement("model");
xModel; xModel = xModel->NextSiblingElement("model")) {
if (!xModel->Attribute("description")) {
Log->Write("ERROR: \t missing attribute description in models?");
return false;
}
string modelName = string(xModel->Attribute("description"));
int model_id = xmltoi(xModel->Attribute("operational_model_id"), -1);
if ((_model==MODEL_GCFM) && (model_id==MODEL_GCFM)) {
if (modelName!="gcfm") {
Log->Write("ERROR: \t mismatch model ID and description. Did you mean gcfm?");
return false;
}
if (!ParseGCFMModel(xModel, xMainNode))
return false;
parsingModelSuccessful = true;
//only parsing one model
break;
}
else if ((_model==MODEL_GOMPERTZ) && (model_id==MODEL_GOMPERTZ)) {
if (modelName!="gompertz") {
Log->Write("ERROR: \t mismatch model ID and description. Did you mean gompertz?");
return false;
}
//only parsing one model
if (!ParseGompertzModel(xModel, xMainNode))
return false;
parsingModelSuccessful = true;
break;
}
else if ((_model==MODEL_GRADIENT) && (model_id==MODEL_GRADIENT)) {
if (modelName!="gradnav") {
Log->Write("ERROR: \t mismatch model ID and description. Did you mean gradnav?");
return false;
}
//only parsing one model
if (!ParseGradientModel(xModel, xMainNode))
return false;
parsingModelSuccessful = true;
break;
}
else if ((_model==MODEL_VELOCITY) && (model_id==MODEL_VELOCITY)) {
if (modelName!="Tordeux2015") {
Log->Write("ERROR:\t mismatch model ID and description. Did you mean Tordeux2015?");
return false;
}
//only parsing one model
if (!ParseVelocityModel(xModel, xMainNode))
return false;
parsingModelSuccessful = true;
break;
}
if ((_model==MODEL_KRAUSZ) && (model_id==MODEL_KRAUSZ)) {
if (modelName!="krausz") {
Log->Write("ERROR: \t mismatch model ID and description. Did you mean krausz?");
return false;
}
if (!ParseKrauszModel(xModel, xMainNode))
return false;
parsingModelSuccessful = true;
//only parsing one model
break;
}
}
if (!parsingModelSuccessful) {
Log->Write("ERROR: \tWrong model id [%d]. Choose 1 (GCFM), 2 (Gompertz), 3 (Tordeux2015) or 5 (Krausz)", _model);
Log->Write("ERROR: \tPlease make sure that all models are specified in the operational_models section");
Log->Write("ERROR: \tand make sure to use the same ID in the agent section");
return false;
}
//route choice strategy
TiXmlNode* xRouters = xMainNode->FirstChild("route_choice_models");
TiXmlNode* xAgentDistri = xMainNode->FirstChild("agents")->FirstChild("agents_distribution");
if (!ParseRoutingStrategies(xRouters, xAgentDistri))
return false;
Log->Write("INFO: \tParsing the project file completed");
return true;
}
bool IniFileParser::ParseHeader(TiXmlNode* xHeader)
{
//logfile
if (xHeader->FirstChild("logfile")) {
_config->SetErrorLogFile(
_config->GetProjectRootDir() + xHeader->FirstChild("logfile")->FirstChild()->Value());
_config->SetLog(2);
Log->Write("INFO:\tlogfile <%s>", _config->GetErrorLogFile().c_str());
}
Log->Write("----\nJuPedSim - JPScore\n");
Log->Write("Current date : %s %s", __DATE__, __TIME__);
Log->Write("Version : %s", JPSCORE_VERSION);
......@@ -206,30 +321,30 @@ bool IniFileParser::Parse(std::string iniFile)
Log->Write("INFO:\tUsing num_threads <%d> threads (%d available)", _config->GetMaxOpenMPThreads(), max_threads);
//display statistics
if (xMainNode->FirstChild("show_statistics")) {
std::string value = xMainNode->FirstChild("show_statistics")->FirstChild()->Value();
if (xHeader->FirstChild("show_statistics")) {
std::string value = xHeader->FirstChild("show_statistics")->FirstChild()->Value();
_config->SetShowStatistics(value=="true");
Log->Write("INFO: \tShow statistics: %s", value.c_str());
}
//trajectories
TiXmlNode* xTrajectories = xMainNode->FirstChild("trajectories");
TiXmlNode* xTrajectories = xHeader->FirstChild("trajectories");
if (xTrajectories) {
double fps;
xMainNode->FirstChildElement("trajectories")->Attribute("fps", &fps);
xHeader->FirstChildElement("trajectories")->Attribute("fps", &fps);
_config->SetFps(fps);
string format =
xMainNode->FirstChildElement("trajectories")->Attribute(
xHeader->FirstChildElement("trajectories")->Attribute(
"format") ?
xMainNode->FirstChildElement("trajectories")->Attribute(
xHeader->FirstChildElement("trajectories")->Attribute(
"format") :
"xml-plain";
int embedMesh = 0;
if (xMainNode->FirstChildElement("trajectories")->Attribute(
if (xHeader->FirstChildElement("trajectories")->Attribute(
"embed_mesh")) {
embedMesh =
string(xMainNode->FirstChildElement("trajectories")->Attribute("embed_mesh"))=="true" ? 1 : 0;
string(xHeader->FirstChildElement("trajectories")->Attribute("embed_mesh"))=="true" ? 1 : 0;
}
if (format=="xml-plain")
_config->SetFileFormat(FORMAT_XML_PLAIN);
......@@ -244,9 +359,9 @@ bool IniFileParser::Parse(std::string iniFile)
//color mode
string color_mode =
xMainNode->FirstChildElement("trajectories")->Attribute(
xHeader->FirstChildElement("trajectories")->Attribute(
"color_mode") ?
xMainNode->FirstChildElement("trajectories")->Attribute(
xHeader->FirstChildElement("trajectories")->Attribute(
"color_mode") :
"velocity";
......@@ -298,112 +413,7 @@ bool IniFileParser::Parse(std::string iniFile)
}
}
// JPSfire
// -------------------------------------
// read walkingspeed
#ifdef JPSFIRE
std::shared_ptr<WalkingSpeed> W( new WalkingSpeed(iniFile) );
_config->SetWalkingSpeed(W);
// read ToxicityAnalysis
std::shared_ptr<ToxicityAnalysis> T( new ToxicityAnalysis(iniFile, _config->GetFps()));
_config->SetToxicityAnalysis(T);
#endif
// -------------------------------------
//pick up which model to use
//get the wanted ped model id
_model = xmltoi(xMainNode->FirstChildElement("agents")->Attribute("operational_model_id"), -1);
if (_model==-1) {
Log->Write("ERROR: \tmissing operational_model_id attribute in the agent section.");
Log->Write("ERROR: \tplease specify the model id to use");
return false;
}
bool parsingModelSuccessful = false;
for (TiXmlElement* xModel = xMainNode->FirstChild("operational_models")->FirstChildElement("model");
xModel; xModel = xModel->NextSiblingElement("model")) {
if (!xModel->Attribute("description")) {
Log->Write("ERROR: \t missing attribute description in models?");
return false;
}
string modelName = string(xModel->Attribute("description"));
int model_id = xmltoi(xModel->Attribute("operational_model_id"), -1);
if ((_model==MODEL_GCFM) && (model_id==MODEL_GCFM)) {
if (modelName!="gcfm") {
Log->Write("ERROR: \t mismatch model ID and description. Did you mean gcfm?");
return false;
}
if (!ParseGCFMModel(xModel, xMainNode))
return false;
parsingModelSuccessful = true;
//only parsing one model
break;
}
else if ((_model==MODEL_GOMPERTZ) && (model_id==MODEL_GOMPERTZ)) {
if (modelName!="gompertz") {
Log->Write("ERROR: \t mismatch model ID and description. Did you mean gompertz?");
return false;
}
//only parsing one model
if (!ParseGompertzModel(xModel, xMainNode))
return false;
parsingModelSuccessful = true;
break;
}
else if ((_model==MODEL_GRADIENT) && (model_id==MODEL_GRADIENT)) {
if (modelName!="gradnav") {
Log->Write("ERROR: \t mismatch model ID and description. Did you mean gradnav?");
return false;
}
//only parsing one model
if (!ParseGradientModel(xModel, xMainNode))
return false;
parsingModelSuccessful = true;
break;
}
else if ((_model==MODEL_VELOCITY) && (model_id==MODEL_VELOCITY)) {
if (modelName!="Tordeux2015") {
Log->Write("ERROR:\t mismatch model ID and description. Did you mean Tordeux2015?");
return false;
}
//only parsing one model
if (!ParseVelocityModel(xModel, xMainNode))
return false;
parsingModelSuccessful = true;
break;
}
if ((_model==MODEL_KRAUSZ) && (model_id==MODEL_KRAUSZ)) {
if (modelName!="krausz") {
Log->Write("ERROR: \t mismatch model ID and description. Did you mean krausz?");
return false;
}
if (!ParseKrauszModel(xModel, xMainNode))
return false;
parsingModelSuccessful = true;
//only parsing one model
break;
}
}
if (!parsingModelSuccessful) {
Log->Write("ERROR: \tWrong model id [%d]. Choose 1 (GCFM), 2 (Gompertz), 3 (Tordeux2015) or 5 (Krausz)", _model);
Log->Write("ERROR: \tPlease make sure that all models are specified in the operational_models section");
Log->Write("ERROR: \tand make sure to use the same ID in the agent section");
return false;
}
//route choice strategy
TiXmlNode* xRouters = xMainNode->FirstChild("route_choice_models");
TiXmlNode* xAgentDistri = xMainNode->FirstChild("agents")->FirstChild("agents_distribution");
if (!ParseRoutingStrategies(xRouters, xAgentDistri))
return false;
Log->Write("INFO: \tParsing the project file completed");
return true;
}
bool IniFileParser::ParseGCFMModel(TiXmlElement* xGCFM, TiXmlElement* xMainNode)
{
Log->Write("\nINFO:\tUsing the GCFM model");
......
......@@ -44,6 +44,8 @@ public:
bool Parse(std::string iniFile);
private:
bool ParseHeader(TiXmlNode* xHeader);
bool ParseGCFMModel(TiXmlElement* xGCFM, TiXmlElement* xMain);
bool ParseKrauszModel(TiXmlElement* xKrausz, TiXmlElement* xMain);
......
<?xml version="1.0" encoding="UTF-8" ?>
<JuPedSim project="JPS-Project" version="0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_ini_core.xsd">
<header>
<!-- seed used for initialising random generator -->
<seed>12542</seed>
<!-- geometry file -->
......@@ -16,7 +16,7 @@
<!-- where to store the logs -->
<logfile>log.txt</logfile>
</header>
<!-- traffic information: e.g closed doors or smoked rooms -->
<traffic_constraints>
<!-- doors states are: close or open -->
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment