Adding train information to building

parent 9b43e882
Pipeline #20441 failed with stages
in 1 minute and 55 seconds
......@@ -815,10 +815,8 @@ bool GeoFileParser::LoadTrainInfo(Building* building)
Log->Write("WARNING:\tNo train constraints were found. Continue.");
}
bool resTTT = LoadTrainTimetable(building, xRootNode);
std::cout << "\nresTTT " << resTTT << "\n";
bool resType = LoadTrainType(building, xRootNode);
std::cout << "\nresType " << resType << "\n";
exit(1);
return (resTTT && resType);
}
bool GeoFileParser::LoadTrainTimetable(Building* building, TiXmlElement * xRootNode)
......@@ -853,11 +851,10 @@ bool GeoFileParser::LoadTrainTimetable(Building* building, TiXmlElement * xRootN
}
for (TiXmlElement* e = xTTT->FirstChildElement("train"); e;
e = e->NextSiblingElement("train")) {
TrainTable TTT = parseTrainTimeTableNode(e);
std::shared_ptr<TrainTimeTable> TTT = parseTrainTimeTableNode(e);
if (1) { // todo: maybe get pointer to train
//building->AddGoal(goal);
std::cout << "\nTODO: add train to building\n----\n";
if (TTT) { // todo: maybe get pointer to train
building->AddTrainTimeTable(TTT);
}
}
}
......@@ -893,23 +890,16 @@ bool GeoFileParser::LoadTrainType(Building* building, TiXmlElement * xRootNode)
}
for (TiXmlElement* e = xTT->FirstChildElement("train"); e;
e = e->NextSiblingElement("train")) {
TrainType TT = parseTrainTypeNode(e);
if (1) { // todo: maybe get pointer to train
//building->AddGoal(goal);
std::cout << "\nTODO: add train type to building\n----\n";
std::shared_ptr<TrainType> TT = parseTrainTypeNode(e);
if (TT) {
building->AddTrainType(TT);
}
}
return true;
}
// <train_time_tables>
// <train id="1" type="RE" room_id="1"
// track_start_x="0" track_start_y="0" track_x-end="300" track_y-end="0"
// train_start_x="0" train_start_y="0" train_x-end="300" train_y-end="0"
// arrival_time="5" departure_time="20>
// </train_time_tables>
TrainTable GeoFileParser::parseTrainTimeTableNode(TiXmlElement * e)
std::shared_ptr<TrainTimeTable> GeoFileParser::parseTrainTimeTableNode(TiXmlElement * e)
{
Log->Write("INFO:\tLoading train time table NODE");
std::string caption = xmltoa(e->Attribute("caption"), "-1");
......@@ -941,25 +931,23 @@ TrainTable GeoFileParser::parseTrainTimeTableNode(TiXmlElement * e)
Point track_end(track_end_x, track_end_y);
Point train_start(train_start_x, train_start_y);
Point train_end(train_end_x, train_end_y);
TrainTable trainTab = {
id,
type,
room_id,
arrival_time,
departure_time,
track_start,
track_end,
train_start,
train_end,
};
return trainTab;
std::shared_ptr<TrainTimeTable> trainTimeTab = std::make_shared<TrainTimeTable>(
TrainTimeTable{
id,
type,
room_id,
arrival_time,
departure_time,
track_start,
track_end,
train_start,
train_end,
});
return trainTimeTab;
}
// <train type="RE" agents_max="600">
// <door id="1" x="3" y="5.5" frequency="2">
// <door id="2" x="13" y="15.5" frequency="3">
// <\train>
TrainType GeoFileParser::parseTrainTypeNode(TiXmlElement * e)
std::shared_ptr<TrainType> GeoFileParser::parseTrainTypeNode(TiXmlElement * e)
{
Log->Write("INFO:\tLoading train type");
// int T_id = xmltoi(e->Attribute("id"), -1);
......@@ -992,11 +980,12 @@ TrainType GeoFileParser::parseTrainTypeNode(TiXmlElement * e)
Log->Write("INFO:\t capacity: %d", agents_max);
Log->Write("INFO:\t number of doors: %d", doors.size());
TrainType Type = {
type,
agents_max,
doors,
};
std::shared_ptr<TrainType> Type = std::make_shared<TrainType>(
TrainType{
type,
agents_max,
doors,
});
return Type;
}
......
......@@ -47,8 +47,8 @@ public:
bool LoadTrainInfo(Building* building);
bool LoadTrainTimetable(Building* building, TiXmlElement * xRootNode);
bool LoadTrainType(Building* building, TiXmlElement * xRootNode);
TrainType parseTrainTypeNode(TiXmlElement * e);
TrainTable parseTrainTimeTableNode(TiXmlElement * e);
std::shared_ptr<TrainType> parseTrainTypeNode(TiXmlElement * e);
std::shared_ptr<TrainTimeTable> parseTrainTimeTableNode(TiXmlElement * e);
private:
Configuration* _configuration;
......
......@@ -246,7 +246,26 @@ bool Simulation::InitArgs()
if (!_operationalModel->Init(_building.get()))
return false;
Log->Write("INFO:\t Init Operational Model done");
Log->Write("Got %d Train Types", _building->GetTrainTypes().size());
for(auto&& TT: _building->GetTrainTypes())
{
Log->Write("INFO\ttype : %s",TT.second->type.c_str());
Log->Write("INFO\tMax : %d",TT.second->nmax);
Log->Write("INFO\tnumber doors : %d\n",TT.second->doors.size());
}
Log->Write("Got %d Train Time Tables",_building->GetTrainTimeTables().size());
for(auto&& TT: _building->GetTrainTimeTables())
{
Log->Write("INFO\tid : %d",TT.second->id);
Log->Write("INFO\ttype : %s",TT.second->type.c_str());
Log->Write("INFO\troom id : %d",TT.second->rid);
Log->Write("INFO\ttin : %.2f%",TT.second->tin);
Log->Write("INFO\ttout : %.2f",TT.second->tout);
Log->Write("INFO\ttrack start : (%.2f, %.2f)",TT.second->pstart._x,TT.second->pstart._y);
Log->Write("INFO\ttrack end : (%.2f, %.2f)",TT.second->pend._x,TT.second->pend._y);
Log->Write("INFO\ttrain start : (%.2f, %.2f)",TT.second->tstart._x, TT.second->tstart._y);
Log->Write("INFO\ttrain end : (%.2f, %.2f)\n",TT.second->tend._x, TT.second->tend._y);
}
// Give the DirectionStrategy the chance to perform some initialization.
// This should be done after the initialization of the operationalModel
// because then, invalid pedestrians have been deleted and FindExit()
......@@ -636,8 +655,8 @@ double Simulation::RunBody(double maxSimTime)
Trans->UpdateClosingTime( _deltaT);
if(Trans->GetClosingTime() <= _deltaT){
Trans->changeTemporaryState();
Log-> Write("INFO:\tReset state of door %d, Time=%.2f", Trans->GetID(), Pedestrian::GetGlobalTime());
}
Log-> Write("INFO:\tReset state of door %d, Time=%.2f", Trans->GetID(), Pedestrian::GetGlobalTime());
}
}
}
......
......@@ -915,6 +915,25 @@ bool Building::AddGoal(Goal* goal)
return true;
}
bool Building::AddTrainType(std::shared_ptr<TrainType> TT)
{
if (_trainTypes.count(TT->type)!=0) {
Log->Write("WARNING: Duplicate type for train found [%s]",TT->type);
}
_trainTypes[TT->type] = TT;
return true;
}
bool Building::AddTrainTimeTable(std::shared_ptr<TrainTimeTable> TTT)
{
if (_trainTimeTables.count(TTT->id)!=0) {
Log->Write("WARNING: Duplicate id for train time table found [%d]",TTT->id);
exit(EXIT_FAILURE);
}
_trainTimeTables[TTT->id] = TTT;
return true;
}
const map<int, Crossing*>& Building::GetAllCrossings() const
{
return _crossings;
......@@ -930,11 +949,20 @@ const map<int, Hline*>& Building::GetAllHlines() const
return _hLines;
}
const std::map<std::string, std::shared_ptr<TrainType> >& Building::GetTrainTypes() const
{
return _trainTypes;
}
const std::map<int, std::shared_ptr<TrainTimeTable> >& Building::GetTrainTimeTables() const
{
return _trainTimeTables;
}
const map<int, Goal*>& Building::GetAllGoals() const
{
return _goals;
}
Transition* Building::GetTransition(string caption) const
{
//eventually
......@@ -1372,11 +1400,11 @@ Transition* Building::GetTransitionByUID(int uid) const
Crossing* Building::GetCrossingByUID(int uid) const
{
for (auto&& cross : _crossings) {
if (cross.second->GetUniqueID() == uid)
return cross.second;
}
return nullptr;
for (auto&& cross : _crossings) {
if (cross.second->GetUniqueID() == uid)
return cross.second;
}
return nullptr;
}
bool Building::SaveGeometry(const std::string& filename) const
......
......@@ -45,24 +45,24 @@
#include "Goal.h"
#include "../general/Configuration.h"
struct TrainTable
struct TrainTimeTable
{
int _id;
std::string _type;
int _rid; // room id
double _tin; // arrival time
double _tout; //leaving time
Point _pstart; // track start
Point _pend; // track end
Point _tstart; // train start
Point _tend; // train end
int id;
std::string type;
int rid; // room id
double tin; // arrival time
double tout; //leaving time
Point pstart; // track start
Point pend; // track end
Point tstart; // train start
Point tend; // train end
};
struct TrainType
{
std::string _type;
int _nmax; // agents_max
std::vector<Transition> _doors;
std::string type;
int nmax; // agents_max
std::vector<Transition> doors;
};
......@@ -95,9 +95,8 @@ private:
std::map<int, Transition*> _transitions;
std::map<int, Hline*> _hLines;
std::map<int, Goal*> _goals;
std::map<int, std::vector<WaitingArea*> > _sr2wa;
std::vector<TrainType> trainTypes; // todo, maybe map<string, TrainType>. shared_ptr?>
std::vector<TrainType> trainTimeTable;
std::map<std::string, std::shared_ptr<TrainType> > _trainTypes;
std::map<int, std::shared_ptr<TrainTimeTable> > _trainTimeTables;
/// pedestrians pathway
bool _savePathway;
std::ofstream _pathWayStream;
......@@ -231,6 +230,10 @@ public:
const std::map<int, Goal*>& GetAllGoals() const;
const std::map<std::string, std::shared_ptr<TrainType> >& GetTrainTypes() const;
const std::map<int, std::shared_ptr<TrainTimeTable> >& GetTrainTimeTables() const;
bool AddCrossing(Crossing* line);
bool AddTransition(Transition* line);
......@@ -239,6 +242,10 @@ public:
bool AddGoal(Goal* goal);
bool AddTrainType(std::shared_ptr<TrainType> TT);
bool AddTrainTimeTable(std::shared_ptr<TrainTimeTable> TTT);
const std::string& GetProjectRootDir() const;
const std::string& GetProjectFilename() const;
......
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