Commit e9d6ede5 authored by karthik's avatar karthik

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

parents 998592eb 380bf83e
......@@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
- 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
- Option to color the pedestrians by group,spotlight,velocity,group,knowledge,router,final_goal,intermediate_goal ( <trajectories format="xml-plain" fps="8" color_mode="group">)
### Changed
-
......@@ -16,7 +17,7 @@ All notable changes to this project will be documented in this file.
### Fixed
- Visiblity in 3D
-
- Numerous geometrical operations
### Fixed
-
......
......@@ -158,7 +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");
//rooms_to_plot.push_back("U9");
for (const auto& it:building->GetAllRooms())
{
......
......@@ -150,7 +150,7 @@ bool Simulation::InitArgs(const ArgumentParser& args)
case FORMAT_XML_PLAIN: {
OutputHandler* tofile = new FileHandler(
args.GetTrajectoriesFile().c_str());
Trajectories* output = new TrajectoriesJPSV04();
Trajectories* output = new TrajectoriesJPSV05();
output->SetOutputHandler(tofile);
_iod->AddIO(output);
break;
......
......@@ -143,10 +143,9 @@ bool EventManager::ReadEventsXml()
_updateFrequency = xmltoi(xEvents->ToElement()->Attribute("update_time"), 1);
_updateRadius = xmltoi(xEvents->ToElement()->Attribute("update_radius"), 2);
string color=xmltoa(xEvents->ToElement()->Attribute("agents_color_by_knowledge"), "false");
if(color=="true")
Pedestrian::SetColorMode(BY_KNOWLEDGE);
//string color=xmltoa(xEvents->ToElement()->Attribute("agents_color_by_knowledge"), "false");
//if(color=="true")
// Pedestrian::SetColorMode(BY_KNOWLEDGE);
//Pedestrian::SetColorMode(BY_SPOTLIGHT);
for (TiXmlElement* e = xEvents->FirstChildElement("event"); e;
......
......@@ -340,6 +340,25 @@ bool ArgumentParser::ParseIniFile(string inifile)
if (format == "vtk")
pFormat = FORMAT_VTK;
//color mode
string color_mode =
xMainNode->FirstChildElement("trajectories")->Attribute(
"color_mode") ?
xMainNode->FirstChildElement("trajectories")->Attribute(
"color_mode") :
"velocity";
if(color_mode=="velocity") Pedestrian::SetColorMode(AgentColorMode::BY_VELOCITY);
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"))
{
......
......@@ -39,9 +39,6 @@
#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
......@@ -137,8 +134,11 @@ enum AgentColorMode {
BY_VELOCITY=1,
BY_KNOWLEDGE,
BY_ROUTE,
BY_ROUTER,
BY_SPOTLIGHT,
//BY_GROUP
BY_GROUP,
BY_FINAL_GOAL,
BY_INTERMEDIATE_GOAL
};
//global functions for convenience
......
......@@ -206,54 +206,15 @@ Point Line::ShortestPoint(const Point &p) const {
return f;
}
/* Prüft, ob Punkt p im Liniensegment enthalten ist
* Verfahren wie bei Line::ShortestPoint(), d. h,
* lambda berechnen und prüfen ob zwischen 0 und 1
* */
//bool Line::IsInLine(const Point& p) const {
// double ax, ay, bx, by, px, py;
// const Point& a = GetPoint1();
// const Point& b = GetPoint2();
// double lambda;
// ax = a.GetX();
// ay = a.GetY();
// bx = b.GetX();
// by = b.GetY();
// px = p.GetX();
// py = p.GetY();
// if (fabs(ax - bx) > J_EPS_DIST) {
// lambda = (px - ax) / (bx - ax);
// } else if (fabs(ay - by) > J_EPS_DIST) {
// lambda = (py - ay) / (by - ay);
// } else {
// Log->Write("ERROR: \tIsInLine: Endpunkt = Startpunkt!!!");
// exit(0);
// }
// return (0 <= lambda) && (lambda <= 1);
//}
/*
* Prüft, ob Punkt p im Liniensegment enthalten ist
* algorithm from:
* http://stackoverflow.com/questions/328107/how-can-you-determine-a-point-is-between-two-other-points-on-a-line-segment
*
* TODO: FIXME Failing with test ( 30.1379 : 124.485 )--( 41.4647 : 124.485 ) and ( 38.4046 : 104.715 )--( 33.7146 : 104.715 )
* */
bool Line::IsInLineSegment(const Point &p) const
{
Point differenceTwoAndOne = _point2 - _point1;
Point differencePAndOne = p - _point1;
// cross product to check if point i colinear
if ((differenceTwoAndOne).CrossProduct(differencePAndOne) > J_EPS)
return false;
// dotproduct and distSquared to check if point is in segment and not just in line
double dotp = differencePAndOne.ScalarProduct(differenceTwoAndOne);
return !(dotp < 0 || (differenceTwoAndOne).NormSquare() < dotp);
//return fabs( (_point1-p ).Norm() + (_point2-p ).Norm() - (_point2-_point1 ).Norm() )<J_EPS;
return fabs( (_point1-p ).Norm() + (_point2-p ).Norm() - (_point2-_point1 ).Norm() )<J_EPS;
}
/* Berechnet direkt den Abstand von p zum Segment l
......
......@@ -37,13 +37,14 @@
#include <thread>
#include <functional>
#include <iomanip>
int main(int argc, char **argv)
{
//gathering some statistics about the runtime
time_t starttime, endtime;
// Log = new FileHandler("./Logfile.dat");
// default logger
Log = new STDIOHandler();
// Parsing the arguments
......@@ -60,6 +61,7 @@ int main(int argc, char **argv)
{
//evacuation time
int evacTime = 0;
Log->Write("INFO: \tStart runSimulation()");
#ifdef _USE_PROTOCOL_BUFFER
//Start the thread for managing incoming messages from MatSim
......@@ -72,29 +74,24 @@ int main(int argc, char **argv)
//process the normal simulation
else
#endif
if(sim.GetAgentSrcManager().GetMaxAgentNumber())
{
//Start the thread for managing the sources of agents if any
//std::thread t1(sim.GetAgentSrcManager());
std::thread t1(&AgentsSourcesManager::Run, &sim.GetAgentSrcManager());
//main thread for the simulation
Log->Write("INFO: \tStart runSimulation()");
evacTime = sim.RunStandardSimulation(args->GetTmax());
Log->Write("\nINFO: \tEnd runSimulation()");
time(&endtime);
//Join the main thread
t1.join();
}
else
{
//main thread for the simulation
Log->Write("INFO: \tStart runSimulation()");
evacTime = sim.RunStandardSimulation(args->GetTmax());
Log->Write("\nINFO: \tEnd runSimulation()");
time(&endtime);
}
if(sim.GetAgentSrcManager().GetMaxAgentNumber())
{
//Start the thread for managing the sources of agents if any
//std::thread t1(sim.GetAgentSrcManager());
std::thread t1(&AgentsSourcesManager::Run, &sim.GetAgentSrcManager());
//main thread for the simulation
evacTime = sim.RunStandardSimulation(args->GetTmax());
//Join the main thread
t1.join();
}
else
{
//main thread for the simulation
evacTime = sim.RunStandardSimulation(args->GetTmax());
}
Log->Write("\nINFO: \tEnd runSimulation()");
time(&endtime);
// some statistics output
if(args->ShowStatistics())
......@@ -109,23 +106,22 @@ int main(int argc, char **argv)
}
double execTime = difftime(endtime, starttime);
Log->Write("\nExec Time [s] : %.2f", execTime);
Log->Write("Evac Time [s] : %d", evacTime);
Log->Write("Realtime Factor : %.2f X", evacTime / execTime);
Log->Write("Number of Threads : %d", args->GetMaxOpenMPThreads());
Log->Write("Warnings : %d", Log->GetWarnings());
Log->Write("Errors : %d", Log->GetErrors());
std::stringstream summary;
summary << std::setprecision(2)<<std::fixed;
summary<<"\nExec Time [s] : "<< execTime<<std::endl;
summary<<"Evac Time [s] : "<< evacTime<<std::endl;
summary<<"Realtime Factor : "<< evacTime / execTime<<" X " <<std::endl;
summary<<"Number of Threads : "<< args->GetMaxOpenMPThreads()<<std::endl;
summary<<"Warnings : "<< Log->GetWarnings()<<std::endl;
summary<<"Errors : "<< Log->GetErrors()<<std::endl;
Log->Write(summary.str().c_str());
//force an output to the screen if the log is not the standard output
if (nullptr == dynamic_cast<STDIOHandler*>(Log))
{
printf("\nExec Time [s] : %4.2f\n", execTime);
printf("Evac Time [s] : %d\n", evacTime);
printf("Realtime Factor : %.2f (X)\n", evacTime / execTime);
printf("Number of Threads : %d\n", args->GetMaxOpenMPThreads());
printf("Warnings : %d\n", Log->GetWarnings());
printf("Errors : %d\n", Log->GetErrors());
printf("%s\n", summary.str().c_str());
}
}
else
{
......
......@@ -23,7 +23,7 @@
using namespace std;
bool AgentsSourcesManager::_isCompleted=false;
bool AgentsSourcesManager::_isCompleted=true;
AgentsSourcesManager::AgentsSourcesManager()
{
......@@ -42,7 +42,6 @@ void AgentsSourcesManager::Run()
{
Log->Write("INFO:\tStarting agent manager thread");
//Generate all agents required for the complete simulation
//It might be more efficient to generate at each frequency step
for (const auto& src : _sources)
......@@ -62,25 +61,17 @@ void AgentsSourcesManager::Run()
{
int current_time = Pedestrian::GetGlobalTime();
//first step
//if(current_time==0){
//finished=ProcessAllSources();
// ProcessAllSources();
// //cout<<"here:"<<endl; exit(0);
//}
if ((current_time != _lastUpdateTime)
&& ((current_time % updateFrequency) == 0))
{
//cout<<"TIME:"<<current_time<<endl;
finished=ProcessAllSources();
_lastUpdateTime = current_time;
//cout << "source size: " << _sources.size() << endl;
}
//wait some time
//std::this_thread::sleep_for(std::chrono::milliseconds(1));
} while (!finished);
Log->Write("INFO:\tTerminating agent manager thread");
_isCompleted = true;//exit(0);
_isCompleted = true;
}
bool AgentsSourcesManager::ProcessAllSources() const
......@@ -442,6 +433,7 @@ void AgentsSourcesManager::GenerateAgents()
void AgentsSourcesManager::AddSource(std::shared_ptr<AgentsSource> src)
{
_sources.push_back(src);
_isCompleted=false;//at least one source was provided
}
const std::vector<std::shared_ptr<AgentsSource> >& AgentsSourcesManager::GetSources() const
......
......@@ -103,7 +103,7 @@ void Pedestrian::SetID(int i)
_id = i;
if(i<=0)
{
cout<<"invalid ID"<<i<<endl;exit(0);
cout<<"invalid ID"<<i<<endl;exit(0);
}
}
......@@ -840,39 +840,58 @@ int Pedestrian::GetAgentsCreated()
int Pedestrian::GetColor()
{
//default color is by velocity
int color = -1;
double v0 = GetV0Norm();
if (v0 != 0.0) {
double v = GetV().Norm();
color = (int) (v / v0 * 255);
}
string key;
switch (_colorMode)
{
case BY_SPOTLIGHT:
{
if (_spotlight==false)
color=-1;
return -1;
break;
}
case BY_VELOCITY:
break;
{
int color = -1;
double v0 = GetV0Norm();
if (v0 != 0.0) {
double v = GetV().Norm();
color = (int) (v / v0 * 255);
}
return color;
}
break;
// Hash the knowledge represented as String
// Hash the knowledge represented as String
case BY_KNOWLEDGE:
{
string key=GetKnowledgeAsString();
std::hash<std::string> hash_fn;
color = hash_fn(key) % 255;
//cout<<"color: "<<hash_fn(key)<<endl;
//cout<<" key : "<<key<<endl;
key=GetKnowledgeAsString();
}
break;
case BY_ROUTER:
case BY_ROUTE:
{
string key = std::to_string(_routingStrategy);
std::hash<std::string> hash_fn;
color = hash_fn(key) % 255;
key = std::to_string(_routingStrategy);
}
break;
case BY_GROUP:
{
key = std::to_string(_group);
}
break;
case BY_FINAL_GOAL:
{
key=std::to_string(_desiredFinalDestination);
}
break;
case BY_INTERMEDIATE_GOAL:
{
key=std::to_string(_exitIndex);
}
break;
......@@ -880,6 +899,7 @@ int Pedestrian::GetColor()
break;
}
return color;
std::hash<std::string> hash_fn;
return hash_fn(key) % 255;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment