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

Commit 52d2597b authored by Erik Andresen's avatar Erik Andresen
Browse files

jpscore with the new JPS AI Routing Framework

parent 6c2eee5f
Pipeline #6371 failed with stages
in 10 seconds
......@@ -36,12 +36,6 @@ endif ()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${warnings}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${warnings}")
# TODO clean up. no flags.
#set(CMAKE_CXX_STANDARD 11)
#set(CMAKE_CXX_STANDARD_REQUIRED ON)
#set(CMAKE_CXX_EXTENSIONS OFF)
if (NOT BUILD_TESTING)
set(BUILD_TESTING OFF) # test units & python tests are not generated.
endif (NOT BUILD_TESTING)
......@@ -204,6 +198,9 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
#boost
find_package(Boost COMPONENTS timer chrono system filesystem unit_test_framework REQUIRED)
#CGAL
find_package(CGAL REQUIRED)
# test all cpp-files in Utest
if (BUILD_TESTING OR BUILD_CPPUNIT_TEST)
......@@ -313,7 +310,7 @@ set(source_files
#quickest
routing/quickest/QuickestPathRouter.cpp
#AI router
#Smoke router
routing/smoke_router/SmokeRouter.cpp
routing/smoke_router/GraphNetwork.cpp
routing/smoke_router/NavigationGraph.cpp
......@@ -339,6 +336,24 @@ set(source_files
routing/smoke_router/cognitiveMap/internnavigationnetwork.cpp
visiLibity/source_code/visilibity.cpp
#AI router
routing/ai_router/AIRouter.cpp
routing/ai_router/BrainStorage.cpp
routing/ai_router/cognitiveMap/associations.cpp
routing/ai_router/cognitiveMap/connection.cpp
routing/ai_router/cognitiveMap/cognitivemap.cpp
routing/ai_router/cognitiveMap/landmark.cpp
routing/ai_router/cognitiveMap/region.cpp
routing/ai_router/cognitiveMap/landmarknetwork.cpp
routing/ai_router/cognitiveMap/internnavigationnetwork.cpp
routing/ai_router/perception/visualsystem.cpp
routing/ai_router/perception/visibleenvironment.cpp
routing/ai_router/perception/cgalgeometry.cpp
routing/ai_router/perception/sign.cpp
routing/ai_router/Cortex.cpp
poly2tri/common/shapes.cpp
poly2tri/sweep/sweep_context.cpp
poly2tri/sweep/advancing_front.cpp
......@@ -385,7 +400,7 @@ set(header_files
#quickest
routing/quickest/QuickestPathRouter.h
#AI router
#Smoke router
routing/smoke_router/SmokeRouter.h
routing/smoke_router/GraphNetwork.h
routing/smoke_router/NavigationGraph.h
......@@ -411,6 +426,23 @@ set(header_files
routing/smoke_router/cognitiveMap/internnavigationnetwork.h
visiLibity/source_code/visilibity.hpp
#AI router
routing/ai_router/AIRouter.h
routing/ai_router/BrainStorage.h
routing/ai_router/cognitiveMap/associations.h
routing/ai_router/cognitiveMap/connection.cpp
routing/ai_router/cognitiveMap/cognitivemap.h
routing/ai_router/cognitiveMap/landmark.h
routing/ai_router/cognitiveMap/region.h
routing/ai_router/cognitiveMap/landmarknetwork.h
routing/ai_router/cognitiveMap/internnavigationnetwork.h
routing/ai_router/perception/visualsystem.h
routing/ai_router/perception/visibleenvironment.h
routing/ai_router/perception/cgalgeometry.h
routing/ai_router/perception/sign.h
routing/ai_router/Cortex.h
pedestrian/Pedestrian.h
pedestrian/PedDistributor.h
pedestrian/Ellipse.h
......@@ -432,6 +464,7 @@ set(header_files
general/ArgumentParser.h
general/Macros.h
general/randomnumbergenerator.h
geometry/Crossing.h
geometry/NavLine.h
......@@ -483,12 +516,14 @@ set(header_files
)
add_library(core STATIC ${source_files})
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIRS})
add_library(cnpy SHARED "cnpy/cnpy.cpp")
target_link_libraries(cnpy ${ZLIB_LIBRARIES})
#add_library ( core SHARED ${source_files} )
#Target
......@@ -507,19 +542,51 @@ if (Boost_FOUND)
# suppress warnings in boost libraries with attribute SYSTEM
include_directories(SYSTEM ${Boost_INCLUDE_DIR})
# todo: is this necessary?
target_link_libraries(core ${Boost_LIBRARIES} cnpy)
endif ()
if (GMP_FOUND)
message(STATUS "GMP FOUND: " ${GMP_FOUND})
message(STATUS "GMP_LIBRARY: " ${GMP_LIBRARIES})
message(STATUS "GMP_INCLUDE_DIR: " ${GMP_INCLUDE_DIR})
include_directories(SYSTEM ${GMP_INCLUDE_DIR})
endif()
if (MPFR_FOUND)
message(STATUS "MPFR FOUND: " ${MPFR_FOUND})
message(STATUS "MPFR_LIBRARY: " ${MPFR_LIBRARIES})
message(STATUS "MPFR_INCLUDE_DIR: " ${MPFR_INCLUDE_DIR})
include_directories(SYSTEM ${MPFR_INCLUDE_DIR})
#target_link_libraries(jpscore ${MPFR_LIBRARIES})
endif()
if (CGAL_FOUND)
message(STATUS "CGAL FOUND: " ${CGAL_FOUND})
message(STATUS "CGAL_LIBRARY_DIRS: " ${CGAL_LIBRARIES_DIR})
message(STATUS "CGAL_INCLUDE_DIRS: " ${CGAL_INCLUDE_DIRS})
#message(STATUS "CGAL_LIB_VERSION: " ${CGAL_LIB_VERSION})
message(STATUS "CGAL_libraries: " ${CGAL_LIBRARY})
#link_directories(${CGAL_LIBRARIES_DIR})
#link_directories(${)
include_directories(SYSTEM ${CGAL_INCLUDE_DIRS})
#message(STATUS "CGAL_3rdparty" ${CGAL_3RD_PARTY_LIBRARIES})
#target_link_libraries(jpscore ${CGAL_LIBRARIES})
endif()
target_link_libraries(jpscore core)
if (WIN32)
target_link_libraries(jpscore core wsock32)
endif (WIN32)
# if(CGAL_FOUND)
# target_link_libraries (jpscore ${CGAL_CORE_LIBRARY})
# endif(CGAL_FOUND)
target_link_libraries(jpscore ${GMP_LIBRARIES} ${MPFR_LIBRARIES} ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES})
##if (JPS_AS_A_SERVICE)
#find_package(Protobuf REQUIRED)
......
......@@ -41,6 +41,7 @@
#include "../routing/global_shortest/GlobalRouter.h"
#include "../routing/quickest/QuickestPathRouter.h"
#include "../routing/smoke_router/SmokeRouter.h"
#include "../routing/ai_router/AIRouter.h"
#include "../routing/ff_router/ffRouter.h"
IniFileParser::IniFileParser(Configuration* config)
......@@ -1100,6 +1101,16 @@ bool IniFileParser::ParseRoutingStrategies(TiXmlNode* routingNode, TiXmlNode* ag
if (!ParseCogMapOpts(e))
return false;
}
else if ((strategy == "AI") &&
(std::find(usedRouter.begin(), usedRouter.end(), id) != usedRouter.end()) ) {
Router *r = new AIRouter(id, ROUTING_AI);
_config->GetRoutingEngine()->AddRouter(r);
Log->Write("\nINFO: \tUsing AIRouter");
///Parsing additional options
if (!ParseAIOpts(e))
return false;
}
else if ((strategy == "ff_global_shortest") &&
(std::find(usedRouter.begin(), usedRouter.end(), id) != usedRouter.end()) ) {
//pRoutingStrategies.push_back(make_pair(id, ROUTING_FF_GLOBAL_SHORTEST));
......@@ -1241,6 +1252,67 @@ bool IniFileParser::ParseCogMapOpts(TiXmlNode* routingNode)
return true;
}
bool IniFileParser::ParseAIOpts(TiXmlNode* routingNode) {
TiXmlNode *sensorNode = routingNode->FirstChild();
if (!sensorNode) {
Log->Write("ERROR:\tNo sensors found.\n");
return false;
}
/// static_cast to get access to the method 'addOption' of the AIRouter
AIRouter *r = static_cast<AIRouter *>(_config->GetRoutingEngine()->GetAvailableRouters().back());
std::vector<std::string> sensorVec;
for (TiXmlElement *e = sensorNode->FirstChildElement("sensor"); e;
e = e->NextSiblingElement("sensor")) {
string sensor = e->Attribute("description");
sensorVec.push_back(sensor);
Log->Write("INFO: \tSensor <%s> added.", sensor.c_str());
}
r->addOption("Sensors", sensorVec);
TiXmlElement *cogMap = routingNode->FirstChildElement("cognitive_map");
if (!cogMap) {
Log->Write("ERROR:\tCognitive Map not specified.\n");
return false;
}
//std::vector<std::string> cogMapStatus;
//cogMapStatus.push_back(cogMap->Attribute("status"));
//Log->Write("INFO: \tAll pedestrian starting with a(n) %s cognitive maps", cogMapStatus[0].c_str());
//r->addOption("CognitiveMap", cogMapStatus);
std::vector<std::string> cogMapFiles;
if (!cogMap->Attribute("files")) {
Log->Write("WARNING:\tNo input files for the cognitive map specified!");
}
else
{
cogMapFiles.push_back(cogMap->Attribute("files"));
r->addOption("CognitiveMapFiles", cogMapFiles);
}
//Signs
TiXmlElement *signs = routingNode->FirstChildElement("signage");
if (!signs)
{
Log->Write("INFO: \tNo signage specified");
}
else
{
r->addOption("SignFiles",std::vector<std::string>{signs->Attribute("file")});
}
return true;
}
bool IniFileParser::ParseLinkedCells(const TiXmlNode& linkedCellNode)
{
if (linkedCellNode.FirstChild("linkedcells")) {
......
......@@ -62,6 +62,8 @@ private:
bool ParseCogMapOpts(TiXmlNode* routingNode);
bool ParseAIOpts(TiXmlNode* routingNode);
bool ParseLinkedCells(const TiXmlNode& linkedCellNode);
bool ParseStepSize(TiXmlNode& stepNode);
......
......@@ -37,6 +37,10 @@
#include "../math/OperationalModel.h"
#include "../JPSfire/B_walking_speed/WalkingSpeed.h"
#include "../JPSfire/C_toxicity_analysis/ToxicityAnalysis.h"
//for random numbers
#include "randomnumbergenerator.h"
//This class provides a data container for all configuration parameters.
class AgentsParameters;
......@@ -114,6 +118,9 @@ public:
//ff router
_has_specific_goals = false;
_write_VTK_files = false;
//for random numbers
_rdGenerator=RandomNumberGenerator();
}
std::shared_ptr<WalkingSpeed> GetWalkingSpeed () {return _walkingSpeed; };
void SetWalkingSpeed(std::shared_ptr<WalkingSpeed> & w) {_walkingSpeed = w; };
......@@ -302,6 +309,8 @@ public:
void AddAgentsParameters(std::shared_ptr<AgentsParameters> agentsParameters,
int id) { _agentsParameters[id] = agentsParameters; };
RandomNumberGenerator* GetRandomNumberGenerator() const {return &_rdGenerator;};
#ifdef _JPS_AS_A_SERVICE
const bool GetRunAsService() const { return _runAsService; };
......@@ -382,6 +391,8 @@ private:
std::string _projectRootDir;
bool _showStatistics;
mutable RandomNumberGenerator _rdGenerator;
FileFormat _fileFormat;
std::map<int, std::shared_ptr<AgentsParameters> > _agentsParameters;
#ifdef _JPS_AS_A_SERVICE
......
......@@ -95,6 +95,12 @@
// Not-a-Number (NaN)
#define J_NAN std::numeric_limits<double>::quiet_NaN()
//update rate for AI router
#ifndef AI_UPDATE_RATE
#define AI_UPDATE_RATE 5.0 //fps
#endif
enum RoomState {
ROOM_CLEAN=0,
ROOM_SMOKED=1
......@@ -121,6 +127,7 @@ enum RoutingStrategy {
ROUTING_QUICKEST,
ROUTING_FROM_FILE,
ROUTING_SMOKE,
ROUTING_AI,
ROUTING_FLOORFIELD,
ROUTING_FF_GLOBAL_SHORTEST,
ROUTING_FF_LOCAL_SHORTEST,
......@@ -297,31 +304,31 @@ inline void ReplaceStringInPlace(std::string& subject, const std::string& search
//**************************************************************
//Text attributes
#define OFF 0 //All attributes off
#define BRIGHT 1 //Bold on
#define OFF 0 //All attributes off
#define BRIGHT 1 //Bold on
// 4 Underscore (on monochrome display adapter only)
#define BLINK 5 //Blink on
#define BLINK 5 //Blink on
// 7 Reverse video on
// 8 Concealed on
// Foreground colors
#define BLACK 30
#define CYAN 36
#define WHITE 37
#define RED 31
#define GREEN 32
#define YELLOW 33
#define BLUE 34
#define MAGENTA 35
#define JPS_BLACK 30
#define JPS_CYAN 36
#define JPS_WHITE 37
#define JPS_RED 31
#define JPS_GREEN 32
#define JPS_YELLOW 33
#define JPS_BLUE 34
#define JPS_MAGENTA 35
// Background colors
#define BG_BLACK 40
#define BG_RED 41
#define BG_GREEN 42
#define BG_YELLOW 43
#define BG_BLUE 44
#define BG_CYAN 47
#define BG_WHITE 47
#define JPS_BG_BLACK 40
#define JPS_BG_RED 41
#define JPS_BG_GREEN 42
#define JPS_BG_YELLOW 43
#define JPS_BG_BLUE 44
#define JPS_BG_CYAN 47
#define JPS_BG_WHITE 47
// Special caracters
#define HOME printf("\033[1;1H"); // cursor up left
......
#ifndef RANDOMNUMBERGENERATOR_H
#define RANDOMNUMBERGENERATOR_H
#include <random>
class RandomNumberGenerator
{
public:
//Engine and distribution with random seed
explicit RandomNumberGenerator(){std::random_device rd;
_randomEngine = std::mt19937(rd());
_rdDistribution = std::uniform_real_distribution<double> (0,1);}
//Engine and distribution with specific seed
explicit RandomNumberGenerator(int seed):_randomEngine(std::mt19937(seed)),
_rdDistribution(std::uniform_real_distribution<double> (0,1)){}
double GetRandomRealBetween0and1(){return _rdDistribution(_randomEngine);}
std::mt19937& GetRandomEngine(){return _randomEngine;}
void SetSeed(int seed){_randomEngine = std::mt19937(seed);}
private:
std::mt19937 _randomEngine;
std::uniform_real_distribution<double> _rdDistribution;
};
#endif // RANDOMNUMBERGENERATOR_H
......@@ -28,6 +28,10 @@
#include "Room.h"
#include "SubRoom.h"
#include "../IO/OutputHandler.h"
#include <sstream>
#include <memory>
using namespace std;
......@@ -190,6 +194,36 @@ void Room::SetOutputHandler(OutputHandler* oh)
_outputFile=oh;
}
std::vector<Point> Room::GetBoundaryVertices() const
{
double xMin=FLT_MAX;
double yMin=FLT_MAX;
double xMax=-FLT_MAX;
double yMax=-FLT_MAX;
for(auto&& itr_subroom: this->GetAllSubRooms())
{
const std::vector<Point> vertices = itr_subroom.second->GetPolygon();
for (Point point:vertices)
{
if (point._x>xMax)
xMax=point._x;
if (point._x<xMin)
xMin=point._x;
if (point._y>yMax)
yMax=point._y;
if (point._y<yMin)
yMin=point._y;
}
}
return std::vector<Point>{Point(xMin,yMin),Point(xMin,yMax),Point(xMax,yMax),Point(xMax,yMin)};
}
OutputHandler* Room::GetOutputHandler() const
{
return _outputFile;
......
......@@ -32,6 +32,7 @@
#include <algorithm>
#include <memory>
#include "../general/Macros.h"
#include "../geometry/Point.h"
//forward declarations
class OutputHandler;
......@@ -147,6 +148,14 @@ public:
*/
void AddTransitionID(int ID);
/**
* @return Vector with the vertices of the geometry's outer boundary rect
*/
std::vector<Point> GetBoundaryVertices() const;
/**
* Debug output for this class
*/
......
......@@ -32,11 +32,15 @@
#include "Obstacle.h"
#include "SubRoom.h"
#include "Transition.h"
#include "Hline.h"
#ifdef _SIMULATOR
#include "../pedestrian/Pedestrian.h"
#endif //_SIMULATOR
#include <cmath>
using namespace std;
/************************************************************
......
/**
* \file AIRouter.cpp
* \date Feb 1, 2014
* \version v0.7
* \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved.
*
* \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/>.
*
* \section Description
*
*
**/
#include "AIRouter.h"
#include "../Router.h"
#include "BrainStorage.h"
#include "./cognitiveMap/cognitivemap.h"
//#include "NavigationGraph.h"
//#include "./sensor/SensorManager.h"
#include "../../geometry/SubRoom.h"
#include "../../geometry/NavLine.h"
#include "../../geometry/Building.h"
#include "../../pedestrian/Pedestrian.h"
#include "../../tinyxml/tinyxml.h"
AIRouter::AIRouter()
{
building=nullptr;
// cm_storage=nullptr;
//sensor_manager=nullptr;
}
AIRouter::AIRouter(int id, RoutingStrategy s) : Router(id, s)
{
building=nullptr;
// cm_storage=nullptr;
//sensor_manager=nullptr;
}
AIRouter::~AIRouter()
{
//delete brain_storage;
//delete sensor_manager;
}
int AIRouter::FindExit(Pedestrian * p)
{
if (std::fmod(std::roundf(p->GetGlobalTime()*100),std::roundf(1.0/AI_UPDATE_RATE*100))==0.0)// && p->GetGlobalTime()>0)
{
//Log->Write(std::to_string(p->GetGlobalTime()));
//sensor_manager->execute(p, SensorManager::PERIODIC);
int status = FindDestination(p);
//(*cm_storage)[p]->UpdateSubRoom();
return status;
}
return 1;
}
int AIRouter::FindDestination(Pedestrian * p)
{
// Discover doors
//sensor_manager->execute(p, SensorManager::NO_WAY);
//check if there is a way to the outside the pedestrian knows (in the cognitive map)
//--------------------COGMAP----------------------------
//Update isovists
(*brain_storage)[p]->GetPerceptionAbilities().UpdateCurrentEnvironment();
(*brain_storage)[p]->GetPerceptionAbilities().UpdateSeenEnv();
// update cogmap
(*brain_storage)[p]->GetCognitiveMap().UpdateMap();
//Find next appropriate landmark
(*brain_storage)[p]->GetCognitiveMap().FindNextTarget();
// find possible crossings in seenEnvironment e.g. to proceed to landmark
std::vector<NavLine> navLines = (*brain_storage)[p]->GetPerceptionAbilities().GetPossibleNavLines(
(*brain_storage)[p]->GetPerceptionAbilities().GetSeenEnvironmentAsPointVec(building->GetRoom(p->GetRoomID())));
NavLine nextNvLine=(*brain_storage)[p]->FindApprCrossing(navLines);
// std::ofstream myfile2;
// std::string str2 = "./isovists/navLinesBefore_pos"+std::to_string(p->GetID())+"_"+std::to_string((int)(std::round(p->GetGlobalTime()*100)))+".txt";
// myfile2.open (str2);
// myfile2 << std::to_string(nextNvLine.GetCentre()._x) << " " << std::to_string(nextNvLine.GetCentre()._y) << std::endl;
// myfile2.close();
// find possible crossings in currentEnv to proceed to nextNvLine
navLines = (*brain_storage)[p]->GetPerceptionAbilities().GetPossibleNavLines(
(*brain_storage)[p]->GetPerceptionAbilities().GetCurrentEnvironmentAsPointVec());
//Find appropriate visible crossing to reach next app. landmark
nextNvLine=(*brain_storage)[p]->FindApprVisibleCrossing(nextNvLine,navLines);
// std::ofstream myfile;
// std::string str = "./isovists/navLines_pos"+std::to_string(p->GetID())+"_"+std::to_string((int)(std::round(p->GetGlobalTime()*100)))+".txt";
// myfile.open (str);
// myfile << std::to_string(nextNvLine.GetCentre()._x) << " " << std::to_string(nextNvLine.GetCentre()._y) << std::endl;
// myfile.close();
p->SetExitLine(&nextNvLine);
return 1;
}