Commit bafa01f3 authored by Oliver Schmidts's avatar Oliver Schmidts

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

parents 775c07fd e672edd3
......@@ -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_*/
DistributeInSubRoom(sr, N, allpos, &pid,dist,building);
sr -> subroom
N -> no of ped in subroom
pid -> pedestrian id
dist -> room
building -> building
void PedDistributor :: DistributeInSubRoom_MitchellAlg(int nAgents , std::vector<Point>& positions) {
AgentsParameters* agents_para=para->GetGroupParameters();
std::srand(time(0));
int index = rand() % positions.size();
std::vector<std::unique_ptr<Point>> pos;
for (int i = 0; i < nAgents; ++i) {
Pedestrian* ped = new Pedestrian();
// PedIndex
ped->SetID(*pid);
ped->SetAge(para->GetAge());
ped->SetGender(para->GetGender());
ped->SetHeight(para->GetHeight());
ped->SetFinalDestination(para->GetGoalId());
ped->SetGroup(para->GetGroupId());
ped->SetRouter(building->GetRoutingEngine()->GetRouter(para->GetRouterId()));
JEllipse E = JEllipse();
E.SetAv(agents_para->GetAtau());
E.SetAmin(agents_para->GetAmin());
E.SetBmax(agents_para->GetBmax());
E.SetBmin(agents_para->GetBmin());
ped->SetEllipse(E);
ped->SetTau(agents_para->GetTau());
ped->SetV0Norm(agents_para->GetV0(),
agents_para->GetV0DownStairs(),
agents_para->GetV0UpStairs());
if (i > 0) {
std::set<int> candidates;
while (candidates.size() < 10)
candidates.insert(rand() % positions.size());
double dist = 0;
double longest = 0;
for (auto itr :: candidates) {
double shortest = 0;
for (unsigned int j = 0; j < pos.size(); ++j)
dist = (positions[itr] - pos[j]).norm();
if (dist == 0 || dist < shortest)
shortest = dist;
if (shortest > longest) {
longest = shortest;
index = itr;
}
}
}
pos.push_back(positions[index]);
ped->SetPos(positions[index],true); //true for the initial position
ped->SetBuilding(building);
positions.erase(positions.begin() + index);
ped->SetRoomID(para->GetRoomId(),"");
ped->SetSubRoomID(r->GetSubRoomID());
ped->SetPatienceTime(para->GetPatience());
ped->SetPremovementTime(para->GetPremovementTime());
ped->SetRiskTolerance(para->GetRiskTolerance());
const Point& start_pos = para->GetStartPosition();
if((std::isnan(start_pos._x)==0 ) && (std::isnan(start_pos._y)==0 ) ) {
if(r->IsInSubRoom(start_pos)==false){
Log->Write("ERROR: \t cannot distribute pedestrian %d in Room %d at fixed position %s",
*pid, para->GetRoomId(), start_pos.toString().c_str());
Log->Write("ERROR: \t Make sure that the position is inside the geometry and belongs to the specified room / subroom");
exit(EXIT_FAILURE);
}
ped->SetPos(start_pos,true); //true for the initial position
Log->Write("INFO: \t fixed position for ped %d in Room %d %s",
*pid, para->GetRoomId(), start_pos.toString().c_str());
}
//r->AddPedestrian(ped);
building->AddPedestrian(ped);
(*pid)++;
}
}
......@@ -32,6 +32,7 @@
#include "../../geometry/Obstacle.h"
#include "../../geometry/Point.h"
#include "../../geometry/Wall.h"
#include "../../IO/OutputHandler.h"
#include <cstdlib>
#include <ctime>
......@@ -102,7 +103,42 @@ BOOST_FIXTURE_TEST_CASE(Obstacle_whichQuad_test, Obstacle)
BOOST_AUTO_TEST_CASE(Obstacle_Contains_test)
{
BOOST_MESSAGE("starting obstacle contains test");
// test
Point P1(0, 0);
Point P2(0, 10);
Point P3(10, 10);
Point P4(10, 0);
Obstacle obs1;
Wall w1(P1, P2);
Wall w2(P2, P3);
Wall w3(P3, P4);
Wall w4(P4, P1);
obs1.AddWall(w1);
obs1.AddWall(w2);
obs1.AddWall(w3);
obs1.AddWall(w4);
obs1.SetClosed(1);
obs1.ConvertLineToPoly();
// inside the obstacle check
for (int i = 1; i < 10; ++i)
BOOST_CHECK(obs1.Contains(Point(i, static_cast<float>(i) / 100)) == true);
// on the edge check
for (int i = 0; i <11; ++i) {
BOOST_CHECK_MESSAGE(obs1.Contains(Point(0, i)) == true, " ( " << 0 <<", "<< i << ")");
BOOST_CHECK_MESSAGE(obs1.Contains(Point(i, 0)) == true, " ( " << i <<", "<< 0 << ")");
BOOST_CHECK_MESSAGE(obs1.Contains(Point(10, i)) == true, " ( " << 10 <<", "<< i << ")");
BOOST_CHECK_MESSAGE(obs1.Contains(Point(i, 10)) == true, " ( " << i <<", "<< 10 << ")");
}
// outside the obstacle check
for (int i = 1; i < 10; ++i)
BOOST_CHECK(obs1.Contains(Point(-i, i*i)) == false);
BOOST_MESSAGE("Leaving obstacle contains test");
}
......@@ -110,6 +146,7 @@ BOOST_AUTO_TEST_CASE(Obstacle_ConvertLineToPoly_Test)
{
BOOST_MESSAGE("starting obstacle ConvertLineToPoly test");
const double PI = 3.14159265358979323846;
for (int i = 1; i < 10; ++i)
{
Point P1 (cos(PI/i), sin(PI/i));
......@@ -118,6 +155,14 @@ BOOST_AUTO_TEST_CASE(Obstacle_ConvertLineToPoly_Test)
Point P4 (-i, -i*i);
Point P5 (100, 100);
std::vector<Point> added_pts;
added_pts.emplace_back(P1);
added_pts.emplace_back(P2);
added_pts.emplace_back(P3);
added_pts.emplace_back(P4);
added_pts.emplace_back(P5);
const unsigned temp = added_pts.size();
Obstacle obs1;
Wall w1(P1, P2);
......@@ -139,6 +184,21 @@ BOOST_AUTO_TEST_CASE(Obstacle_ConvertLineToPoly_Test)
obs1.AddWall(w5);
BOOST_CHECK_MESSAGE(obs1.ConvertLineToPoly() == true, obs1.ConvertLineToPoly());
// GetPolygon test
int flag = 0;
const std::vector<Point> poly_pts = obs1.GetPolygon();
for (unsigned j = 0; j < poly_pts.size(); j++)
for (unsigned k = 0; k < temp; ++k)
if (poly_pts[j] == added_pts[k]) {
++flag;
added_pts.erase(added_pts.begin() + k);
k = temp;
}
BOOST_CHECK_MESSAGE(flag == temp, poly_pts.size() << " == " << temp);
//BOOST_CHECK_EQUAL_COLLECTIONS(poly_pts.begin(), poly_pts.end(),
//added_pts.begin(), added_pts.end());
}
BOOST_MESSAGE("Leaving obstacle ConvertLineToPoly test");
}
......@@ -172,4 +232,5 @@ BOOST_AUTO_TEST_CASE(Obstacle_GetCentroid_Test)
}
BOOST_MESSAGE("Leaving obstacle GetCentroid & IntersectWithLine test");
}
BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
......@@ -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