Commit e8efcb45 authored by Ulrich Kemloh's avatar Ulrich Kemloh

New information are now accepted with a probability in events

parent 0a05650f
......@@ -557,7 +557,6 @@ void TrajectoriesJPSV06::WriteFrame(int frameNr, Building* building)
char tmp1[CLENGTH] = "";
int color=ped->GetColor();
double a = ped->GetLargerAxis();
double b = ped->GetSmallerAxis();
......
......@@ -498,29 +498,29 @@ int Simulation::RunBody(double maxSimTime)
while ( (_nPeds || !_agentSrcManager.IsCompleted() ) && t < maxSimTime)
{
t = 0 + (frameNr - 1) * _deltaT;
//process the queue for incoming pedestrians
ProcessAgentsQueue();
if(t>Pedestrian::GetMinPremovementTime())
{
//update the linked cells
_building->UpdateGrid();
//update the linked cells
_building->UpdateGrid();
// update the positions
_operationalModel->ComputeNextTimeStep(t, _deltaT, _building.get());
// update the positions
_operationalModel->ComputeNextTimeStep(t, _deltaT, _building.get());
//update the routes and locations
UpdateRoutesAndLocations();
//update the events
_em->ProcessEvent();
//update the events
//_em->Update_Events(t);
_em->ProcessEvent();
//update the routes and locations
UpdateRoutesAndLocations();
//other updates
//someone might have left the building
_nPeds = _building->GetAllPedestrians().size();
}
//other updates
//someone might have left the building
_nPeds = _building->GetAllPedestrians().size();
}
// update the global time
Pedestrian::SetGlobalTime(t);
......@@ -528,7 +528,8 @@ int Simulation::RunBody(double maxSimTime)
if (0 == frameNr % writeInterval) {
_iod->WriteFrame(frameNr / writeInterval, _building.get());
}
Log->ProgressBar(initialnPeds, initialnPeds - _building->GetAllPedestrians().size() , t);
Log->ProgressBar(initialnPeds, initialnPeds - _nPeds , t);
// needed to control the execution time PART 2
// time(&endtime);
// double timeToWait=t-difftime(endtime, starttime);
......@@ -571,5 +572,5 @@ AgentsSourcesManager& Simulation::GetAgentSrcManager()
Building* Simulation::GetBuilding()
{
return _building.get();
return _building.get();
}
This diff is collapsed.
......@@ -120,6 +120,9 @@ private:
*/
bool MergeKnowledge(Pedestrian* p1, Pedestrian* p2);
bool MergeKnowledgeUsingProbability(Pedestrian* p1, Pedestrian* p2);
/**
* Update the pedestrian route based on the new information
* @param p1
......@@ -127,6 +130,7 @@ private:
*/
bool UpdateRoute(Pedestrian* p1);
void CreateSomeEngine();
private:
......
......@@ -1257,16 +1257,19 @@ void Building::DeletePedestrian(Pedestrian* &ped)
}
}
_allPedestians.erase(it);
}
//update the stats before deleting
Transition* trans =GetTransitionByUID(ped->GetExitIndex());
if(trans)
{
trans->IncreaseDoorUsage(1, ped->GetGlobalTime());
//this can happen if the pedesrians is pushed too hard
// or cant stop due to high velocity
// he will remain in the simulation in that case
if(trans->IsOpen()==false) return;
}
_allPedestians.erase(it);
delete ped;
//ped=nullptr;
}
const vector<Pedestrian*>& Building::GetAllPedestrians() const
......
......@@ -27,8 +27,6 @@
#include "Knowledge.h"
#include "../IO/OutputHandler.h"
extern OutputHandler* Log;
Knowledge::Knowledge()
{
......@@ -36,22 +34,29 @@ Knowledge::Knowledge()
_time = 0;
_quality=1;
_id=-1;
_hasBeenRefusedOnce=false;
_latency=0.0;
}
Knowledge::~Knowledge()
{
}
void Knowledge::Dump()
std::string Knowledge::Dump()
{
Log->Write("INFO: \tdoor [%d] state [%d] since [%f]\n",_id,_isClosed,_time);
char tmp[2048];
sprintf(tmp,"door [%d] state [%d] since [%.2f] sec. Refused= %d, Quality=%.2f, latency=%.2f",_id,_isClosed,_time,_hasBeenRefusedOnce,_quality,_latency);
return std::string(tmp);
}
void Knowledge::SetState(int id, bool is_closed, double time)
void Knowledge::SetState(int id, bool is_closed, double time, double quality, double latency, bool refuse)
{
_isClosed=is_closed;
_time=time;
_id=id;
_quality=quality;
_hasBeenRefusedOnce=refuse;
_latency=latency;
}
bool Knowledge::GetState() const
......@@ -64,7 +69,44 @@ double Knowledge::GetQuality() const
return _quality;
}
void Knowledge::SetQuality(double quality)
{
_quality=quality;
}
double Knowledge::GetTime() const
{
return _time;
}
bool Knowledge::HasBeenRefused() const
{
return _hasBeenRefusedOnce;
}
void Knowledge::Refuse(bool state)
{
_hasBeenRefusedOnce=state;
}
bool Knowledge::CanBeForwarded() const
{
return (_latency<=0);
}
void Knowledge::SetLatency(double latency)
{
_latency=latency;
}
double Knowledge::GetLatency() const
{
return _latency;
}
void Knowledge::DecreaseLatency(double minus)
{
_latency = _latency - minus;
if (_latency <= 0)
_latency = 0.0;
}
......@@ -43,12 +43,76 @@ public:
*/
~Knowledge();
void Dump();
void SetState(int id, bool is_closed, double time);
/**
* Initialize the knowledge
* @param id
* @param is_closed
* @param time
* @param quality
* @param refuse
*/
void SetState(int id, bool is_closed, double time, double quality, double latency, bool refuse=false);
/**
* @return the state of the object. close or open
*/
bool GetState() const;
/**
* transmitted knowledge have a lower quality than those gathered by oneself.
* @return the quality of the knowledge
*/
double GetQuality() const;
/**
* transmitted knowledge have a lower quality than those gathered by oneself.
* @return the quality of the knowledge
*/
void SetQuality(double quality);
/**
* When was the event recorded
*/
double GetTime() const;
/**
* @return whether this knowledge has been refused before
*/
bool HasBeenRefused() const;
/**
* store but refuse the knowledge.
* @param state
*/
void Refuse(bool state);
/**
* print the content of the knowledge as string
*/
std::string Dump();
/**
* @return true, if the information can be forwarded
*/
bool CanBeForwarded() const;
/**
* Set/Get the latency time before forwarding the information
*/
void SetLatency(double latency);
/**
* Set/Get the latency time before forwarding the information
*/
double GetLatency() const;
/**
* Update the latency by reducing the specified time.
* The latency will eventually be 0 and the information will be forwarded.
* @param minus
*/
void DecreaseLatency(double minus);
private:
/// information quality in [0..1]. 1 is very reliable information
double _quality; //
......@@ -59,7 +123,9 @@ private:
/// id of the door
int _id;
/// whether I already accepted or refused that information
bool _refusedOnce;
bool _hasBeenRefusedOnce;
/// time to retain this information before forwarding
double _latency;
};
#endif /* KNOWLEDGE_H_ */
......
......@@ -329,10 +329,10 @@ void Pedestrian::ClearMentalMap()
_exitIndex = -1;
}
void Pedestrian::AddKnownClosedDoor(int door, double time)
void Pedestrian::AddKnownClosedDoor(int door, double ttime, bool state, double quality, double latency)
{
if(time==0) time=_globalTime;
_knownDoors[door].SetState(door,true,time);
if(ttime==0) ttime=_globalTime;
_knownDoors[door].SetState(door,state,ttime,quality, latency);
}
void Pedestrian::ClearKnowledge()
......@@ -340,7 +340,7 @@ void Pedestrian::ClearKnowledge()
_knownDoors.clear();
}
const map<int, Knowledge>& Pedestrian::GetKnownledge() const
map<int, Knowledge>& Pedestrian::GetKnownledge()
{
return _knownDoors;
}
......@@ -350,6 +350,9 @@ const std::string Pedestrian::GetKnowledgeAsString() const
string key="";
for(auto&& knowledge:_knownDoors)
{
//skip low quality information
if(knowledge.second.GetQuality()<0.2) continue;
int door=knowledge.first;
if(key.empty())
key.append(std::to_string(door));
......@@ -765,6 +768,10 @@ void Pedestrian::Dump(int ID, int pa)
printf(">> mental map");
for(auto&& item: _mentalMap)
printf("\t room / destination [%d, %d]\n", item.first, item.second);
for(auto&& item:_knownDoors)
printf(">> %s \n",item.second.Dump().c_str());
printf(">> Knowledge: %s \n",GetKnowledgeAsString().c_str());
printf(">> Color: %d \n",GetColor());
break;
case 1:
......
......@@ -205,10 +205,19 @@ public:
int GetFinalDestination() const;
void ClearMentalMap(); // erase the peds memory
// functions for known closed Doors
void AddKnownClosedDoor(int door, double time);
// needed for information sharing
const std::map<int, Knowledge>& GetKnownledge() const;
/**
* Update the knowledge of the pedestrian
* @param door
* @param ttime
* @param state
* @param quality
*/
void AddKnownClosedDoor(int door, double ttime, bool state, double quality, double latency);
/***
* @return the knowledge of the pedstrian
*/
std::map<int, Knowledge>& GetKnownledge();
/**
* For convenience
......
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