path issues with trajectories

this commit solves issues addressed in:

- #324
- #326
parent 35c73b09
Pipeline #21758 passed with stages
in 9 minutes and 17 seconds
......@@ -47,6 +47,9 @@
#include "../routing/ff_router_trips/ffRouterTrips.h"
#include "../routing/trips_router/TripsRouter.h"
namespace fs = std::filesystem;
/* https://stackoverflow.com/questions/38530981/output-compiler-version-in-a-c-program#38531037 */
std::string ver_string(int a, int b, int c) {
std::ostringstream ss;
......@@ -268,8 +271,19 @@ bool IniFileParser::Parse(std::string iniFile)
std::string tmp;
tmp = xTrajectories->FirstChildElement("file")->Attribute(
"location");
if (tmp.c_str())
_config->SetTrajectoriesFile(_config->GetProjectRootDir()+tmp);
fs::path p(tmp);
fs::path curr_abs_path = fs::current_path();
fs::path rel_path = fs::path(_config->GetProjectRootDir()) / fs::path(tmp);
fs::path combined = (curr_abs_path /= rel_path);
std::string traj = combined.string();
if (traj.c_str())
{
_config->SetTrajectoriesFile(traj);
_config->SetOriginalTrajectoriesFile(traj);
}
Log->Write("INFO: \toutput file <%s>", _config->GetTrajectoriesFile().c_str());
Log->Write("INFO: \tin format <%s> at <%.0f> frames per seconds",format.c_str(), _config->GetFps());
}
......
......@@ -23,7 +23,7 @@
#define JPSCORE_INIFILEPARSER_H
#include <string>
#include <filesystem>
#include "../general/Configuration.h"
#include "../routing/DirectionStrategy.h"
......
......@@ -58,7 +58,7 @@ Simulation::Simulation(Configuration* args)
:_config(args)
{
_countTraj = 0;
_maxFileSize = 10; // MB
_maxFileSize = 1; // MB
_nPeds = 0;
_seed = 8091983;
_deltaT = 0;
......@@ -152,18 +152,31 @@ bool Simulation::InitArgs()
}
if (!_config->GetTrajectoriesFile().empty()) {
fs::path p(_config->GetTrajectoriesFile());
fs::path curr_abs_path = fs::current_path();
fs::path rel_path = _config->GetTrajectoriesFile();
fs::path combined = (curr_abs_path /= rel_path);
std::string traj = combined.string();
_config->SetTrajectoriesFile(combined);
if(!fs::exists(traj))
fs::create_directories(combined.parent_path());
switch (_config->GetFileFormat()) {
case FORMAT_XML_PLAIN: {
OutputHandler* tofile = new FileHandler(
_config->GetTrajectoriesFile().c_str());
traj.c_str());
Trajectories* output = new TrajectoriesJPSV05();
output->SetOutputHandler(tofile);
_iod->AddIO(output);
break;
}
case FORMAT_PLAIN: {
OutputHandler* file = new FileHandler(
_config->GetTrajectoriesFile().c_str());
traj.c_str());
outputTXT = new TrajectoriesFLAT();
outputTXT->SetOutputHandler(file);
_iod->AddIO(outputTXT);
......@@ -172,7 +185,7 @@ bool Simulation::InitArgs()
case FORMAT_VTK: {
Log->Write("INFO: \tFormat vtk not yet supported\n");
OutputHandler* file = new FileHandler(
(_config->GetTrajectoriesFile()+".vtk").c_str());
(traj+".vtk").c_str());
Trajectories* output = new TrajectoriesVTK();
output->SetOutputHandler(file);
_iod->AddIO(output);
......@@ -453,7 +466,9 @@ void Simulation::PrintStatistics(double simTime)
goal->GetID(), goal->GetDoorUsage(),
goal->GetLastPassingTime());
string statsfile = "flow_exit_id_"+to_string(goal->GetID())+".txt";
fs::path p(_config->GetOriginalTrajectoriesFile());
string statsfile = "flow_exit_id_"+to_string(goal->GetID())+"_"+p.stem().string()+".txt";
if(goal->GetOutflowRate() < (std::numeric_limits<double>::max)())
{
char tmp[50];
......@@ -708,6 +723,8 @@ bool Simulation::WriteTrajectories(std::string trajectoryName)
if(_config-> GetFileFormat() == FORMAT_PLAIN)
{
fs::path p = _config->GetTrajectoriesFile();
fs::path parent = p.parent_path();
int sf = fs::file_size(p);
if(sf>_maxFileSize*1024*1024)
{
......@@ -715,7 +732,8 @@ bool Simulation::WriteTrajectories(std::string trajectoryName)
this->incrementCountTraj();
char tmp_traj_name[100];
sprintf(tmp_traj_name,"%s_%.4d_%s", trajectoryName.c_str(), _countTraj, extention.c_str());
_config->SetTrajectoriesFile(tmp_traj_name);
fs::path abs_traj_name = parent/ fs::path(tmp_traj_name);
_config->SetTrajectoriesFile(abs_traj_name.string());
Log->Write("INFO:\tNew trajectory file <%s>", tmp_traj_name);
OutputHandler* file = new FileHandler(_config->GetTrajectoriesFile().c_str());
outputTXT->SetOutputHandler(file);
......
......@@ -99,6 +99,7 @@ public:
_hostname = "localhost";
_trajectoriesFile = "trajectories.xml";
_originalTrajectoriesFile = "trajectories.xml";
_errorLogFile = "log.txt";
_projectFile = "";
_geometryFile = "";
......@@ -125,7 +126,7 @@ public:
// _dirSubLocal = nullptr;
// _dirLocal = nullptr;
_dirStrategy = nullptr;
//for random numbers
//for random numbers
_rdGenerator=RandomNumberGenerator();
......@@ -315,6 +316,10 @@ public:
void SetTrajectoriesFile(std::string trajectoriesFile) { _trajectoriesFile = trajectoriesFile; };
const std::string& GetOriginalTrajectoriesFile() const { return _originalTrajectoriesFile; };
void SetOriginalTrajectoriesFile(std::string trajectoriesFile) { _originalTrajectoriesFile = trajectoriesFile; };
const std::string& GetErrorLogFile() const { return _errorLogFile; };
void SetErrorLogFile(std::string errorLogFile) { _errorLogFile = errorLogFile; };
......@@ -431,6 +436,7 @@ private:
std::string _hostname;
std::string _trajectoriesFile;
std::string _originalTrajectoriesFile;
std::string _errorLogFile;
std::string _projectFile;
std::string _geometryFile;
......
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