Commit e7985c06 authored by Ulrich Kemloh's avatar Ulrich Kemloh

fixed errors where the quickest path was not using the triangulation

parent e381c6d8
......@@ -284,10 +284,14 @@ bool EventManager::UpdateRoute(Pedestrian* ped)
RoutingStrategy strategy=ped->GetRouter()->GetStrategy();
//retrieve the new router
Router*rout =engine->GetRouter(strategy);
//check for validity
ped->SetRouter(rout);
//clear all previous routes
ped->ClearMentalMap();
//only update if it is a new router
if(ped->GetRouter()!=rout)
{
//check for validity
ped->SetRouter(rout);
//clear all previous routes
ped->ClearMentalMap();
}
//ped->ClearKnowledge();
//overwrite/update the pedestrian router
if(!rout) status= false;
......@@ -465,7 +469,7 @@ bool EventManager::MergeKnowledge(Pedestrian* p1, Pedestrian* p2)
}
//p2->SetSpotlight(true);
//Pedestrian::SetColorMode(BY_SPOTLIGHT);
cout<<"refusing..."<<p2->GetID()<<endl;
//cout<<"refusing..."<<p2->GetID()<<endl;
return false;
}
......
......@@ -399,8 +399,9 @@ bool Line::IntersectionWithCircle(const Point &centre, double radius /*cm for pe
delta = b * b - 4 * a * c;
if (p1==p2) {
Log->Write("isLineCrossingCircle: Your line is a point");
if (p1==p2)
{
//Log->Write("isLineCrossingCircle: Your line is a point");
return false;
}
if (delta < 0.0) {
......
......@@ -514,7 +514,7 @@ bool SubRoom::SanityCheck()
if((IsConvex()==false) && (_hlines.size()==0))
{
Log->Write("WARNING:\t Room [%d] Subroom [%d] is not convex!",_roomID,_id);
Log->Write("\t\t you might consider adding extra hlines in your routing.xml file");
Log->Write(" \t you might consider adding extra hlines in your routing.xml file");
} else {
// everything is fine
}
......@@ -522,7 +522,7 @@ bool SubRoom::SanityCheck()
if(_hlines.size()==0)
{
Log->Write("WARNING:\t you have obstacles in room [%d] Subroom [%d]!",_roomID,_id);
Log->Write("\t\t you might consider adding extra hlines in your routing.xml file");
Log->Write(" \t you might consider adding extra hlines in your routing.xml file");
} else {
// everything is fine
}
......
......@@ -2,7 +2,7 @@
<JPScore project="JPS-Project" version="0.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_events.xsd">
<events update_frequency="1" update_radius="201.5" agents_color_by_knowledge="true">
<events update_frequency="1" update_radius="0.5" agents_color_by_knowledge="true">
<event time="10" type="door" state="close" id="2" caption="exit" />
<event time="30" type="door" state="close" id="3" caption="exit" />
</events>
......
......@@ -146,10 +146,12 @@
</operational_models>
<route_choice_models>
<router router_id="1" description="global_shortest">
<!-- <router router_id="1" description="global_shortest"> -->
<!-- <parameters></parameters> -->
<!-- </router> -->
<router router_id="1" description="quickest">
<parameters></parameters>
</router>
</route_choice_models>
</JuPedSim>
......@@ -95,7 +95,7 @@ Point DirectionInRangeBottleneck::GetTarget(Room* room, Pedestrian* ped) const
double d = 0.2;
// fix when using triangulation to avoid steering too near to the walls
double lenSq = ExitLine.LengthSquare();
if (lenSq >= 16 && lenSq < 50)
if (lenSq >= 19 && lenSq < 50)
d = 1;
else if(lenSq >= 50 &&lenSq < 100)
d = 2;
......
......@@ -1354,7 +1354,6 @@ string GlobalRouter::GetRoutingInfoFile()
// everything is fine. proceed with parsing
TiXmlElement* xMainNode = doc.RootElement();
TiXmlNode* xRouters=xMainNode->FirstChild("route_choice_models");
string nav_line_file="";
for(TiXmlElement* e = xRouters->FirstChildElement("router"); e;
......@@ -1362,13 +1361,9 @@ string GlobalRouter::GetRoutingInfoFile()
{
string strategy=e->Attribute("description");
vector<string> routers={"local_shortest", "global_shortest", "global_safest","dynamic","quickest"};
if(strategy=="local_shortest")
{
if (e->FirstChild("parameters")->FirstChildElement("navigation_lines"))
nav_line_file=e->FirstChild("parameters")->FirstChildElement("navigation_lines")->Attribute("file");
}
else if(strategy=="global_shortest")
if(std::find(routers.begin(), routers.end(), strategy) != routers.end())
{
if (e->FirstChild("parameters")->FirstChildElement("navigation_lines"))
nav_line_file=e->FirstChild("parameters")->FirstChildElement("navigation_lines")->Attribute("file");
......@@ -1395,19 +1390,7 @@ string GlobalRouter::GetRoutingInfoFile()
}
_minDistanceBetweenTriangleEdges=xmltof(para->Attribute("minimum_distance_between_edges"),-FLT_MAX);
_minAngleInTriangles=xmltof(para->Attribute("minimum_angle_in_triangles"),-FLT_MAX);
}
}
else if(strategy=="global_safest")
{
if (e->FirstChild("parameters")->FirstChildElement("navigation_lines"))
nav_line_file=e->FirstChild("parameters")->FirstChildElement("navigation_lines")->Attribute("file");
}
else if(strategy=="dynamic")
{
if (e->FirstChild("parameters")->FirstChildElement("navigation_lines"))
nav_line_file=e->FirstChild("parameters")->FirstChildElement("navigation_lines")->Attribute("file");
}
}
......
......@@ -112,7 +112,7 @@ protected:
* @obsolete
* return a random exit
*/
int GetBestDefaultRandomExit(Pedestrian* p);
virtual int GetBestDefaultRandomExit(Pedestrian* p);
/**
* Generate a navigation mesh based on delauney triangulation
......@@ -220,10 +220,10 @@ private:
// normalize the probs
std::default_random_engine _rdGenerator;
std::uniform_real_distribution<double> _rdDistribution;
// store all subrooms at the same elevation
std::map<double, std::vector<SubRoom*> > _subroomsAtElevation;
protected:
// store all subrooms at the same elevation
std::map<double, std::vector<SubRoom*> > _subroomsAtElevation;
std::map <int, AccessPoint*> _accessPoints;
Building *_building;
......
......@@ -40,43 +40,44 @@ QuickestPathRouter::QuickestPathRouter( ):GlobalRouter() { }
QuickestPathRouter::~QuickestPathRouter() { }
string QuickestPathRouter::GetRoutingInfoFile() const
{
TiXmlDocument doc(_building->GetProjectFilename());
if (!doc.LoadFile())
{
Log->Write("ERROR: \t%s", doc.ErrorDesc());
Log->Write("ERROR: \t could not open/parse the project file");
return "";
}
// everything is fine. proceed with parsing
TiXmlElement* xMainNode = doc.RootElement();
TiXmlNode* xRouters=xMainNode->FirstChild("route_choice_models");
string nav_line_file="";
for(TiXmlElement* e = xRouters->FirstChildElement("router"); e;
e = e->NextSiblingElement("router"))
{
string strategy=e->Attribute("description");
if(strategy=="quickest")
{
if (e->FirstChild("parameters")->FirstChildElement("navigation_lines"))
nav_line_file=e->FirstChild("parameters")->FirstChildElement("navigation_lines")->Attribute("file");
}
}
if (nav_line_file == "")
return nav_line_file;
else
return _building->GetProjectRootDir()+nav_line_file;
}
//string QuickestPathRouter::GetRoutingInfoFile() const
//{
// TiXmlDocument doc(_building->GetProjectFilename());
// if (!doc.LoadFile())
// {
// Log->Write("ERROR: \t%s", doc.ErrorDesc());
// Log->Write("ERROR: \t could not open/parse the project file");
// return "";
// }
//
// // everything is fine. proceed with parsing
// TiXmlElement* xMainNode = doc.RootElement();
// TiXmlNode* xRouters=xMainNode->FirstChild("route_choice_models");
//
// string nav_line_file="";
//
// for(TiXmlElement* e = xRouters->FirstChildElement("router"); e;
// e = e->NextSiblingElement("router"))
// {
//
// string strategy=e->Attribute("description");
//
// if(strategy=="quickest")
// {
// if (e->FirstChild("parameters")->FirstChildElement("navigation_lines"))
// nav_line_file=e->FirstChild("parameters")->FirstChildElement("navigation_lines")->Attribute("file");
// }
// }
//
// if (nav_line_file == "")
// return nav_line_file;
// else
// return _building->GetProjectRootDir()+nav_line_file;
//}
int QuickestPathRouter::FindExit(Pedestrian* ped)
{
//ped->ClearMentalMap();
int next=FindNextExit(ped);
// that ped will be deleted
......@@ -131,7 +132,6 @@ int QuickestPathRouter::FindNextExit(Pedestrian* ped)
continue;
nextDestination = GetQuickestRoute(ped,_accessPoints[apID]);
//uncomment these lines to return to the gsp
//nextDestination = ap->GetNearestTransitAPTO(ped->GetFinalDestination());
......@@ -207,7 +207,7 @@ double QuickestPathRouter::TAP (double alpha)
}
int QuickestPathRouter::GetQuickestRoute(Pedestrian*ped, AccessPoint* nearestAP __attribute__((unused)))
int QuickestPathRouter::GetQuickestRoute(Pedestrian*ped, AccessPoint* nearestAP )
{
//int preferredExit=nearestAP->GetNearestTransitAPTO(ped->GetFinalDestination());
......@@ -226,64 +226,24 @@ int QuickestPathRouter::GetQuickestRoute(Pedestrian*ped, AccessPoint* nearestAP
//special case where there is only one alternative
//cout<<"app size: "<<aps.size()<<endl;
if(aps.size()==1) return preferredExit;
//in some cases the nearestAP might be included. Remove it
// aps.erase(
// std::remove_if(aps.begin(), aps.end(),
// [&nearestAP](AccessPoint * o) { return o->GetID()==nearestAP->GetID();}),
// aps.end());
//select the optimal time
for(unsigned int ap=0; ap<aps.size(); ap++)
{
int exitid=aps[ap]->GetID();
//FIXME: remove redundant codes
// if(exitid==nearestAP->GetID()){
// printf("\n Ignoring: %d out of %ld\n",exitid,aps.size());
// continue;
// }
double time= GetEstimatedTravelTimeVia(ped,exitid);
// // select the reference and
// int flag=FREE_EXIT;
// int exitid=aps[ap]->GetID();
// Pedestrian* myref=NULL;
// SelectReferencePedestrian(ped,&myref,J_QUEUE_VEL_THRESHOLD_NEW_ROOM,exitid,&flag);
//
// // compute the time
// double time=FLT_MAX;
//
// // case of free exit
// if((myref==NULL)&& (flag==FREE_EXIT)) {
// //time= (ped->GetPos()- aps[ap]->GetCentre()).Norm()/ped->GetV0Norm();
// // time to reach the AP
// double t1 = (ped->GetPos()- aps[ap]->GetCentre()).Norm()/ped->GetV().Norm();
//
// //guess time from the Ap to the outside
// double t2 = (aps[ap]->GetDistanceTo(ped->GetFinalDestination()))/ped->GetV().Norm();
//
// time=t1+t2;
// //cout<<"time = "<<time<<endl;
// }
//
// // case of unreachable exit
// if((myref==NULL)&& (flag==UNREACHEABLE_EXIT)) {
// time= FLT_MAX;
// }
//
// // case of ref ped
// if((myref!=NULL) && (flag==REF_PED_FOUND)) {
//
// //time to reach the reference
// double t1= (ped->GetPos()- myref->GetPos()).Norm()/ped->GetV().Norm();
// //double t1= (ped->GetPos()- myref->GetPos()).Norm()/ped->GetV0Norm();
//
// //time for the reference to get out
// double t2=(myref->GetPos()- aps[ap]->GetCentre()).Norm()/myref->GetV().Norm();
//
// //guess time from the Ap to the outside
// double t3 = (aps[ap]->GetDistanceTo(ped->GetFinalDestination()))/ped->GetV().Norm();
//
// time=t1+t2+t3;
// }
//
// if((myref==NULL) && (flag==REF_PED_FOUND)) {
// Log->Write("ERROR:\t Fatal Error in Quickest Path Router");
// Log->Write("ERROR:\t reference pedestrians is NULL");
// return -1;
// }
if(time<minTime)
{
......@@ -315,18 +275,17 @@ double QuickestPathRouter::gain(double time)
return 1.0/time;
}
bool QuickestPathRouter::Init(Building* building)
{
Log->Write("INFO:\tInit Quickest Path Router Engine");
// prefer path through corridors to path through rooms
SetEdgeCost(100.0);
SetEdgeCost(1.0);
if (GlobalRouter::Init(building) == false)
return false;
// activate the spotlight for tracking some pedestrians
//Pedestrian::ActivateSpotlightSystem(true);
Pedestrian::SetColorMode(AgentColorMode::BY_SPOTLIGHT);
//vector<string> rooms;
//rooms.push_back("150");
......@@ -354,11 +313,6 @@ bool QuickestPathRouter::SelectReferencePedestrian(Pedestrian* myself, Pedestria
queue.reserve(250);
GetQueueAtExit(crossing,jamThreshold,radius,queue,myself->GetSubRoomID());
// if(myself->GetID()==37)
// {
// for (auto ped: queue)
// ped->SetSpotlight(true);
// }
if(queue.size()==0)
{
//check if I can see/reach the exit without much effort
......@@ -642,7 +596,6 @@ int QuickestPathRouter::GetObstaclesCountBetween(const Point& p1, const Point& p
return obstacles;
}
int QuickestPathRouter::isCongested(Pedestrian* ped)
{
//define as the ratio of people in front of me and behind me
......@@ -684,7 +637,6 @@ int QuickestPathRouter::isCongested(Pedestrian* ped)
return false;
}
double QuickestPathRouter::GetEstimatedTravelTimeVia(Pedestrian* ped, int exitid)
{
//select a reference pedestrian
......@@ -727,7 +679,7 @@ double QuickestPathRouter::GetEstimatedTravelTimeVia(Pedestrian* ped, int exitid
if(myref->GetV().Norm()==0.0)
{
Log->Write("WARNING:\t the reference pedestrian velocity is zero !");
//Log->Write("WARNING:\t the reference pedestrian velocity is zero !");
}
//time for the reference to get out
//double t2=(myref->GetPos() - ap->GetCentre()).Norm()/myref->GetV().Norm();
......@@ -839,11 +791,6 @@ int QuickestPathRouter::GetBestDefaultRandomExit(Pedestrian* ped)
//double normFactor=0.0;
//map <int, double> doorProb;
// get the opened exits
SubRoom* sub = _building->GetRoom(ped->GetRoomID())->GetSubRoom(
ped->GetSubRoomID());
// get the relevant opened exits
vector <AccessPoint*> relevantAPs;
GetRelevantRoutesTofinalDestination(ped,relevantAPs);
......@@ -860,6 +807,10 @@ int QuickestPathRouter::GetBestDefaultRandomExit(Pedestrian* ped)
double minDistGlobal = FLT_MAX;
double minDistLocal = FLT_MAX;
// get the opened exits
SubRoom* sub = _building->GetRoom(ped->GetRoomID())->GetSubRoom(
ped->GetSubRoomID());
for(unsigned int g=0; g<relevantAPs.size(); g++)
{
AccessPoint* ap=relevantAPs[g];
......@@ -880,7 +831,8 @@ int QuickestPathRouter::GetBestDefaultRandomExit(Pedestrian* ped)
//check if visible
if (sub->IsVisible(posA, posC, true) == false)
if(_building->IsVisible(posA, posC, _subroomsAtElevation[sub->GetMaxElevation()],true)==false)
//if (sub->IsVisible(posA, posC, true) == false)
{
ped->RerouteIn(10);
//ped->Dump(ped->GetID());
......
......@@ -64,7 +64,7 @@ private:
/**
* @return the right path for the extra information
*/
virtual std::string GetRoutingInfoFile() const;
//virtual std::string GetRoutingInfoFile() const;
/**
* find the next suitable destination for the pedestrian
......@@ -220,7 +220,7 @@ private:
* @param ped
* @return
*/
int GetBestDefaultRandomExit(Pedestrian* ped);
virtual int GetBestDefaultRandomExit(Pedestrian* ped);
};
......
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