Commit 6790e6fd authored by karthik's avatar karthik

Merge branch 'v0.7' of https://cst.version.fz-juelich.de/jupedsim/jpscore into v0.7

parents ca7866d2 740dd556
......@@ -6,14 +6,16 @@ All notable changes to this project will be documented in this file.
### Added
- Changelog file
- Rimea testcases
- risk tolerance factor (value in [0 1]) for pedestrian. Pedestrians with high values are likely to take more risks.
- Boost testcases for geometry functions
- risk tolerance factor (value in [0 1]) for pedestrian. Pedestrians with high values are likely to take more risks.
- Sources for generating agents at runtime. Parameter are frequency(agents per seconds) and maximum number
### Changed
-
-
### Fixed
-
- Visiblity in 3D
-
### Fixed
......
......@@ -141,6 +141,7 @@ endif(BUILD_TESTING OR BUILD_CPPUNIT_TEST)
if(BUILD_TESTING)
file(GLOB_RECURSE test_py_files "${CMAKE_TEST_DIR}/*runtest_*.py")
endif(BUILD_TESTING)
# add sources and headers
set ( source_files
Simulation.cpp
......@@ -183,6 +184,13 @@ set ( source_files
pedestrian/Pedestrian.cpp
pedestrian/AgentsParameters.cpp
pedestrian/Knowledge.cpp
pedestrian/AgentsQueue.cpp
pedestrian/AgentsSource.cpp
pedestrian/Pedestrian.cpp
pedestrian/AgentsSourcesManager.cpp
pedestrian/StartDistribution.cpp
voronoi/VoronoiDiagramGenerator.cpp
routing/AccessPoint.cpp
routing/DirectionStrategy.cpp
......@@ -260,12 +268,17 @@ set ( header_files
routing/cognitive_map/fire_mesh/Knot.h
routing/cognitive_map/fire_mesh/FireMeshStorage.h
pedestrian/Pedestrian.h
pedestrian/PedDistributor.h
pedestrian/Ellipse.h
pedestrian/AgentsParameters.h
pedestrian/Knowledge.h
pedestrian/AgentsQueue.h
pedestrian/AgentsSource.h
pedestrian/Pedestrian.h
pedestrian/AgentsSourcesManager.h
pedestrian/StartDistribution.h
voronoi/VoronoiDiagramGenerator.h
mpi/LCGrid.h
......@@ -315,11 +328,9 @@ add_library ( core STATIC ${source_files} )
#add_library ( core SHARED ${source_files} )
#Target
add_executable(
jpscore main.cpp
)
add_executable( jpscore main.cpp )
target_link_libraries(jpscore core)
target_link_libraries(jpscore core )
if(WIN32)
target_link_libraries (jpscore core wsock32)
......@@ -328,6 +339,37 @@ endif(WIN32)
if(CGAL_FOUND)
target_link_libraries (jpscore ${CGAL_CORE_LIBRARY})
endif(CGAL_FOUND)
#protocol buffer
find_package(Protobuf)
if(PROTOBUF_FOUND)
message(STATUS "Protocol buffer library found")
include_directories(${PROTOBUF_INCLUDE_DIRS})
set (hybrid_source_files
matsim/HybridSimulationManager.cpp
matsim/JPSserver.cpp
matsim/JPSclient.cpp
matsim/MATSimInterface.pb.cc
matsim/MATSimInterface.grpc.pb.cc
)
set (hybrid_header_files
matsim/JPSclient.h
matsim/MATSimInterface.grpc.pb.h
matsim/MATSimInterface.proto
matsim/HybridSimulationManager.h
matsim/JPSserver.h
matsim/MATSimInterface.pb.h
)
add_library (hybrid STATIC ${hybrid_source_files} )
target_link_libraries (core hybrid grpc++_unsecure grpc gpr ${PROTOBUF_LIBRARY} dl)
#PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS foo.proto)
#add_executable(jpscore ${PROTO_SRCS} ${PROTO_HDRS})
endif(PROTOBUF_FOUND)
#----------------------------------------------------------------------
# enable as many warnings as possible
# set(warning_flags "-Wall -Wextra")
......
......@@ -116,7 +116,7 @@ string TrajectoriesJPSV04::WritePed(Pedestrian* ped)
void TrajectoriesJPSV04::WriteHeader(long nPeds, double fps, Building* building, int seed)
{
nPeds=building->GetAllPedestrians().size();
//nPeds=building->GetAllPedestrians().size();
string tmp;
tmp =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" "<trajectories>\n";
......@@ -158,6 +158,7 @@ void TrajectoriesJPSV04::WriteGeometry(Building* building)
// first the rooms
//to avoid writing navigation line twice
vector<int> navLineWritten;
rooms_to_plot.push_back("U9");
for (const auto& it:building->GetAllRooms())
{
......@@ -167,7 +168,7 @@ void TrajectoriesJPSV04::WriteGeometry(Building* building)
continue;
for (int k = 0; k < r->GetNumberOfSubRooms(); k++) {
SubRoom* s = r->GetSubRoom(k); //if(s->GetSubRoomID()!=0) continue;
SubRoom* s = r->GetSubRoom(k); //if(s->GetSubRoomID()!=7) continue;
geometry.append(s->WriteSubRoom());
// the hlines
......@@ -444,7 +445,7 @@ void TrajectoriesVTK::WriteFooter()
void TrajectoriesJPSV06::WriteHeader(long nPeds, double fps, Building* building, int seed)
{
nPeds=building->GetAllPedestrians().size();
//nPeds=building->GetAllPedestrians().size();
string tmp;
tmp =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" "<trajectories>\n";
......@@ -624,7 +625,7 @@ void TrajectoriesXML_MESH::WriteGeometry(Building* building)
void TrajectoriesJPSV05::WriteHeader(long nPeds, double fps, Building* building, int seed)
{
nPeds=building->GetAllPedestrians().size();
//nPeds=building->GetAllPedestrians().size();
string tmp;
tmp = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" "<trajectories>\n";
char agents[CLENGTH] = "";
......
......@@ -62,7 +62,7 @@ public:
{
_outputHandler = NULL;
};
virtual ~Trajectories(){};
virtual ~Trajectories(){delete _outputHandler;};
virtual void WriteHeader(long nPeds, double fps, Building* building, int seed)=0;
virtual void WriteGeometry(Building* building)=0;
virtual void WriteFrame(int frameNr, Building* building)=0;
......
......@@ -125,8 +125,8 @@ void TraVisToClient::createConnection()
/* start the socket session */
if (!startSocketSession()) {
fprintf(stderr, "startSocketSession() failed!");
fprintf(stderr, "socket creation failed for host [%s] on port [%d]!",_hostname.c_str(),_port);
fprintf(stderr, "startSocketSession() failed!\n");
fprintf(stderr, "socket creation failed for host [%s] on port [%d]!\n",_hostname.c_str(),_port);
exit(EXIT_FAILURE);
}
......@@ -286,7 +286,6 @@ TraVisToClient::createServerSocket(unsigned short portNumber)
}
dtrace("server started at port %hu", portNumber);
dtrace("leaving createServerSocket()");
return (sock);
}
......
......@@ -25,7 +25,6 @@
*
**/
#ifndef TRAVISTOCLIENT_H_
#define TRAVISTOCLIENT_H_
......@@ -48,7 +47,6 @@
// fprintf(stderr, "%-15s|%03d| ", fileName, lineNumber);
// }
// #ifdef TRACE_LOGGING
/*
......@@ -62,20 +60,15 @@
fprintf(stderr, "ERROR: "), \
fprintf(stderr, __VA_ARGS__), \
_printErrorMessage())
*/
*/
// // #define dtrace(...) _printDebugLine(__FILE__, __LINE__, false, __VA_ARGS__)
// // #define derror(...) _printDebugLine(__FILE__, __LINE__, true, __VA_ARGS__)
// #else
// #define dtrace(...) ((void) 0)
// #define derror(...) (fprintf(stderr, __VA_ARGS__), _printErrorMessage())
// #endif /* TRACE_LOGGING */
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
......@@ -95,7 +88,6 @@ typedef int socklen_t;
#define startSocketSession() _startWin32SocketSession()
#define stopSocketSession() _stopWin32SocketSession()
#else
#include <unistd.h>
#include <netinet/in.h>
......@@ -111,17 +103,15 @@ typedef int socket_t;
#define SOCKET_ERROR (-1)
#endif
#ifndef IPPORT_USERRESERVED
#define IPPORT_USERRESERVED (5000) ///< up to this number, ports are reserved and should not be used
#endif
#define PORT 8989
#define HOST "localhost"
class TraVisToClient {
class TraVisToClient
{
public:
/// create a client with specific parameters
......@@ -147,7 +137,8 @@ private:
unsigned long lookupHostAddress(const char *hostName);
socket_t createClientSocket(const char *serverName, unsigned short portNumber);
socket_t createClientSocket(const char *serverName,
unsigned short portNumber);
socket_t createServerSocket(unsigned short portNumber);
......@@ -166,8 +157,6 @@ private:
#define closesocket close
#endif
private:
bool _isConnected;
socket_t _tcpSocket;
......
This diff is collapsed.
......@@ -51,6 +51,12 @@
#include "pedestrian/PedDistributor.h"
#include "routing/CognitiveMapRouter.h"
#include "events/EventManager.h"
#include "pedestrian/AgentsSourcesManager.h"
//Forward declarations
//class AgentsSourcesManager;
class EventManager;
class HybridSimulationManager;
class Simulation
{
......@@ -58,7 +64,7 @@ private:
///Number of pedestrians in the simulation
long _nPeds;
///Maximum simulation time
double _tmax;
//double _tmax;
/// time step
double _deltaT;
/// frame rate for the trajectories
......@@ -69,22 +75,31 @@ private:
std::unique_ptr<Building> _building;
/// Force model to use
std::shared_ptr<OperationalModel> _operationalModel;
/// differential equation solver
/// Manage all route choices algorithms
std::shared_ptr<RoutingEngine> _routingEngine;
/// differential equation solver
ODESolver* _solver;
/// writing the trajectories to file
IODispatcher* _iod;
///new: EventManager
/// EventManager
EventManager* _em;
/// argument parser
ArgumentParser _argsParser;
/// profiling flag
bool _profiling;
/// architecture flag
int _hpc;
/// Agents sources manager
AgentsSourcesManager _agentSrcManager;
/// hybrid simulation manager
//HybridSimulationManager
std::shared_ptr<HybridSimulationManager>_hybridSimManager=nullptr;
public:
/**
* Constructor
*/
Simulation(const ArgumentParser& args);
/**
* Destructor
*/
virtual ~Simulation();
/**
......@@ -98,38 +113,53 @@ public:
bool InitArgs(const ArgumentParser& args);
/**
* @return the total simulated/evacuation time
* Update the route of the pedestrians and reassign rooms, in the case a room change happens
*/
int RunSimulation();
void UpdateRoutesAndLocations();
/**
* Updathe route of the pedestrians and reassign rooms, in the case a room change happens
* Perform some initialisation for the simulation.
* such as writing the headers for the trajectories.
* @param the maximal number of pedestrian
*/
void UpdateRoutesAndLocations();
//void Update(double &b, double &p, double &t, double &g);
void RunHeader(long nPed=-1);
/**
* Set the ProfilingFlag
* Run the main part of the simulation
*/
void SetProfileFlag(bool flag);
int RunBody(double maxSimTime);
/**
* Get the ProfileFlag
* Perform some finalization like writing the
* footers for the trajectories.
*/
bool GetProfileFlag();
void RunFooter();
/**
* Get the HPCFlag
* Run a standard simulation
* @return the total simulated/evacuation time
*/
int GetHPCFlag();
int RunStandardSimulation(double maxSimTime);
/**
* print some statistics about the simulation
*/
void PrintStatistics();
/**
* @return the agents source manager
*/
AgentsSourcesManager& GetAgentSrcManager();
/**
* Check if any agents are waiting to enter the simulation
*/
void ProcessAgentsQueue();
/**
* @return a pointer to the building object
*/
Building* GetBuilding();
};
#endif /*SIMULATION_H_*/
......@@ -94,7 +94,17 @@ BOOST_AUTO_TEST_CASE(LINE_ISINLINESEGMENT_TEST)
for (int i = 0; i < 20; ++i)
BOOST_CHECK(!L1.IsInLineSegment(Point(i, i)));
Point P1 (30.1379, 124.485);
Point P2 (41.4647, 124.485);
Point P3 (38.4046,104.715);
Point P4 (33.7146,104.715);
Line L2(P1,P2);
Line L3(P3,P4);
BOOST_CHECK(L2.IsInLineSegment(P3)==false);
BOOST_CHECK(L2.IsInLineSegment(P4)==false);
BOOST_CHECK(L3.IsInLineSegment(P1)==false);
BOOST_CHECK(L3.IsInLineSegment(P2)==false);
BOOST_MESSAGE("Leaving is_in_linesegment test");
}
......
......@@ -232,7 +232,8 @@ bool EventManager::UpdateAgentKnowledge(Building* _b)
if( (ped1->GetPos()-ped2->GetPos()).Norm()<_updateRadius)
{
//maybe same room and subroom ?
if(_b->IsVisible(ped1->GetPos(),ped2->GetPos()))
vector<SubRoom*> empty;
if(_b->IsVisible(ped1->GetPos(),ped2->GetPos(),empty))
{
MergeKnowledge(ped1, ped2); //ped1->SetSpotlight(true);
ped2->SetNewEventFlag(true);
......
This diff is collapsed.
......@@ -47,13 +47,16 @@ class OutputHandler;
class TiXmlElement;
class TiXmlNode;
class AgentsParameters;
class HybridSimulationManager;
extern OutputHandler* Log;
class ArgumentParser
{
private:
string pHostname;
string _hostname;
string pTrajectoriesFile;
string pErrorLogFile;
string pNavMeshFilename;
......@@ -96,7 +99,7 @@ private:
int pLog;
int pPort;
int _embedMesh;
int pMaxOpenMPThreads;
int _maxOpenMPThreads;
int pModel;
FileFormat pFormat;
vector<pair<int, RoutingStrategy> > pRoutingStrategies;
......@@ -110,7 +113,9 @@ private:
*/
std::shared_ptr<DirectionStrategy> p_exit_strategy;
std::shared_ptr<OperationalModel> p_op_model;
std::shared_ptr<RoutingEngine> p_routingengine;
std::shared_ptr<RoutingEngine> _routingengine;
std::shared_ptr<HybridSimulationManager> _hybridSimManager=nullptr;
private:
bool ParseGCFMModel(TiXmlElement* xGCFM);
......@@ -217,6 +222,8 @@ public:
int GetHPCFlag() const;
bool ShowStatistics()const;
std::shared_ptr<HybridSimulationManager> GetHybridSimManager() const;
vector<pair<int, RoutingStrategy> > GetRoutingStrategy() const;
const FileFormat& GetFileFormat() const;
......
......@@ -49,6 +49,7 @@
// should be true only when using this file in the simulation core
#define _SIMULATOR 1
//#define _USE_PROTOCOL_BUFFER 1
......@@ -88,7 +89,7 @@
#define FINAL_DEST_OUT -1
// Linked cells
#define LIST_EMPTY -1
#define LIST_EMPTY -1
enum RoomState {
......
......@@ -51,15 +51,15 @@
using namespace std;
Building::Building()
{
_caption = "no_caption";
_projectFilename = "";
_geometryFilename= "";
_routingEngine = nullptr;
_linkedCellGrid = nullptr;
_savePathway = false;
}
//Building::Building()
//{
// _caption = "no_caption";
// _projectFilename = "";
// _geometryFilename= "";
// _routingEngine = nullptr;
// _linkedCellGrid = nullptr;
// _savePathway = false;
//}
#ifdef _SIMULATOR
Building::Building(const std::string& filename, const std::string& rootDir, RoutingEngine& engine, PedDistributor& distributor, double linkedCellSize)
......@@ -72,7 +72,7 @@ Building::Building(const std::string& filename, const std::string& rootDir, Rout
//todo: what happens if any of these methods failed (return false)? throw exception ?
this->LoadGeometry();
this->LoadRoutingInfo(filename);
this->AddSurroundingRoom();
//this->AddSurroundingRoom();
this->InitGeometry();
this->LoadTrafficInfo();
distributor.Distribute(this);
......@@ -843,26 +843,37 @@ SubRoom* Building::GetSubRoomByUID( int uid)
return NULL;
}
bool Building::IsVisible(Line* l1, Line* l2, bool considerHlines)
//bool Building::IsVisible(Line* l1, Line* l2, bool considerHlines)
//{
//
// for(auto&& itr_room: _rooms)
// {
// for(auto&& itr_subroom: itr_room.second->GetAllSubRooms())
// {
// if(itr_subroom.second->IsVisible(l1,l2,considerHlines)==false) return false;
// }
// }
// return true;
//}
bool Building::IsVisible(const Point& p1, const Point& p2, const std::vector<SubRoom*>& subrooms, bool considerHlines)
{
for(auto&& itr_room: _rooms)
//loop over all subrooms if none is provided
if (subrooms.empty())
{
for(auto&& itr_subroom: itr_room.second->GetAllSubRooms())
for(auto&& itr_room: _rooms)
{
if(itr_subroom.second->IsVisible(l1,l2,considerHlines)==false) return false;
for(auto&& itr_subroom: itr_room.second->GetAllSubRooms())
{
if(itr_subroom.second->IsVisible(p1,p2,considerHlines)==false) return false;
}
}
}
return true;
}
bool Building::IsVisible(const Point& p1, const Point& p2, bool considerHlines)
{
for(auto&& itr_room: _rooms)
else
{
for(auto&& itr_subroom: itr_room.second->GetAllSubRooms())
for(auto&& sub: subrooms)
{
if(itr_subroom.second->IsVisible(p1,p2,considerHlines)==false) return false;
if(sub and sub->IsVisible(p1,p2,considerHlines)==false) return false;
}
}
......@@ -937,7 +948,6 @@ void Building::InitGrid(double cellSize)
y_max = y_max + 1*cellSize;
double boundaries[4] = { x_min, x_max, y_min, y_max };
int pedsCount = _allPedestians.size();
//no algorithms
// the domain is made of a single cell
......@@ -953,7 +963,8 @@ void Building::InitGrid(double cellSize)
Log->Write("INFO: \tInitializing the grid with cell size: %f ", cellSize);
}
_linkedCellGrid = new LCGrid(boundaries, cellSize, pedsCount);
//_linkedCellGrid = new LCGrid(boundaries, cellSize, _allPedestians.size());
_linkedCellGrid = new LCGrid(boundaries, cellSize, Pedestrian::GetAgentsCreated());
_linkedCellGrid->ShallowCopy(_allPedestians);
Log->Write("INFO: \tDone with Initializing the grid ");
......@@ -1144,7 +1155,8 @@ void Building::DeletePedestrian(Pedestrian* &ped)
}
//update the stats before deleting
Transition* trans =GetTransitionByUID(ped->GetExitIndex());
if(trans) {
if(trans)
{
trans->IncreaseDoorUsage(1, ped->GetGlobalTime());
}
delete ped;
......@@ -1169,9 +1181,12 @@ void Building::AddPedestrian(Pedestrian* ped)
void Building::GetPedestrians(int room, int subroom, std::vector<Pedestrian*>& peds) const
{
for(unsigned int p = 0;p<_allPedestians.size();p++){
Pedestrian* ped=_allPedestians[p];
if(room==ped->GetRoomID() && subroom==ped->GetSubRoomID())
//for(unsigned int p = 0;p<_allPedestians.size();p++){
// Pedestrian* ped=_allPedestians[p];
for (auto&& ped : _allPedestians)
{
if ((room == ped->GetRoomID()) && (subroom == ped->GetSubRoomID()))
{
peds.push_back(ped);
}
......
......@@ -73,7 +73,7 @@ private:
public:
/// constructor
Building();
//Building();
Building(const std::string&, const std::string&, RoutingEngine&, PedDistributor&, double);
/// destructor
virtual ~Building();
......@@ -122,14 +122,14 @@ public:
* Alls walls and transitions and crossings are used in this check.
* The use of hlines is optional, because they are not real, can can be considered transparent
*/
bool IsVisible(Line* l1, Line* l2, bool considerHlines=false);
//bool IsVisible(Line* l1, Line* l2, bool considerHlines=false);
/**
* @return true if the two points are visible from each other.
* Alls walls and transitions and crossings are used in this check.
* The use of hlines is optional, because they are not real, can be considered transparent
*/
bool IsVisible(const Point& p1, const Point& p2, bool considerHlines=false);
bool IsVisible(const Point& p1, const Point& p2, const std::vector<SubRoom*>& subrooms, bool considerHlines=false);
/**
* @return a crossing or a transition matching the given caption.
......
......@@ -36,9 +36,6 @@ using namespace std;
Crossing::Crossing()
{
_id = -1;
_room1 = NULL;
_subRoom1 = NULL;