-
Notifications
You must be signed in to change notification settings - Fork 27
/
IniFileParser.cpp
1679 lines (1481 loc) · 72.5 KB
/
IniFileParser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* \section License
* This file is part of JuPedSim.
*
* JuPedSim is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* JuPedSim is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
**/
//
// Created by laemmel on 24.03.16.
//
#include "IniFileParser.h"
#include "OutputHandler.h"
#include "general/Filesystem.h"
#include "general/OpenMP.h"
#include "math/GCFMModel.h"
#include "math/GompertzModel.h"
#include "math/GradientModel.h"
#include "math/KrauszModel.h"
#include "math/VelocityModel.h"
#include "pedestrian/Pedestrian.h"
#include "routing/ai_router/AIRouter.h"
#include "routing/ff_router/ffRouter.h"
#include "routing/ff_router_trips/ffRouterTrips.h"
#include "routing/global_shortest/GlobalRouter.h"
#include "routing/quickest/QuickestPathRouter.h"
#include "routing/smoke_router/SmokeRouter.h"
#include <tinyxml.h>
/* 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;
ss << a << '.' << b << '.' << c;
return ss.str();
}
//https://sourceforge.net/p/predef/wiki/Compilers/
std::string true_cxx =
#ifdef __clang__
"clang++";
#elif defined(__GNUC__)
"g++";
#elif defined(__MINGW32__)
"MinGW";
#elif defined(_MSC_VER)
"Visual Studio";
#else
"Compiler not identified";
#endif
std::string true_cxx_ver =
#ifdef __clang__
ver_string(__clang_major__, __clang_minor__, __clang_patchlevel__);
#elif defined(__GNUC__)
ver_string(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
#elif defined(__MINGW32__)
ver_string(__MINGW32__, __MINGW32_MAJOR_VERSION, __MINGW32_MINOR_VERSION);
#elif defined( _MSC_VER)
ver_string(_MSC_VER, _MSC_FULL_VER,_MSC_BUILD);
#else
"";
#endif
IniFileParser::IniFileParser(Configuration* config)
{
_config = config;
}
bool IniFileParser::Parse(std::string iniFile)
{
Log->Write("INFO: \tLoading and parsing the project file <%s>",
iniFile.c_str());
_config->SetProjectFile(iniFile);//TODO in some locations it is called iniFile and in others project file,
// and as I just realized, I called it configuration. We should be consistent here anything else
// is confusing [gl march '16]
fs::path root(iniFile);
fs::path q(iniFile);
_config->SetProjectRootDir(fs::absolute(q.parent_path()).string());
TiXmlDocument doc(iniFile);
if (!doc.LoadFile()) {
Log->Write("ERROR: \t%s", doc.ErrorDesc());
Log->Write("ERROR: \tCould not parse the project file");
return false;
}
// everything is fine. proceed with parsing
TiXmlElement* xMainNode = doc.RootElement();
if (!xMainNode) {
Log->Write("ERROR:\tRoot element does not exist");
return false;
}
if (xMainNode->ValueStr()!="JuPedSim") {
Log->Write("ERROR:\tRoot element value is not 'JuPedSim'.");
return false;
}
//check the header version
if (!xMainNode->Attribute("version")) {
Log->Write("WARNING:\t There is no header version. I am assuming %s",
JPS_VERSION);
}
else if (std::stod(xMainNode->Attribute("version"))<std::stod(JPS_OLD_VERSION)) {
Log->Write("ERROR:\t Wrong header version. Only version greater than %s is supported.", JPS_OLD_VERSION);
return false;
}
//check the structure of inifile
if (xMainNode->FirstChild("header")) {
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;
}
std::string modelName = std::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")) {
fs::path logPath( xHeader->FirstChild("logfile")->FirstChild()->Value());
fs::path root(_config->GetProjectRootDir()); // returns an absolute path already
fs::path canonicalPath = fs::weakly_canonical(root / logPath);
std::string log = canonicalPath.string();
_config->SetErrorLogFile(log);
_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);
Log->Write("Compiler : %s (%s)", true_cxx.c_str(), true_cxx_ver.c_str());
Log->Write("Commit hash : %s", GIT_COMMIT_HASH);
Log->Write("Commit date : %s", GIT_COMMIT_DATE);
Log->Write("Branch : %s\n----\n", GIT_BRANCH);
//seed
if (xHeader->FirstChild("seed")) {
TiXmlNode* seedNode = xHeader->FirstChild("seed")->FirstChild();
if (seedNode) {
const char* seedValue = seedNode->Value();
_config->SetSeed((unsigned int)atoi(seedValue));//strtol
}
else {
_config->SetSeed((unsigned int)time(NULL));
}
}
// srand(_config->GetSeed());
Log->Write("INFO:\trandom seed <%d>", _config->GetSeed());
// max simulation time
if (xHeader->FirstChild("max_sim_time")) {
const char* tmax =
xHeader->FirstChildElement("max_sim_time")->FirstChild()->Value();
_config->SetTmax(atof(tmax));
Log->Write("INFO: \tMaximal simulation time <%.2f> seconds", _config->GetTmax());
}
// Progressbar
if (xHeader->FirstChild("progressbar")) {
_config->SetPRB(true);
Log->Write("INFO: \tUse Progressbar");
}
// geometry file name
if (xHeader->FirstChild("geometry")) {
std::string filename = xHeader->FirstChild("geometry")->FirstChild()->Value();
_config->SetGeometryFile(filename);
Log->Write("INFO: \tgeometry <%s>", filename.c_str());
}
//max CPU
int max_threads = 1;
#ifdef _OPENMP
max_threads = omp_get_max_threads();
#endif
if (xHeader->FirstChild("num_threads")) {
TiXmlNode* numthreads = xHeader->FirstChild("num_threads")->FirstChild();
if (numthreads) {
#ifdef _OPENMP
omp_set_num_threads(xmltoi(numthreads->Value()));
#endif
}
}
_config->SetMaxOpenMPThreads(omp_get_max_threads());
Log->Write("INFO:\tUsing num_threads <%d> threads (%d available)", _config->GetMaxOpenMPThreads(), max_threads);
//display statistics
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 = xHeader->FirstChild("trajectories");
if (xTrajectories) {
double fps;
xHeader->FirstChildElement("trajectories")->Attribute("fps", &fps);
_config->SetFps(fps);
std::string format =
xHeader->FirstChildElement("trajectories")->Attribute(
"format") ?
xHeader->FirstChildElement("trajectories")->Attribute(
"format") :
"xml-plain";
int embedMesh = 0;
if (xHeader->FirstChildElement("trajectories")->Attribute(
"embed_mesh")) {
embedMesh =
std::string(xHeader->FirstChildElement("trajectories")->Attribute("embed_mesh"))=="true" ? 1 : 0;
}
if (format=="xml-plain")
_config->SetFileFormat(FORMAT_XML_PLAIN);
if (format=="xml-plain" && embedMesh==1)
_config->SetFileFormat(FORMAT_XML_PLAIN_WITH_MESH);
if (format=="xml-bin")
_config->SetFileFormat(FORMAT_XML_BIN);
if (format=="plain")
_config->SetFileFormat(FORMAT_PLAIN);
if (format=="vtk")
_config->SetFileFormat(FORMAT_VTK);
//color mode
std::string color_mode =
xHeader->FirstChildElement("trajectories")->Attribute(
"color_mode") ?
xHeader->FirstChildElement("trajectories")->Attribute(
"color_mode") :
"velocity";
if (color_mode=="velocity")
Pedestrian::SetColorMode(
AgentColorMode::BY_VELOCITY); //TODO: config parameter! does not belong to the pedestrian model, we should create a pedestrian config instead. [gl march '16]
if (color_mode=="spotlight") Pedestrian::SetColorMode(AgentColorMode::BY_SPOTLIGHT);
if (color_mode=="group") Pedestrian::SetColorMode(AgentColorMode::BY_GROUP);
if (color_mode=="knowledge") Pedestrian::SetColorMode(AgentColorMode::BY_KNOWLEDGE);
if (color_mode=="router") Pedestrian::SetColorMode(AgentColorMode::BY_ROUTER);
if (color_mode=="final_goal") Pedestrian::SetColorMode(AgentColorMode::BY_FINAL_GOAL);
if (color_mode=="intermediate_goal") Pedestrian::SetColorMode(AgentColorMode::BY_INTERMEDIATE_GOAL);
//a file descriptor was given
if (xTrajectories->FirstChild("file")) {
fs::path trajLoc( xTrajectories->FirstChildElement("file")->Attribute("location"));
fs::path root(_config->GetProjectRootDir()); // returns an absolute path already
fs::path canonicalPath = fs::weakly_canonical(root / trajLoc);
std::string traj = canonicalPath.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());
}
if (xTrajectories->FirstChild("socket")) {
std::string tmp =
xTrajectories->FirstChildElement("socket")->Attribute("hostname");
if (tmp.c_str())
_config->SetHostname(tmp);
int port;
xTrajectories->FirstChildElement("socket")->Attribute("port", &port);
_config->SetPort(port);
Log->Write("INFO: \tStreaming results to output [%s:%d] ",
_config->GetHostname().c_str(), _config->GetPort());
}
}
return true;
}
bool IniFileParser::ParseGCFMModel(TiXmlElement* xGCFM, TiXmlElement* xMainNode)
{
Log->Write("\nINFO:\tUsing the GCFM model");
Log->Write("INFO:\tParsing the model parameters");
TiXmlNode* xModelPara = xGCFM->FirstChild("model_parameters");
if (!xModelPara) {
Log->Write("ERROR: \t !!!! Changes in the operational model section !!!");
Log->Write("ERROR: \t !!!! The new version is in inputfiles/ship_msw/ini_ship2.xml !!!");
return false;
}
// For convenience. This moved to the header as it is not model specific
if (xModelPara->FirstChild("tmax")) {
Log->Write(
"ERROR: \tthe maximal simulation time section moved to the header!!!");
Log->Write("ERROR: \t\t <max_sim_time> </max_sim_time>\n");
return false;
}
//solver
if (!ParseNodeToSolver(*xModelPara))
return false;
//stepsize
if (!ParseStepSize(*xModelPara))
return false;
//exit crossing strategy
if (!ParseStrategyNodeToObject(*xModelPara))
return false;
//linked-cells
if (!ParseLinkedCells(*xModelPara))
return false;
//force_ped
if (xModelPara->FirstChild("force_ped")) {
std::string nu = xModelPara->FirstChildElement("force_ped")->Attribute("nu");
std::string dist_max = xModelPara->FirstChildElement("force_ped")->Attribute(
"dist_max");
std::string disteff_max =
xModelPara->FirstChildElement("force_ped")->Attribute(
"disteff_max"); // @todo: rename disteff_max to force_max
std::string interpolation_width =
xModelPara->FirstChildElement("force_ped")->Attribute(
"interpolation_width");
_config->SetMaxFPed(atof(dist_max.c_str()));
_config->SetNuPed(atof(nu.c_str()));
_config->SetDistEffMaxPed(atof(disteff_max.c_str()));
_config->SetIntPWidthPed(atof(interpolation_width.c_str()));
Log->Write(
"INFO: \tfrep_ped nu=%.3f, dist_max=%.3f, disteff_max=%.3f, interpolation_width=%.3f",
atof(nu.c_str()), atof(dist_max.c_str()), atof(disteff_max.c_str()), atof(interpolation_width.c_str()));
}
//force_wall
if (xModelPara->FirstChild("force_wall")) {
std::string nu = xModelPara->FirstChildElement("force_wall")->Attribute("nu");
std::string dist_max = xModelPara->FirstChildElement("force_wall")->Attribute(
"dist_max");
std::string disteff_max =
xModelPara->FirstChildElement("force_wall")->Attribute(
"disteff_max");
std::string interpolation_width =
xModelPara->FirstChildElement("force_wall")->Attribute(
"interpolation_width");
_config->SetMaxFWall(atof(dist_max.c_str()));
_config->SetNuWall(atof(nu.c_str()));
_config->SetDistEffMaxWall(atof(disteff_max.c_str()));
_config->SetIntPWidthWall(atof(interpolation_width.c_str()));
Log->Write(
"INFO: \tfrep_wall mu=%.3f, dist_max=%.3f, disteff_max=%.3f, interpolation_width=%.3f",
atof(nu.c_str()), atof(dist_max.c_str()), atof(disteff_max.c_str()), atof(interpolation_width.c_str()));
}
//Parsing the agent parameters
TiXmlNode* xAgentDistri = xMainNode->FirstChild("agents")->FirstChild("agents_distribution");
ParseAgentParameters(xGCFM, xAgentDistri);
//TODO: models do not belong in a configuration container [gl march '16]
_config->SetModel(std::shared_ptr<OperationalModel>(new GCFMModel(_exit_strategy, _config->GetNuPed(),
_config->GetNuWall(), _config->GetDistEffMaxPed(),
_config->GetDistEffMaxWall(), _config->GetIntPWidthPed(),
_config->GetIntPWidthWall(), _config->GetMaxFPed(),
_config->GetMaxFWall())));
return true;
}
bool IniFileParser::ParseKrauszModel(TiXmlElement* xKrausz, TiXmlElement* xMainNode)
{
Log->Write("\nINFO:\tUsing the Krausz model");
Log->Write("INFO:\tParsing the model parameters");
TiXmlNode* xModelPara = xKrausz->FirstChild("model_parameters");
if (!xModelPara) {
Log->Write("ERROR: \t !!!! Changes in the operational model section !!!");
Log->Write("ERROR: \t !!!! The new version is in inputfiles/ship_msw/ini_ship2.xml !!!");
return false;
}
// For convenience. This moved to the header as it is not model specific
if (xModelPara->FirstChild("tmax")) {
Log->Write(
"ERROR: \tthe maximal simulation time section moved to the header!!!");
Log->Write("ERROR: \t\t <max_sim_time> </max_sim_time>\n");
return false;
}
//solver
if (!ParseNodeToSolver(*xModelPara))
return false;
//stepsize
if (!ParseStepSize(*xModelPara))
return false;
//exit crossing strategy
if (!ParseStrategyNodeToObject(*xModelPara))
return false;
//linked-cells
if (!ParseLinkedCells(*xModelPara))
return false;
//force_ped
if (xModelPara->FirstChild("force_ped")) {
std::string nu = xModelPara->FirstChildElement("force_ped")->Attribute("nu");
std::string dist_max = xModelPara->FirstChildElement("force_ped")->Attribute(
"dist_max");
std::string disteff_max =
xModelPara->FirstChildElement("force_ped")->Attribute(
"disteff_max"); // @todo: rename disteff_max to force_max
std::string interpolation_width =
xModelPara->FirstChildElement("force_ped")->Attribute(
"interpolation_width");
_config->SetMaxFPed(atof(dist_max.c_str()));
_config->SetNuPed(atof(nu.c_str()));
_config->SetDistEffMaxPed(atof(disteff_max.c_str()));
_config->SetIntPWidthPed(atof(interpolation_width.c_str()));
Log->Write(
"INFO: \tfrep_ped nu=%.3f, dist_max=%.3f, disteff_max=%.3f, interpolation_width=%.3f",
atof(nu.c_str()), atof(dist_max.c_str()), atof(disteff_max.c_str()), atof(interpolation_width.c_str()));
}
//force_wall
if (xModelPara->FirstChild("force_wall")) {
std::string nu = xModelPara->FirstChildElement("force_wall")->Attribute("nu");
std::string dist_max = xModelPara->FirstChildElement("force_wall")->Attribute(
"dist_max");
std::string disteff_max =
xModelPara->FirstChildElement("force_wall")->Attribute(
"disteff_max");
std::string interpolation_width =
xModelPara->FirstChildElement("force_wall")->Attribute(
"interpolation_width");
_config->SetMaxFWall(atof(dist_max.c_str()));
_config->SetNuWall(atof(nu.c_str()));
_config->SetDistEffMaxWall(atof(disteff_max.c_str()));
_config->SetIntPWidthWall(atof(interpolation_width.c_str()));
Log->Write(
"INFO: \tfrep_wall mu=%.3f, dist_max=%.3f, disteff_max=%.3f, interpolation_width=%.3f",
atof(nu.c_str()), atof(dist_max.c_str()), atof(disteff_max.c_str()), atof(interpolation_width.c_str()));
}
//Parsing the agent parameters
TiXmlNode* xAgentDistri = xMainNode->FirstChild("agents")->FirstChild("agents_distribution");
ParseAgentParameters(xKrausz, xAgentDistri);
//TODO: models do not belong in a configuration container [gl march '16]
_config->SetModel(std::shared_ptr<OperationalModel>(new KrauszModel(_exit_strategy, _config->GetNuPed(),
_config->GetNuWall(), _config->GetDistEffMaxPed(),
_config->GetDistEffMaxWall(), _config->GetIntPWidthPed(),
_config->GetIntPWidthWall(), _config->GetMaxFPed(),
_config->GetMaxFWall())));
return true;
}
bool IniFileParser::ParseGompertzModel(TiXmlElement* xGompertz, TiXmlElement* xMainNode)
{
//parsing the model parameters
Log->Write("\nINFO:\tUsing the Gompertz model");
Log->Write("INFO:\tParsing the model parameters");
TiXmlNode* xModelPara = xGompertz->FirstChild("model_parameters");
if (!xModelPara) {
Log->Write("ERROR: \t !!!! Changes in the operational model section !!!");
Log->Write("ERROR: \t !!!! The new version is in inputfiles/ship_msw/ini_ship3.xml !!!");
return false;
}
// For convenience. This moved to the header as it is not model specific
if (xModelPara->FirstChild("tmax")) {
Log->Write("ERROR: \tthe maximal simulation time section moved to the header!!!");
Log->Write("ERROR: \t\t <max_sim_time> </max_sim_time>\n");
return false;
}
//solver
if (!ParseNodeToSolver(*xModelPara))
return false;
//stepsize
if (!ParseStepSize(*xModelPara))
return false;
//exit crossing strategy
if (!ParseStrategyNodeToObject(*xModelPara))
return false;
//linked-cells
if (!ParseLinkedCells(*xModelPara))
return false;
//force_ped
if (xModelPara->FirstChild("force_ped")) {
std::string nu = xModelPara->FirstChildElement("force_ped")->Attribute("nu");
_config->SetNuPed(atof(nu.c_str()));
if (!xModelPara->FirstChildElement("force_ped")->Attribute("a"))
_config->SetaPed(1.0); // default value
else {
std::string a = xModelPara->FirstChildElement("force_ped")->Attribute("a");
_config->SetaPed(atof(a.c_str()));
}
if (!xModelPara->FirstChildElement("force_ped")->Attribute("b"))
_config->SetbPed(0.25); // default value
else {
std::string b = xModelPara->FirstChildElement("force_ped")->Attribute("b");
_config->SetbPed(atof(b.c_str()));
}
if (!xModelPara->FirstChildElement("force_ped")->Attribute("c"))
_config->SetcPed(3.0); // default value
else {
std::string c = xModelPara->FirstChildElement("force_ped")->Attribute("c");
_config->SetcPed(atof(c.c_str()));
}
Log->Write("INFO: \tfrep_ped mu=%s, a=%0.2f, b=%0.2f c=%0.2f", nu.c_str(), _config->GetaPed(),
_config->GetbPed(), _config->GetcPed());
}
//force_wall
if (xModelPara->FirstChild("force_wall")) {
std::string nu = xModelPara->FirstChildElement("force_wall")->Attribute("nu");
_config->SetNuWall(atof(nu.c_str()));
if (!xModelPara->FirstChildElement("force_wall")->Attribute("a"))
_config->SetaWall(1.0); // default value
else {
std::string a = xModelPara->FirstChildElement("force_wall")->Attribute("a");
_config->SetaWall(atof(a.c_str()));
}
if (!xModelPara->FirstChildElement("force_wall")->Attribute("b"))
_config->SetbWall(0.7); // default value
else {
std::string b = xModelPara->FirstChildElement("force_wall")->Attribute("b");
_config->SetbWall(atof(b.c_str()));
}
if (!xModelPara->FirstChildElement("force_wall")->Attribute("c"))
_config->SetcWall(3.0); // default value
else {
std::string c = xModelPara->FirstChildElement("force_wall")->Attribute("c");
_config->SetcWall(atof(c.c_str()));
}
Log->Write("INFO: \tfrep_wall mu=%s, a=%0.2f, b=%0.2f c=%0.2f", nu.c_str(), _config->GetaWall(),
_config->GetbWall(), _config->GetcWall());
}
//Parsing the agent parameters
TiXmlNode* xAgentDistri = xMainNode->FirstChild("agents")->FirstChild("agents_distribution");
ParseAgentParameters(xGompertz, xAgentDistri);
//TODO: models do not belong in a configuration container [gl march '16]
_config->SetModel(std::shared_ptr<OperationalModel>(new GompertzModel(_exit_strategy, _config->GetNuPed(),
_config->GetaPed(), _config->GetbPed(), _config->GetcPed(),
_config->GetNuWall(), _config->GetaWall(), _config->GetbWall(),
_config->GetcWall())));
return true;
}
bool IniFileParser::ParseGradientModel(TiXmlElement* xGradient, TiXmlElement* xMainNode)
{
//parsing the model parameters
Log->Write("\nINFO:\tUsing the Gradient model");
Log->Write("INFO:\tParsing the model parameters");
TiXmlNode* xModelPara = xGradient->FirstChild("model_parameters");
if (!xModelPara) {
Log->Write("ERROR: \t !!!! Changes in the operational model section !!!");
Log->Write("ERROR: \t !!!! The new version is in inputfiles/ship_msw/ini_ship3.xml !!!");
return false;
}
// For convenience. This moved to the header as it is not model specific
if (xModelPara->FirstChild("tmax")) {
Log->Write("ERROR: \tthe maximal simulation time section moved to the header!!!");
Log->Write("ERROR: \t\t <max_sim_time> </max_sim_time>\n");
return false;
}
//solver
if (!ParseNodeToSolver(*xModelPara))
return false;
//stepsize
if (!ParseStepSize(*xModelPara))
return false;
//exit crossing strategy
if (!ParseStrategyNodeToObject(*xModelPara))
return false;
//floorfield
double pDeltaH = 0., pWallAvoidDistance = 0., pSlowDownDistance = 0.; //TODO: should be moved to configuration [gl march '16]
bool pUseWallAvoidance = false;
if (xModelPara->FirstChild("floorfield")) {
if (!xModelPara->FirstChildElement("floorfield")->Attribute("delta_h"))
pDeltaH = 0.0625; // default value
else {
std::string delta_h = xModelPara->FirstChildElement("floorfield")->Attribute("delta_h");
pDeltaH = atof(delta_h.c_str());
}
_config->set_deltaH(pDeltaH);
if (!xModelPara->FirstChildElement("floorfield")->Attribute("wall_avoid_distance"))
pWallAvoidDistance = .8; // default value
else {
std::string wall_avoid_distance = xModelPara->FirstChildElement("floorfield")->Attribute(
"wall_avoid_distance");
pWallAvoidDistance = atof(wall_avoid_distance.c_str());
}
_config->set_wall_avoid_distance(pWallAvoidDistance);
if (!xModelPara->FirstChildElement("floorfield")->Attribute("use_wall_avoidance"))
pUseWallAvoidance = true; // default value
else {
std::string use_wall_avoidance = xModelPara->FirstChildElement("floorfield")->Attribute("use_wall_avoidance");
pUseWallAvoidance = !(use_wall_avoidance=="false");
}
_config->set_use_wall_avoidance(pUseWallAvoidance);
Log->Write("INFO: \tfloorfield <delta h=%0.4f, wall avoid distance=%0.2f>", pDeltaH, pWallAvoidDistance);
Log->Write("INFO: \tfloorfield <use wall avoidance=%s>", pUseWallAvoidance ? "true" : "false");
}
//linked-cells
if (!ParseLinkedCells(*xModelPara))
return false;
//force_ped
if (xModelPara->FirstChild("force_ped")) {
std::string nu = xModelPara->FirstChildElement("force_ped")->Attribute("nu");
_config->SetNuPed(atof(nu.c_str()));
if (!xModelPara->FirstChildElement("force_ped")->Attribute("a"))
_config->SetaPed(1.0); // default value
else {
std::string a = xModelPara->FirstChildElement("force_ped")->Attribute("a");
_config->SetaPed(atof(a.c_str()));
}
if (!xModelPara->FirstChildElement("force_ped")->Attribute("b"))
_config->SetbPed(0.25); // default value
else {
std::string b = xModelPara->FirstChildElement("force_ped")->Attribute("b");
_config->SetbPed(atof(b.c_str()));
}
if (!xModelPara->FirstChildElement("force_ped")->Attribute("c"))
_config->SetcPed(3.0); // default value
else {
std::string c = xModelPara->FirstChildElement("force_ped")->Attribute("c");
_config->SetcPed(atof(c.c_str()));
}
Log->Write("INFO: \tfrep_ped mu=%s, a=%0.2f, b=%0.2f c=%0.2f", nu.c_str(), _config->GetaPed(),
_config->GetbPed(), _config->GetcPed());
}
//force_wall
if (xModelPara->FirstChild("force_wall")) {
std::string nu = xModelPara->FirstChildElement("force_wall")->Attribute("nu");
_config->SetNuWall(atof(nu.c_str()));
if (!xModelPara->FirstChildElement("force_wall")->Attribute("a"))
_config->SetaWall(1.0); // default value
else {
std::string a = xModelPara->FirstChildElement("force_wall")->Attribute("a");
_config->SetaWall(atof(a.c_str()));
}
if (!xModelPara->FirstChildElement("force_wall")->Attribute("b"))
_config->SetbWall(0.7); // default value
else {
std::string b = xModelPara->FirstChildElement("force_wall")->Attribute("b");
_config->SetbWall(atof(b.c_str()));
}
if (!xModelPara->FirstChildElement("force_wall")->Attribute("c"))
_config->SetcWall(3.0); // default value
else {
std::string c = xModelPara->FirstChildElement("force_wall")->Attribute("c");
_config->SetcWall(atof(c.c_str()));
}
Log->Write("INFO: \tfrep_wall mu=%s, a=%0.2f, b=%0.2f c=%0.2f", nu.c_str(), _config->GetaWall(),
_config->GetbWall(), _config->GetcWall());
}
//anti_clipping
if (xModelPara->FirstChild("anti_clipping")) {
if (!xModelPara->FirstChildElement("anti_clipping")->Attribute("slow_down_distance"))
pSlowDownDistance = .2; //default value
else {
std::string slow_down_distance = xModelPara->FirstChildElement("anti_clipping")->Attribute(
"slow_down_distance");
pSlowDownDistance = atof(slow_down_distance.c_str());
}
_config->set_slow_down_distance(pSlowDownDistance);
Log->Write("INFO: \tAnti Clipping: SlowDown Distance=%0.2f", pSlowDownDistance);
}
//Parsing the agent parameters
TiXmlNode* xAgentDistri = xMainNode->FirstChild("agents")->FirstChild("agents_distribution");
ParseAgentParameters(xGradient, xAgentDistri);
//TODO: models do not belong in a configuration container [gl march '16]
_config->SetModel(std::shared_ptr<OperationalModel>(new GradientModel(_exit_strategy, _config->GetNuPed(),
_config->GetaPed(), _config->GetbPed(), _config->GetcPed(),
_config->GetNuWall(), _config->GetaWall(), _config->GetbWall(),
_config->GetcWall(), _config->get_deltaH(), _config->get_wall_avoid_distance(), _config->get_use_wall_avoidance(),
_config->get_slow_down_distance())));
return true;
}
bool IniFileParser::ParseVelocityModel(TiXmlElement* xVelocity, TiXmlElement* xMainNode)
{
//parsing the model parameters
Log->Write("\nINFO:\tUsing Tordeux2015 model");
Log->Write("INFO:\tParsing the model parameters");
TiXmlNode* xModelPara = xVelocity->FirstChild("model_parameters");
if (!xModelPara) {
Log->Write("ERROR: \t !!!! Changes in the operational model section !!!");
Log->Write("ERROR: \t !!!! The new version is in inputfiles/ship_msw/ini_ship3.xml !!!");
return false;
}
// For convenience. This moved to the header as it is not model specific
if (xModelPara->FirstChild("tmax")) {
Log->Write("ERROR: \tthe maximal simulation time section moved to the header!!!");
Log->Write("ERROR: \t\t <max_sim_time> </max_sim_time>\n");
return false;
}
//solver
if (!ParseNodeToSolver(*xModelPara))
return false;
//stepsize
if (!ParseStepSize(*xModelPara))
return false;
//exit crossing strategy
if (!ParseStrategyNodeToObject(*xModelPara))
return false;
//linked-cells
if (!ParseLinkedCells(*xModelPara))
return false;
//periodic
if (!ParsePeriodic(*xModelPara))
return false;
//force_ped
if (xModelPara->FirstChild("force_ped")) {
if (!xModelPara->FirstChildElement("force_ped")->Attribute("a"))
_config->SetaPed(1.0); // default value
else {
std::string a = xModelPara->FirstChildElement("force_ped")->Attribute("a");
_config->SetaPed(atof(a.c_str()));
}
if (!xModelPara->FirstChildElement("force_ped")->Attribute("D"))
_config->SetDPed(0.1); // default value in [m]
else {
std::string D = xModelPara->FirstChildElement("force_ped")->Attribute("D");
_config->SetDPed(atof(D.c_str()));
}
Log->Write("INFO: \tfrep_ped a=%0.2f, D=%0.2f", _config->GetaPed(), _config->GetDPed());
}
//force_wall
if (xModelPara->FirstChild("force_wall")) {
if (!xModelPara->FirstChildElement("force_wall")->Attribute("a"))
_config->SetaWall(1.0); // default value
else {
std::string a = xModelPara->FirstChildElement("force_wall")->Attribute("a");
_config->SetaWall(atof(a.c_str()));
}
if (!xModelPara->FirstChildElement("force_wall")->Attribute("D"))
_config->SetDWall(0.1); // default value in [m]
else {
std::string D = xModelPara->FirstChildElement("force_wall")->Attribute("D");
_config->SetDWall(atof(D.c_str()));
}
Log->Write("INFO: \tfrep_wall a=%0.2f, D=%0.2f", _config->GetaWall(), _config->GetDWall());
}
//Parsing the agent parameters
TiXmlNode* xAgentDistri = xMainNode->FirstChild("agents")->FirstChild("agents_distribution");
ParseAgentParameters(xVelocity, xAgentDistri);
_config->SetModel(std::shared_ptr<OperationalModel>(new VelocityModel(_exit_strategy, _config->GetaPed(),
_config->GetDPed(), _config->GetaWall(),
_config->GetDWall())));
return true;
}
void IniFileParser::ParseAgentParameters(TiXmlElement* operativModel, TiXmlNode* agentsDistri)
{
//Parsing the agent parameters
Log->Write("\nINFO:\tParsing agents parameters");
//first get list of actually used router
std::vector<int> usedAgentParams;
usedAgentParams.clear();
for (TiXmlElement* e = agentsDistri->FirstChildElement("group"); e;
e = e->NextSiblingElement("group")) {
int agentsParams = -1;
if (e->Attribute("agent_parameter_id")) {
agentsParams = atoi(e->Attribute("agent_parameter_id"));
if(std::find(usedAgentParams.begin(), usedAgentParams.end(), agentsParams) == usedAgentParams.end()) {
usedAgentParams.emplace_back(agentsParams);
}
}
}
for(TiXmlElement* xAgentPara = operativModel->FirstChildElement("agent_parameters"); xAgentPara;
xAgentPara = xAgentPara->NextSiblingElement("agent_parameters")) {
//get the group ID
int para_id= xmltoi(xAgentPara->Attribute("agent_parameter_id"),-1);
if (std::find(usedAgentParams.begin(), usedAgentParams.end(), para_id) != usedAgentParams.end() ) {
Log->Write("INFO: \tParsing the group parameter id [%d]", para_id);
auto agentParameters = std::shared_ptr<AgentsParameters>(new AgentsParameters(para_id, _config->GetSeed()));
_config->AddAgentsParameters(agentParameters, para_id);
//desired speed
if (xAgentPara->FirstChild("v0")) {
double mu = xmltof(xAgentPara->FirstChildElement("v0")->Attribute("mu"));
double sigma = xmltof(xAgentPara->FirstChildElement("v0")->Attribute("sigma"));
agentParameters->InitV0(mu, sigma);
agentParameters->InitV0DownStairs(mu, sigma);
agentParameters->InitV0UpStairs(mu, sigma);
Log->Write("INFO: \tdesired speed mu=%f , sigma=%f", mu, sigma);
}
if (xAgentPara->FirstChild("v0_upstairs")) {
double mu = xmltof(xAgentPara->FirstChildElement("v0_upstairs")->Attribute("mu"));
double sigma = xmltof(xAgentPara->FirstChildElement("v0_upstairs")->Attribute("sigma"));
agentParameters->InitV0UpStairs(mu, sigma);
Log->Write("INFO: \tdesired speed upstairs mu=%f , sigma=%f", mu, sigma);
}
if (xAgentPara->FirstChild("v0_downstairs")) {
double mu = xmltof(xAgentPara->FirstChildElement("v0_downstairs")->Attribute("mu"));
double sigma = xmltof(xAgentPara->FirstChildElement("v0_downstairs")->Attribute("sigma"));
agentParameters->InitV0DownStairs(mu, sigma);
Log->Write("INFO: \tdesired speed downstairs mu=%f , sigma=%f", mu, sigma);
}//------------------------------------------------------------------------
if (xAgentPara->FirstChild("escalator_upstairs")) {
double mu = xmltof(xAgentPara->FirstChildElement("escalator_upstairs")->Attribute("mu"));
double sigma = xmltof(xAgentPara->FirstChildElement("escalator_upstairs")->Attribute("sigma"));
agentParameters->InitEscalatorUpStairs(mu, sigma);
Log->Write("INFO: \tspeed of escalator upstairs mu=%f , sigma=%f", mu, sigma);
}
if (xAgentPara->FirstChild("escalator_downstairs")) {
double mu = xmltof(xAgentPara->FirstChildElement("escalator_downstairs")->Attribute("mu"));
double sigma = xmltof(xAgentPara->FirstChildElement("escalator_downstairs")->Attribute("sigma"));
agentParameters->InitEscalatorDownStairs(mu, sigma);
Log->Write("INFO: \tspeed of escalator downstairs mu=%f , sigma=%f", mu, sigma);
}
if (xAgentPara->FirstChild("v0_idle_escalator_upstairs")) {
double mu = xmltof(xAgentPara->FirstChildElement("v0_idle_escalator_upstairs")->Attribute("mu"));
double sigma = xmltof(
xAgentPara->FirstChildElement("v0_idle_escalator_upstairs")->Attribute("sigma"));
agentParameters->InitV0IdleEscalatorUpStairs(mu, sigma);
Log->Write("INFO: \tdesired speed idle escalator upstairs mu=%f , sigma=%f", mu, sigma);
}
if (xAgentPara->FirstChild("v0_idle_escalator_downstairs")) {
double mu = xmltof(xAgentPara->FirstChildElement("v0_idle_escalator_downstairs")->Attribute("mu"));