diff --git a/src/dsm/dsm.hpp b/src/dsm/dsm.hpp index 71335009c..529d86a8e 100644 --- a/src/dsm/dsm.hpp +++ b/src/dsm/dsm.hpp @@ -6,7 +6,7 @@ static constexpr uint8_t DSM_VERSION_MAJOR = 2; static constexpr uint8_t DSM_VERSION_MINOR = 5; -static constexpr uint8_t DSM_VERSION_PATCH = 2; +static constexpr uint8_t DSM_VERSION_PATCH = 3; static auto const DSM_VERSION = std::format("{}.{}.{}", DSM_VERSION_MAJOR, DSM_VERSION_MINOR, DSM_VERSION_PATCH); diff --git a/src/dsm/headers/Sensors.hpp b/src/dsm/headers/Sensors.hpp index 129d9437b..2765c43c2 100644 --- a/src/dsm/headers/Sensors.hpp +++ b/src/dsm/headers/Sensors.hpp @@ -8,16 +8,22 @@ #include +#include "../utility/Typedef.hpp" + namespace dsm { /// @brief The Counter class contains two counters to count input and output. class Counter { protected: + Id m_code; std::pair m_counters = {0, 0}; // First = in, Second = out public: + void setCode(Id const code); /// @brief Increase the input counter by one void increaseInputCounter(); /// @brief Increase the output counter by one void increaseOutputCounter(); + + Id code() const; /// @brief Get the number of input counts registered /// @param reset If true, the counter is reset to 0. Default is true int inputCounts(bool reset = true); diff --git a/src/dsm/sources/RoadNetwork.cpp b/src/dsm/sources/RoadNetwork.cpp index 5770caca9..2325c347c 100644 --- a/src/dsm/sources/RoadNetwork.cpp +++ b/src/dsm/sources/RoadNetwork.cpp @@ -70,6 +70,8 @@ namespace dsm { newStreetId, *street, dynamic_cast(*street).flowRate()); } else if (street->isSpire()) { addEdge(newStreetId, *street); + dynamic_cast(*m_edges.at(newStreetId)) + .setCode(dynamic_cast(*street).code()); } else { addEdge(newStreetId, *street); } @@ -263,7 +265,7 @@ namespace dsm { // Check if the first line is nodeId;lat;lon std::string line; std::getline(ifs, line); - if (line != "id;lon;lat") { + if (line != "id;lon;lat;type") { throw std::invalid_argument( Logger::buildExceptionMessage("Invalid file format.")); } @@ -274,15 +276,21 @@ namespace dsm { continue; } std::istringstream iss{line}; - std::string nodeId, lat, lon; + std::string nodeId, lat, lon, type; std::getline(iss, nodeId, ';'); std::getline(iss, lon, ';'); - std::getline(iss, lat, '\n'); + std::getline(iss, lat, ';'); + std::getline(iss, type, '\n'); dLon = lon == "Nan" ? 0. : std::stod(lon); dLat = lat == "Nan" ? 0. : std::stod(lat); auto const& it{m_nodes.find(std::stoul(nodeId))}; if (it != m_nodes.cend()) { it->second->setCoords(std::make_pair(dLat, dLon)); + if (type == "traffic_light" && !it->second->isTrafficLight()) { + makeTrafficLight(it->first, 60); + } else if (type == "roundabout" && !it->second->isRoundabout()) { + makeRoundabout(it->first); + } } else { Logger::warning( std::format("Node with id {} not found. Skipping coordinates ({}, {}).", @@ -365,8 +373,9 @@ namespace dsm { continue; } std::istringstream iss{line}; - std::string sourceId, targetId, length, lanes, highway, maxspeed, name, geometry; - // u;v;length;highway;maxspeed;name;geometry + std::string sourceId, targetId, length, lanes, highway, maxspeed, name, geometry, + coilcode; + // u;v;length;highway;maxspeed;name;geometry;coilcode std::getline(iss, sourceId, ';'); std::getline(iss, targetId, ';'); std::getline(iss, length, ';'); @@ -374,7 +383,8 @@ namespace dsm { std::getline(iss, highway, ';'); std::getline(iss, maxspeed, ';'); std::getline(iss, name, ';'); - std::getline(iss, geometry, '\n'); + std::getline(iss, geometry, ';'); + std::getline(iss, coilcode, '\n'); if (maxspeed.empty()) { maxspeed = "30"; // Default to 30 km/h if no maxspeed is provided } else { @@ -460,6 +470,11 @@ namespace dsm { std::stoul(lanes), name, coords); + if (!coilcode.empty()) { + makeSpireStreet(streetId); + auto& coil = edge(streetId); + coil.setCode(static_cast(std::stoul(coilcode))); + } } } else { throw std::invalid_argument( @@ -474,7 +489,7 @@ namespace dsm { path.substr(path.find_last_of(".")) == ".csv")); std::ofstream file{path}; // Column names - file << "id;lon;lat\n"; + file << "id;lon;lat;type\n"; for (auto const& [nodeId, pNode] : m_nodes) { file << nodeId << ';'; if (pNode->coords().has_value()) { @@ -482,6 +497,13 @@ namespace dsm { } else { file << "Nan;Nan"; } + if (pNode->isTrafficLight()) { + file << ";traffic_light"; + } else if (pNode->isRoundabout()) { + file << ";roundabout"; + } else { + file << ";intersection"; + } file << '\n'; } file.close(); @@ -492,10 +514,15 @@ namespace dsm { path.substr(path.find_last_of(".")) == ".csv")); std::ofstream file{path}; // Column names - file << "id;source_id;target_id;name;geometry\n"; + file << "id;source_id;target_id;name;coil_code;geometry\n"; for (auto const& [streetId, pStreet] : m_edges) { file << streetId << ';' << pStreet->source() << ';' << pStreet->target() << ';' << pStreet->name() << ';'; + if (pStreet->isSpire()) { + file << dynamic_cast(*pStreet).code() << ';'; + } else { + file << ';'; + } if (!pStreet->geometry().empty()) { file << "LINESTRING("; for (size_t i{0}; i < pStreet->geometry().size(); ++i) { diff --git a/src/dsm/sources/Sensors.cpp b/src/dsm/sources/Sensors.cpp index 18987750e..45f7f6449 100644 --- a/src/dsm/sources/Sensors.cpp +++ b/src/dsm/sources/Sensors.cpp @@ -1,9 +1,11 @@ #include "../headers/Sensors.hpp" namespace dsm { + void Counter::setCode(Id const code) { m_code = code; } void Counter::increaseInputCounter() { m_counters.first++; } void Counter::increaseOutputCounter() { m_counters.second++; } + Id Counter::code() const { return m_code; } int Counter::inputCounts(bool reset) { if (reset) { int count{0}; diff --git a/src/dsm/utility/Typedef.hpp b/src/dsm/utility/Typedef.hpp index 28194e91c..20dde48ce 100644 --- a/src/dsm/utility/Typedef.hpp +++ b/src/dsm/utility/Typedef.hpp @@ -30,6 +30,6 @@ namespace dsm { FRECCIAROSSA = 6, // Frecciarossa ES = 7, // Eurostar }; - enum log_level_t : uint8_t { DEBUG = 0, INFO = 1, WARNING = 2, ERROR = 3 }; + enum log_level_t : uint8_t { DEBUG = 0, WARNING = 1, INFO = 2, ERROR = 3 }; }; // namespace dsm diff --git a/test/data/edges.csv b/test/data/edges.csv index 53e983b2f..df7be0f4b 100644 --- a/test/data/edges.csv +++ b/test/data/edges.csv @@ -1,5 +1,5 @@ -id;source_id;target_id;name;geometry -8;2;2;;LINESTRING(0 2,0 2) -6;2;0;;LINESTRING(0 2,0 0) -3;1;0;;LINESTRING(0 1,0 0) -1;0;1;;LINESTRING(0 0,0 1) +id;source_id;target_id;name;coil_code;geometry +8;2;2;;;LINESTRING(0 2,0 2) +6;2;0;;;LINESTRING(0 2,0 0) +3;1;0;;;LINESTRING(0 1,0 0) +1;0;1;;;LINESTRING(0 0,0 1) diff --git a/test/data/nodes.csv b/test/data/nodes.csv index c41817f9a..d04ea1896 100644 --- a/test/data/nodes.csv +++ b/test/data/nodes.csv @@ -1,4 +1,4 @@ -id;lon;lat -1;0;1 -0;0;0 -2;0;2 +id;lon;lat;type +1;0;1;intersection +0;0;0;intersection +2;0;2;intersection