Commit 36d7aea7 authored by tobias schroedter's avatar tobias schroedter

Added DoorState to Crossing, either OPEN, CLOSE, or TEMP_CLOSE

parent 9ef6a348
......@@ -46,8 +46,8 @@ void GeoFileParser::LoadBuilding(Building* building)
exit(EXIT_FAILURE);
}
if (!LoadTrafficInfo(building)) {
Log->Write("ERROR:\t could not load extra traffic information!");
exit(EXIT_FAILURE);
Log->Write("ERROR:\t could not load extra traffic information!");
exit(EXIT_FAILURE);
}
}
......@@ -75,10 +75,10 @@ bool GeoFileParser::LoadGeometry(Building* building)
return false;
}
if (xRootNode->Attribute("unit")) if (std::string(xRootNode->Attribute("unit"))!="m") {
Log->Write("ERROR:\tOnly the unit m (meters) is supported. \n\tYou supplied [%s]",
xRootNode->Attribute("unit"));
return false;
}
Log->Write("ERROR:\tOnly the unit m (meters) is supported. \n\tYou supplied [%s]",
xRootNode->Attribute("unit"));
return false;
}
double version = xmltof(xRootNode->Attribute("version"), -1);
......@@ -580,18 +580,37 @@ bool GeoFileParser::LoadTrafficInfo(Building* building)
sprintf(tmp, "\t>> ID: %d\n", id);
str.append(tmp);
//------------------ state
std::string state = xmltoa(xDoor->Attribute("state"), "open");
//store transition in a map and call getTransition/getCrossin
if (state=="open") {
std::string stateStr = xmltoa(xDoor->Attribute("state"), "open");
DoorState state = StringToDoorState(stateStr);
//store transition in a map and call getTransition/getCrossing
switch (state) {
case DoorState::OPEN:
building->GetTransition(id)->Open();
}
else if (state=="close") {
break;
case DoorState::CLOSE:
building->GetTransition(id)->Close();
break;
case DoorState::TEMP_CLOSE:
building->GetTransition(id)->TempClose();
break;
case DoorState::ERROR:
Log->Write("WARNING:\t Unknown door state: <%s>. open or close. Default: open",
stateStr.c_str());
building->GetTransition(id)->Open();
break;
}
else {
Log->Write("WARNING:\t Unknown door state: <%s>. open or close. Default: open", state.c_str());
}
sprintf(tmp, "\t>> state: %s\n", state.c_str());
// if (state=="open") {
// building->GetTransition(id)->Open();
// }
// else if (state=="close") {
// building->GetTransition(id)->Close();
// }
// else {
// Log->Write("WARNING:\t Unknown door state: <%s>. open or close. Default: open", state.c_str());
// }
// }
sprintf(tmp, "\t>> state: %s\n", stateStr.c_str());
str.append(tmp);
//------------------ outflow
double outflow = xmltof(xDoor->Attribute("outflow"), -1.0);
......
......@@ -225,6 +225,27 @@ enum USERMODE {
DISTANCE_AND_DIRECTIONS_USED
};
// Describes the door
enum class DoorState { OPEN, CLOSE, TEMP_CLOSE, ERROR };
inline DoorState StringToDoorState(std::string name){
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
if (name.compare("open") == 0){
return DoorState::OPEN;
}
if (name.compare("temp_close") == 0){
return DoorState::TEMP_CLOSE;
}
if (name.compare("close") == 0){
return DoorState::CLOSE;
}
return DoorState::ERROR;
};
constexpr double magicnum(int i) {
return (i == UNKNOWN_DISTANCE) ? -3.0 : (i == UNKNOWN_COST) ? -2.0 : (i == WALL_ON_COSTARRAY) ? -7.0 : (i == TARGET_REGION) ? 0.0 : J_NAN;
// switch (i) {
......
......@@ -35,9 +35,6 @@ using namespace std;
Crossing::Crossing()
{
_id = -1;
_isOpen=true;
_temporaryClosed=false; // some doors have to be closed and opened again
// depending on _outflowRate.
_doorUsage = 0;
_maxDoorUsage = (std::numeric_limits<int>::max)(); //avoid name conflicts in windows winmindef.h
_outflowRate = (std::numeric_limits<double>::max)();
......@@ -48,6 +45,7 @@ Crossing::Crossing()
_partialDoorUsage = 0;
_closingTime = 0;
_state = DoorState::OPEN;
}
Crossing::~Crossing()
......@@ -86,7 +84,17 @@ bool Crossing::IsExit() const
bool Crossing::IsOpen() const
{
return _isOpen;
return _state == DoorState::OPEN;
}
bool Crossing::IsClose() const
{
return _state == DoorState::CLOSE;
}
bool Crossing::IsTempClose() const
{
return _state == DoorState::TEMP_CLOSE;
}
bool Crossing::IsTransition() const
......@@ -96,12 +104,18 @@ bool Crossing::IsTransition() const
void Crossing::Close()
{
_isOpen = false;
_state = DoorState::CLOSE;
}
void Crossing::TempClose()
{
_state = DoorState::TEMP_CLOSE;
}
void Crossing::Open()
{
_isOpen = true;
_state = DoorState::OPEN;
}
bool Crossing::IsInSubRoom(int subroomID) const
......@@ -141,10 +155,10 @@ void Crossing::WriteToErrorLog() const
string s;
char tmp[CLENGTH];
sprintf(tmp, "\t\tCROSS: %d (%f, %f) -- (%f, %f)\n", GetID(), GetPoint1()._x,
GetPoint1()._y, GetPoint2()._x, GetPoint2()._y);
GetPoint1()._y, GetPoint2()._x, GetPoint2()._y);
s.append(tmp);
sprintf(tmp, "\t\t\t\tSubRoom: %d <-> SubRoom: %d\n", GetSubRoom1()->GetSubRoomID(),
GetSubRoom2()->GetSubRoomID());
GetSubRoom2()->GetSubRoomID());
s.append(tmp);
Log->Write(s);
}
......@@ -159,14 +173,14 @@ string Crossing::GetDescription() const
geometry.append(tmp);
//geometry.append("\t\t<door color=\"250\">\n");
sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\" zPos=\"%.2f\" />\n",
(GetPoint1()._x) * FAKTOR,
(GetPoint1()._y) * FAKTOR,
_subRoom1->GetElevation(GetPoint1())*FAKTOR);
(GetPoint1()._x) * FAKTOR,
(GetPoint1()._y) * FAKTOR,
_subRoom1->GetElevation(GetPoint1())*FAKTOR);
geometry.append(tmp);
sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\" zPos=\"%.2f\" />\n",
(GetPoint2()._x) * FAKTOR,
(GetPoint2()._y) * FAKTOR,
_subRoom1->GetElevation(GetPoint2())*FAKTOR);
(GetPoint2()._x) * FAKTOR,
(GetPoint2()._y) * FAKTOR,
_subRoom1->GetElevation(GetPoint2())*FAKTOR);
geometry.append(tmp);
geometry.append("\t\t</crossing>\n");
return geometry;
......@@ -255,11 +269,6 @@ void Crossing::UpdateClosingTime(double dt)
_closingTime -= dt;
}
bool Crossing::isTemporaryClosed()
{
return _temporaryClosed;
}
double Crossing::GetDT()
{
......@@ -297,23 +306,9 @@ void Crossing::regulateFlow(double time)
// --> [1]
//---------------------------
_closingTime = number / _outflowRate - T; //[1]
_temporaryClosed = true;
this->Close();
// _temporaryClosed = true;
// this->Close();
this->TempClose();
Log-> Write("INFO:\tClosing door %d. DoorUsage = %d (max = %d). Flow = %.2f (max = %.2f) Time=%.2f", GetID(), GetDoorUsage(), GetMaxDoorUsage(), flow, _outflowRate, time);
}
......@@ -322,14 +317,24 @@ void Crossing::regulateFlow(double time)
{
Log-> Write("INFO:\tClosing door %d. DoorUsage = %d (>= %d). Time=%.2f", GetID(), GetDoorUsage(), GetMaxDoorUsage(), time);
this->Close();
_temporaryClosed = false;
// _temporaryClosed = false;
}
_lastFlowMeasurement = time + _closingTime;
}
void Crossing::changeTemporaryState()
{
_temporaryClosed = false;
_closingTime = 0;
this->Open();
// _temporaryClosed = false;
_closingTime = 0;
this->Open();
}
DoorState Crossing::GetState() const
{
return _state;
}
void Crossing::SetState(DoorState _state)
{
Crossing::_state = _state;
}
\ No newline at end of file
......@@ -39,193 +39,193 @@ class SubRoom;
class Crossing : public Hline {
private:
// /// TODO ? unique between crossings and transitions ?
// int _id;
/// only one room needed, since a crossing only separates 2 subrooms
//Room* _room1;
//SubRoom* _subRoom1;
//SubRoom* _subRoom2;
bool _isOpen;
bool _temporaryClosed;
int _doorUsage;
double _lastPassingTime;
double _outflowRate; // pedestrians / second
int _maxDoorUsage;
double _closingTime; // time to wait until door is reopened
double _DT; // flow observation time
int _DN; // number of pedestrians that pass the line to trigger measurement
// of the flow
int _partialDoorUsage; //door usage in _DT
double _lastFlowMeasurement;
std::string _flowAtExit;
int _doorUsage;
double _lastPassingTime;
double _outflowRate; // pedestrians / second
int _maxDoorUsage;
double _closingTime; // time to wait until door is reopened
double _DT; // flow observation time
int _DN; // number of pedestrians that pass the line to trigger measurement
// of the flow
int _partialDoorUsage; //door usage in _DT
double _lastFlowMeasurement;
std::string _flowAtExit;
DoorState _state;
public:
// last ped that passed was in room {1,2} that many ticks
// last ped that passed was in room {1,2} that many ticks
// int _lastTickTime1 = 0;
// int _lastTickTime2 = 0;
// int _refresh1 = 0;
// int _refresh2 = 0;
/**
* Constructor
*/
Crossing();
/**
* Constructor
*/
Crossing();
/**
* Destructor
*/
virtual ~Crossing();
// /**
// * Set/Get the Id of the crossing
// * TODO: do you really want to shadow ?
// */
// void SetID(int ID);
//
// /**
// * Set/Get the Id of the crossing
// * TODO: do you really want to shadow ?
// */
// int GetID () const;
/**
* Set/Get the second subroom
*/
//void SetSubRoom2(SubRoom* r2);
/**
* Destructor
*/
virtual ~Crossing();
/**
* Set/Get the second subroom
*/
//SubRoom* GetSubRoom2() const;
/**
* Set/Get the second subroom
*/
//void SetSubRoom2(SubRoom* r2);
/**
* Close the door
*/
void Close();
/**
* Set/Get the second subroom
*/
//SubRoom* GetSubRoom2() const;
/**
* Open the door
*/
void Open();
/**
* Close the door
*/
void Close();
/**
* \return true if the subroomID is associated with the current crossing
*/
bool IsInSubRoom(int subroomID) const;
/**
* Temporaily closes the door
*/
void TempClose();
/**
* @return true if the crossing is open = passable
*/
virtual bool IsOpen() const;
/**
* Open the door
*/
void Open();
/**
* \return true if the subroomID is associated with the current crossing
*/
bool IsInSubRoom(int subroomID) const;
/**
* @return true if the state == OPEN
*/
virtual bool IsOpen() const;
/**
* @return true if the state == TEMP_CLOSE
*/
virtual bool IsTempClose() const;
/**
/**
* @return true if the state == CLOSE
*/
virtual bool IsClose() const;
/**
* @return true if the crossing is an exit/transition. (Transitions are derived from this class)
* @see Transition
*/
virtual bool IsExit() const;
virtual bool IsExit() const;
/**
*
* @return true if it is a transition
*/
virtual bool IsTransition() const;
/**
*
* @return true if it is a transition
*/
virtual bool IsTransition() const;
/**
* @return the other subroom not matching the data
*/
virtual SubRoom* GetOtherSubRoom(int roomID, int subroomID) const;
/**
* @return the other subroom not matching the data
*/
virtual SubRoom* GetOtherSubRoom(int roomID, int subroomID) const;
/**
* Debug output
*/
virtual void WriteToErrorLog() const;
/**
* Debug output
*/
virtual void WriteToErrorLog() const;
/**
* @return a nicely formatted string representation of the object
*/
virtual std::string GetDescription() const;
/**
* @return a nicely formatted string representation of the object
*/
virtual std::string GetDescription() const;
/**
* @return the number of subrooms this has in common with other (0, 1, 2)
* @param other the other crossing
* @param subroom returns one of the common subrooms
*/
virtual int CommonSubroomWith(Crossing* other, SubRoom* &subroom);
/**
* @return the number of subrooms this has in common with other (0, 1, 2)
* @param other the other crossing
* @param subroom returns one of the common subrooms
*/
virtual int CommonSubroomWith(Crossing* other, SubRoom* &subroom);
/**
* Increment the number of persons that used that crossing
* @param number, how many person have passed the crossing
* @param time, at which time
*/
void IncreaseDoorUsage(int number, double time);
void IncreasePartialDoorUsage(int number);
void ResetPartialDoorUsage();
int GetPartialDoorUsage() const;
/**
* @return the number of pedestrians that used that crossing.
*/
int GetDoorUsage() const;
/**
* Increment the number of persons that used that crossing
* @param number, how many person have passed the crossing
* @param time, at which time
*/
void IncreaseDoorUsage(int number, double time);
void IncreasePartialDoorUsage(int number);
void ResetPartialDoorUsage();
int GetPartialDoorUsage() const;
/**
* @return the number of pedestrians that used that crossing.
*/
int GetDoorUsage() const;
/**
* @return outflow rate of crossing/transition
*/
double GetOutflowRate() const;
/**
* @return outflow rate of crossing/transition
*/
double GetOutflowRate() const;
/**
* @return max of number of agents that can pass crossing/transition
*/
int GetMaxDoorUsage() const;
/**
* @return max of number of agents that can pass crossing/transition
*/
int GetMaxDoorUsage() const;
/**
* set _maxDoorUsage
* @param max door usage
*/
void SetMaxDoorUsage(int mdu);
/**
* set _maxDoorUsage
* @param max door usage
*/
void SetMaxDoorUsage(int mdu);
/**
* set outflow rate
* @param outflow
*
*/
void SetOutflowRate(double outflow);
void SetOutflowRate(double outflow);
/**
* @return the flow curve for this crossing
*/
const std::string & GetFlowCurve() const;
/**
* @return the flow curve for this crossing
*/
const std::string & GetFlowCurve() const;
/**
* @return the last time this crossing was crossed
*/
double GetLastPassingTime() const;
/**
* @return the last time this crossing was crossed
*/
double GetLastPassingTime() const;
/**
* @return the time we should wait until the door is reopened
*
*/
double GetClosingTime() const;
/**
* @return the time we should wait until the door is reopened
*
*/
double GetClosingTime() const;
/**
* @param dt: time to decrease the waiting time until door is reopened
*/
void UpdateClosingTime(double dt);
/**
* @param dt: time to decrease the waiting time until door is reopened
*/
void UpdateClosingTime(double dt);
bool isTemporaryClosed();
/**
* changes two private variables
* _temporaryClosed is false
* and _closingTime is 0
*/
void changeTemporaryState();
double GetDT();
void SetDT(double dt);
int GetDN();
void SetDN(int dt);
/**
* changes two private variables
* _temporaryClosed is false
* and _closingTime is 0
*/
void changeTemporaryState();
double GetDT();
void SetDT(double dt);
int GetDN();
void SetDN(int dt);
void regulateFlow(double time);
void regulateFlow(double time);
DoorState GetState() const;
void SetState(DoorState _state);
};
#endif /* _CROSSING_H */
#endif /* _CROSSING_H */
\ No newline at end of file
......@@ -37,7 +37,7 @@ using namespace std;
Transition::Transition() : Crossing()
{
_isOpen = true;
// _isOpen = true;
_room2 = nullptr;
// _lastTickTime1 = 0;
// _lastTickTime2 = 0;
......@@ -62,10 +62,10 @@ void Transition::SetRoom2(Room* r)
_room2 = r;
}
bool Transition::IsOpen() const
{
return Crossing::IsOpen();
}
//bool Transition::IsOpen() const
//{
// return Crossing::IsOpen();
//}
Room* Transition::GetRoom2() const
......@@ -145,12 +145,12 @@ void Transition::WriteToErrorLog() const
string s;
char tmp[CLENGTH];
sprintf(tmp, "\t\tTRANS: %d [%s] (%f, %f) -- (%f, %f)\n", GetID(), GetCaption().c_str(),
GetPoint1()._x, GetPoint1()._y, GetPoint2()._x, GetPoint2()._y);
GetPoint1()._x, GetPoint1()._y, GetPoint2()._x, GetPoint2()._y);
s.append(tmp);
// erster Raum
if (GetRoom1() != nullptr) {
sprintf(tmp, "\t\t\t\tRoom: %d [%s] SubRoom: %d", GetRoom1()->GetID(),
GetRoom1()->GetCaption().c_str(), GetSubRoom1()->GetSubRoomID());
GetRoom1()->GetCaption().c_str(), GetSubRoom1()->GetSubRoomID());
} else {
sprintf(tmp, "\t\t\t\tAusgang");
}
......@@ -158,7 +158,7 @@ void Transition::WriteToErrorLog() const
// zweiter Raum
if (GetRoom2() != nullptr) {
sprintf(tmp, " <->\tRoom: %d [%s] SubRoom: %d\n", GetRoom2()->GetID(),
GetRoom2()->GetCaption().c_str(), GetSubRoom2()->GetSubRoomID());
GetRoom2()->GetCaption().c_str(), GetSubRoom2()->GetSubRoomID());
} else {
sprintf(tmp, " <->\tAusgang\n");
}
......@@ -175,14 +175,14 @@ string Transition::GetDescription() const
sprintf(tmp,"\t\t<door ID=\"%d\" color=\"180\" caption=\"%d_%d_%s\">\n",GetUniqueID(),GetID(),GetUniqueID(),GetCaption().c_str());
geometry.append(tmp);
sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\" zPos=\"%.2f\"/>\n",
(GetPoint1()._x) * FAKTOR,
(GetPoint1()._y) * FAKTOR,
GetSubRoom1()->GetElevation(GetPoint1())*FAKTOR);
(GetPoint1()._x) * FAKTOR,
(GetPoint1()._y) * FAKTOR,
GetSubRoom1()->GetElevation(GetPoint1())*FAKTOR);
geometry.append(tmp);
sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\" zPos=\"%.2f\"/>\n",
(GetPoint2()._x) * FAKTOR,
(GetPoint2()._y) * FAKTOR,
GetSubRoom1()->GetElevation(GetPoint2())*FAKTOR);
(GetPoint2()._x) * FAKTOR,
(GetPoint2()._y) * FAKTOR,
GetSubRoom1()->GetElevation(GetPoint2())*FAKTOR);
geometry.append(tmp);
geometry.append("\t\t</door>\n");
return geometry;
......
......@@ -24,7 +24,7 @@
*
*
**/
#ifndef _TRANSITION_H
#define _TRANSITION_H
......@@ -36,60 +36,58 @@ class Room;
class Transition : public Crossing {
private:
Room* _room2;
bool _isOpen;
std::string _type;
// number of agents that passed that exit
Room* _room2;
std::string _type;
// number of agents that passed that exit
public:
/**
* Cosntructor
*/
Transition();
/**
* Destructor
*/
virtual ~Transition();
/**
* Set/Get the type of the transition
*/
void SetType(std::string s);
/**
* Set/Get the second room associated with this transition.
* The first one is set in the crossing class.
*/
void SetRoom2(Room* ID);
/**
* Set/Get the type of the transition
*/
std::string GetType() const;
/**
* Set/Get the second room associated with this transition.
* The first one is set in the crossing class.
*/
Room* GetRoom2() const;
/**
* @return the other room.
*/
Room* GetOtherRoom(int room_id) const;
// virtual functions
virtual bool IsOpen() const;
virtual bool IsExit() const;
virtual bool IsTransition() const;
virtual bool IsInRoom(int roomID) const;
virtual SubRoom* GetOtherSubRoom(int roomID, int subroomID) const;
virtual void WriteToErrorLog() const;