Commit a9f06f78 authored by GrgrLmml's avatar GrgrLmml

extracted XML parsers

ini.xml is now parsed into a global configuration
bugfix in Line.cpp (collinear but disjunct lines are no longer classified as intersecting)
GRPC / jupedsim as a service -- ready (currently deactivated in CMakeLists.txt and Macros.h)
reformated Code according to stroustrup with 5 spaces indent
parent 0d4b8cc2
This diff is collapsed.
This diff is collapsed.
/**
* \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 30.03.16.
//
#ifndef JPSCORE_GEOFILEPARSER_H
#define JPSCORE_GEOFILEPARSER_H
#include "../general/Configuration.h"
#include "../geometry/Building.h"
#include "../geometry/GeometryReader.h"
//TODO: the class name GeoFileParser is misleading as the ``geometry'' file contains among others also relations (transitions)
//TODO: between geometries/rooms. Probably, EnvironmentFileParser would be better, still parts of the environment are
//TODO: currently stored in the ``ini'' file (e.g. goals) [gl march '16]
//TODO: currently stored in the ``ini'' file (e.g. goals) [gl march '16]
class GeoFileParser : public GeometryReader {
public:
GeoFileParser(const Configuration* configuration);
virtual void LoadBuilding(Building* building) override;
virtual bool LoadTrafficInfo(Building* building) override;
private:
const Configuration* _configuration;
bool LoadGeometry(Building* building);
bool LoadRoutingInfo(Building* filename);
};
#endif //JPSCORE_GEOFILEPARSER_H
This diff is collapsed.
/**
* \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.
//
#ifndef JPSCORE_INIFILEPARSER_H
#define JPSCORE_INIFILEPARSER_H
#include <string>
#include "../general/Configuration.h"
#include "../routing/DirectionStrategy.h"
class OutputHandler;
class TiXmlElement;
class TiXmlNode;
extern OutputHandler* Log;
class IniFileParser {
public:
IniFileParser(Configuration* config);
bool Parse(std::string iniFile);
private:
bool ParseGCFMModel(TiXmlElement* xGCFM);
bool ParseGompertzModel(TiXmlElement* xGompertz);
bool ParseGradientModel(TiXmlElement* xGradient);
bool ParseVelocityModel(TiXmlElement* xVelocity);
void ParseAgentParameters(TiXmlElement* operativModel);
bool ParseRoutingStrategies(TiXmlNode* routingNode);
bool ParseCogMapOpts(TiXmlNode* routingNode);
bool ParseLinkedCells(const TiXmlNode& linkedCellNode);
bool ParseStepSize(TiXmlNode& stepNode);
bool ParsePeriodic(TiXmlNode& Node);
bool ParseNodeToSolver(const TiXmlNode& solverNode);
bool ParseStrategyNodeToObject(const TiXmlNode& strategyNode);
Configuration* _config;
int _model;
std::shared_ptr<DirectionStrategy> _exit_strategy;
};
#endif //JPSCORE_INIFILEPARSER_H
/**
* \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 31.03.16.
//
#include "PedDistributionParser.h"
#include "../tinyxml/tinyxml.h"
PedDistributionParser::PedDistributionParser(const Configuration* configuration)
:_configuration(configuration)
{
}
bool PedDistributionParser::LoadPedDistribution(vector<std::shared_ptr<StartDistribution>>& startDis,
vector<std::shared_ptr<StartDistribution>>& startDisSub,
std::vector<std::shared_ptr<AgentsSource>>& startDisSources)
{
Log->Write("INFO: \tLoading and parsing the persons attributes");
TiXmlDocument doc(_configuration->GetProjectFile());
if (!doc.LoadFile()) {
Log->Write("ERROR: \t%s", doc.ErrorDesc());
Log->Write("ERROR: \t could not parse the project file");
return false;
}
TiXmlNode* xRootNode = doc.RootElement()->FirstChild("agents");
if (!xRootNode) {
Log->Write("ERROR:\tcould not load persons attributes");
return false;
}
TiXmlNode* xDist = xRootNode->FirstChild("agents_distribution");
for (TiXmlElement* e = xDist->FirstChildElement("group"); e;
e = e->NextSiblingElement("group")) {
int room_id = xmltoi(e->Attribute("room_id"));
int group_id = xmltoi(e->Attribute("group_id"));
int subroom_id = xmltoi(e->Attribute("subroom_id"), -1);
int number = xmltoi(e->Attribute("number"), 0);
int agent_para_id = xmltoi(e->Attribute("agent_parameter_id"), -1);
int goal_id = xmltoi(e->Attribute("goal_id"), FINAL_DEST_OUT);
int router_id = xmltoi(e->Attribute("router_id"), -1);
int route_id = xmltoi(e->Attribute("route_id"), -1);
int age = xmltoi(e->Attribute("age"), -1);
string gender = xmltoa(e->Attribute("gender"), "female");
double height = xmltof(e->Attribute("height"), -1);
double patience = xmltof(e->Attribute("patience"), 5);
double premovement_mean = xmltof(e->Attribute("pre_movement_mean"), 0);
double premovement_sigma = xmltof(e->Attribute("pre_movement_sigma"), 0);
double risk_tolerance_mean = xmltof(e->Attribute("risk_tolerance_mean"), 0);
double risk_tolerance_sigma = xmltof(e->Attribute("risk_tolerance_sigma"), 0);
double x_min = xmltof(e->Attribute("x_min"), -FLT_MAX);
double x_max = xmltof(e->Attribute("x_max"), FLT_MAX);
double y_min = xmltof(e->Attribute("y_min"), -FLT_MAX);
double y_max = xmltof(e->Attribute("y_max"), FLT_MAX);
double bounds[4] = {x_min, x_max, y_min, y_max};
//sanity check
if ((x_max<x_min) || (y_max<y_min)) {
Log->Write(
"ERROR:\tinvalid bounds [%0.2f,%0.2f,%0.2f,%0.2f] of the group [%d]. Max and Min values mismatched?",
group_id, x_min, x_max, y_min, y_max);
return false;
}
auto dis = std::shared_ptr<StartDistribution>(new StartDistribution(_configuration->GetSeed()));
dis->SetRoomID(room_id);
dis->SetSubroomID(subroom_id);
//dis->SetSubroomUID(subroom_uid);
dis->SetGroupId(group_id);
dis->Setbounds(bounds);
dis->SetAgentsNumber(number);
dis->SetAge(age);
dis->SetGender(gender);
dis->SetGoalId(goal_id);
dis->SetRouteId(route_id);
dis->SetRouterId(router_id);
dis->SetHeight(height);
dis->SetPatience(patience);
dis->InitPremovementTime(premovement_mean, premovement_sigma);
if (e->Attribute("risk_tolerance_mean") && e->Attribute("risk_tolerance_sigma")) {
std::string distribution_type = "normal";
double risk_tolerance_mean = xmltof(e->Attribute("risk_tolerance_mean"), NAN);
double risk_tolerance_sigma = xmltof(e->Attribute("risk_tolerance_sigma"), NAN);
Log->Write("INFO:\trisk tolerance mu = %f, risk tolerance sigma = %f\n", risk_tolerance_mean,
risk_tolerance_sigma);
dis->InitRiskTolerance(distribution_type, risk_tolerance_mean, risk_tolerance_sigma);
}
else if (e->Attribute("risk_tolerance_alpha") && e->Attribute("risk_tolerance_beta")) {
std::string distribution_type = "beta";
double risk_tolerance_alpha = xmltof(e->Attribute("risk_tolerance_alpha"), NAN);
double risk_tolerance_beta = xmltof(e->Attribute("risk_tolerance_beta"), NAN);
Log->Write("INFO:\trisk tolerance alpha = %f, risk tolerance beta = %f\n", risk_tolerance_alpha,
risk_tolerance_beta);
dis->InitRiskTolerance(distribution_type, risk_tolerance_alpha, risk_tolerance_beta);
}
else {
std::string distribution_type = "normal";
double risk_tolerance_mean = 0.;
double risk_tolerance_sigma = 1.;
Log->Write("INFO:\trisk tolerance mu = %f, risk tolerance sigma = %f\n", risk_tolerance_mean,
risk_tolerance_sigma);
dis->InitRiskTolerance(distribution_type, risk_tolerance_mean, risk_tolerance_sigma);
}
if (subroom_id==-1) { // no subroom was supplied
startDis.push_back(dis);
}
else {
startDisSub.push_back(dis);
}
if (_configuration->GetAgentsParameters().count(agent_para_id)==0) {
Log->Write(
"ERROR:\t Please specify which set of agents parameters (agent_parameter_id) to use for the group [%d]!",
group_id);
Log->Write("ERROR:\t Default values are not implemented yet");
return false;
}
dis->SetGroupParameters(_configuration->GetAgentsParameters().at(agent_para_id).get());
if (e->Attribute("start_x") && e->Attribute("start_y")) {
double startX = xmltof(e->Attribute("start_x"), NAN);
double startY = xmltof(e->Attribute("start_y"), NAN);
Log->Write("INFO:\tstart_x = %f, start_y = %f\n", startX, startY);
dis->SetStartPosition(startX, startY, 0.0);
}
}
//Parse the sources
TiXmlNode* xSources = xRootNode->FirstChild("agents_sources");
if (xSources) {
for (TiXmlElement* e = xSources->FirstChildElement("source"); e;
e = e->NextSiblingElement("source")) {
int id = xmltoi(e->Attribute("id"), -1);
int frequency = xmltoi(e->Attribute("frequency"), -1);
int agents_max = xmltoi(e->Attribute("agents_max"), -1);
int group_id = xmltoi(e->Attribute("group_id"), -1);
string caption = xmltoa(e->Attribute("caption"), "no caption");
auto source = std::shared_ptr<AgentsSource>(
new AgentsSource(id, caption, agents_max, group_id,
frequency));
startDisSources.push_back(source);
Log->Write("INFO:\tSource with id %s will not be parsed !", e->Attribute("id"));
}
}
Log->Write("INFO: \t...Done");
return true;
}
/**
* \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 31.03.16.
//
#ifndef JPSCORE_PEDDISTRIBUTIONPARSER_H
#define JPSCORE_PEDDISTRIBUTIONPARSER_H
#include "../pedestrian/PedDistributionLoader.h"
class PedDistributionParser : public PedDistributionLoader {
public:
PedDistributionParser(const Configuration* configuration);
virtual bool LoadPedDistribution(std::vector<std::shared_ptr<StartDistribution>>& startDis,
std::vector<std::shared_ptr<StartDistribution>>& startDisSub,
std::vector<std::shared_ptr<AgentsSource>>& startDisSources) override;
private:
const Configuration* _configuration;
};
#endif //JPSCORE_PEDDISTRIBUTIONPARSER_H
This diff is collapsed.
......@@ -33,7 +33,6 @@
#ifndef SIMULATION_H_
#define SIMULATION_H_
#include "general/ArgumentParser.h"
#include "geometry/Building.h"
#include "geometry/SubRoom.h"
......@@ -52,16 +51,15 @@
#include "routing/CognitiveMapRouter.h"
#include "events/EventManager.h"
#include "pedestrian/AgentsSourcesManager.h"
#include "general/Configuration.h"
//Forward declarations
//class AgentsSourcesManager;
class EventManager;
class HybridSimulationManager;
class Simulation
{
class Simulation {
private:
///Number of pedestrians in the simulation
///Number of pedestrians in the simulation
long _nPeds;
///Maximum simulation time
//double _tmax;
......@@ -83,19 +81,18 @@ private:
IODispatcher* _iod;
/// EventManager
EventManager* _em;
/// argument parser
ArgumentParser _argsParser;
/// config
const Configuration* _config;
/// Agents sources manager
AgentsSourcesManager _agentSrcManager;
/// hybrid simulation manager
//HybridSimulationManager
std::shared_ptr<HybridSimulationManager>_hybridSimManager=nullptr;
int _periodic;
public:
/**
* Constructor
*/
Simulation(const ArgumentParser& args);
Simulation(const Configuration* args);
/**
* Destructor
......@@ -108,9 +105,9 @@ public:
long GetPedsNumber() const;
/**
* Read parameters from the argument parser class.
* Read parameters from config.
*/
bool InitArgs(const ArgumentParser& args);
bool InitArgs();
/**
* Update the route of the pedestrians and reassign rooms, in the case a room change happens
......@@ -131,13 +128,12 @@ public:
*/
void UpdateLocations();
/**
* Perform some initialisation for the simulation.
* such as writing the headers for the trajectories.
* @param the maximal number of pedestrian
*/
void RunHeader(long nPed=-1);
void RunHeader(long nPed = -1);
/**
* Run the main part of the simulation
......@@ -176,12 +172,11 @@ public:
*/
Building* GetBuilding();
/**
* Update the flow for the door that the pedestrian just crossed
* @param ped
*/
void UpdateFlowAtDoors(const Pedestrian &ped) const;
void UpdateFlowAtDoors(const Pedestrian& ped) const;
};
#endif /*SIMULATION_H_*/
find_package(PkgConfig)
pkg_check_modules(PC_GRPC grpc++)
set(GRPC_DEFINITIONS ${PC_GRPC_CFLAGS_OTHER})
find_path(GRPC_INCLUDE_DIR grpc++/grpc++.h
HINTS ${PC_GRPC_INCLUDEDIR} ${PC_GRPC_INCLUDE_DIRS}
PATHS_SUFIXES grpc++)
find_library(GRPC_LIBRARY NAMES grpc++ libgrpc++
HINTS ${PC_GRPC_LIBDIR} ${PC_GRPC_LIBRARY_DIRS})
set(GRPC_LIBRARIES ${GRPC_LIBRARY})
set(GRPC_INCLUD_DIRS ${GRPC_INCLUDE_DIR})
message(STATUS ${GRPC_LIBRARY})
message(STATUS ${GRPC_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GRPC DEFAULT_MSG
GRPC_LIBRARY GRPC_INCLUDE_DIR)
mark_as_advanced(GRPC_INCLUDE_DIR GRPC_LIBRARY)
find_program(GRPC_CPP_PLUGIN grpc_cpp_plugin) # Get full path to plugin
function(PROTOBUF_GENERATE_GRPC_CPP SRCS HDRS)
if(NOT ARGN)
message(SEND_ERROR "Error: PROTOBUF_GENERATE_GRPC_CPP() called without any proto files")
return()
endif()
if(PROTOBUF_GENERATE_CPP_APPEND_PATH) # This variable is common for all types of output.
# Create an include path for each file specified
foreach(FIL ${ARGN})
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
get_filename_component(ABS_PATH ${ABS_FIL} PATH)
list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
if(${_contains_already} EQUAL -1)
list(APPEND _protobuf_include_path -I ${ABS_PATH})
endif()
endforeach()
else()
set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR})
endif()
if(DEFINED PROTOBUF_IMPORT_DIRS)
foreach(DIR ${PROTOBUF_IMPORT_DIRS})
get_filename_component(ABS_PATH ${DIR} ABSOLUTE)
list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
if(${_contains_already} EQUAL -1)
list(APPEND _protobuf_include_path -I ${ABS_PATH})
endif()
endforeach()
endif()
set(${SRCS})
set(${HDRS})
foreach(FIL ${ARGN})
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
get_filename_component(FIL_WE ${FIL} NAME_WE)
list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.grpc.pb.cc")
list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.grpc.pb.h")
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.grpc.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.grpc.pb.h"
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
ARGS --grpc_out=${CMAKE_CURRENT_BINARY_DIR}
--plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN}
${_protobuf_include_path} ${ABS_FIL}
DEPENDS ${ABS_FIL} ${PROTOBUF_PROTOC_EXECUTABLE}
COMMENT "Running gRPC C++ protocol buffer compiler on ${FIL}"
VERBATIM)
endforeach()
set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
set(${SRCS} ${${SRCS}} PARENT_SCOPE)
set(${HDRS} ${${HDRS}} PARENT_SCOPE)
endfunction()
This diff is collapsed.
This diff is collapsed.
/**
* \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 23.03.16.
//
#ifndef JPSCORE_CONFIGURATION_H
#define JPSCORE_CONFIGURATION_H
#include <string>
#include <cstdlib>
#include <memory>
#include "Macros.h"
#ifdef _JPS_AS_A_SERVICE
#include "../hybrid/HybridSimulationManager.h"
#endif
#include "../routing/RoutingEngine.h"
#include "../math/OperationalModel.h"
//This class provides a data container for all configuration parameters.
class AgentsParameters;
#ifdef _JPS_AS_A_SERVICE
class HybridSimulationManager;
#endif
class Configuration {
public:
Configuration()
{
_log = 0;
_port = -1.0;
_routingEngine = std::shared_ptr<RoutingEngine>(new RoutingEngine());
}
int GetSolver() const { return _solver; };
void SetSolver(int solver) { _solver = solver; };
std::shared_ptr<RoutingEngine> GetRoutingEngine() const { return _routingEngine; };
//TODO: this is certainly not a config parameter but part of the model, we really should separate data and model [gl march '16]
void SetRoutingEngine(std::shared_ptr<RoutingEngine> routingEngine) { _routingEngine = routingEngine; };
int GetMaxOpenMPThreads() const { return _maxOpenMPThreads; };
void SetMaxOpenMPThreads(int maxOpenMPThreads) { _maxOpenMPThreads = maxOpenMPThreads; };
int GetLog() const { return _log; };
void SetLog(int log) { _log = log; };
int GetPort() const { return _port; };
void SetPort(int port) { _port = port; };
unsigned int GetSeed() const { return _port; };
void SetSeed(unsigned int seed) { _seed = seed; };
double GetFps() const { return _fps; };
void SetFps(double fps) { _fps = fps; };
double GetLinkedCellSize() const { return _linkedCellSize; };
void SetLinkedCellSize(double linkedCellSize) { _linkedCellSize = linkedCellSize; };
std::shared_ptr<OperationalModel> GetModel() const { return _model; };
void SetModel(std::shared_ptr<OperationalModel> model) { _model = model; };
double GetTmax() const { return _tMax; };
void SetTmax(double tMax) { _tMax = tMax; };
double Getdt() const { return _dT; };