LCOV - code coverage report
Current view: top level - app/src/Static - Demand.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 38 42 90.5 %
Date: 2023-08-17 16:45:52 Functions: 6 6 100.0 %

          Line data    Source code
       1             : #include "Static/Demand.hpp"
       2             : 
       3             : #include <iostream>
       4             : #include <stdexcept>
       5             : 
       6             : using namespace std;
       7             : using namespace Static;
       8             : 
       9             : typedef Network::Node Node;
      10             : 
      11        7313 : void Demand::addDemand(Node u, Node v, Flow f) {
      12        7313 :     flows[u][v] += f;
      13        7313 : }
      14             : 
      15           9 : vector<Node> Demand::getStartNodes() const {
      16           9 :     vector<Node> ret;
      17           9 :     ret.reserve(flows.size());
      18             : 
      19          18 :     for(const auto &[u, _]: flows)
      20           9 :         ret.push_back(u);
      21             : 
      22           9 :     return ret;
      23             : }
      24             : 
      25           9 : vector<Node> Demand::getDestinations(Node u) const {
      26           9 :     const auto &dest = flows.at(u);
      27             : 
      28           9 :     vector<Node> ret;
      29           9 :     ret.reserve(dest.size());
      30             : 
      31          18 :     for(const auto &[v, _]: dest)
      32           9 :         ret.push_back(v);
      33             : 
      34           9 :     return ret;
      35             : }
      36             : 
      37           9 : Flow Demand::getDemand(Node u, Node v) const {
      38           9 :     return flows.at(u).at(v);
      39             : }
      40             : 
      41           3 : Flow Demand::getTotalDemand() const {
      42           3 :     Flow f = 0;
      43           6 :     for(const auto &p1: flows) {
      44           6 :         for(const auto &p2: p1.second) {
      45           3 :             f += p2.second;
      46             :         }
      47             :     }
      48           3 :     return f;
      49             : }
      50             : 
      51             : // clang-format off
      52           1 : Demand Demand::Loader<
      53             :     const VISUM::OFormatDemand &,
      54             :     const SUMOAdapter &    
      55             : >::load(
      56             :     const VISUM::OFormatDemand &oDemand,
      57             :     const SUMOAdapter           &adapter
      58             : ) {
      59             :     // clang-format on
      60             : 
      61           1 :     Demand demand;
      62             : 
      63           1 :     const auto &startNodes = oDemand.getStartNodes();
      64         120 :     for(const auto &u: startNodes) {
      65         357 :         const auto &destinations = oDemand.getDestinations(u);
      66        7428 :         for(const auto &v: destinations) {
      67        7309 :             Static::Network::Node source, sink;
      68        7309 :             try {
      69        7309 :                 source = adapter.toTAZNode(u).first;
      70           0 :             } catch(const out_of_range &e) {
      71           0 :                 throw out_of_range("TAZ source node " + u + " does not exist.");
      72             :             }
      73        7309 :             try {
      74        7309 :                 sink = adapter.toTAZNode(v).second;
      75           0 :             } catch(const out_of_range &e) {
      76           0 :                 throw out_of_range("TAZ sink node " + v + " does not exist.");
      77             :             }
      78             : 
      79        7309 :             demand.addDemand(
      80             :                 source,
      81             :                 sink,
      82       21927 :                 oDemand.getDemand(u, v) / (oDemand.getTo() - oDemand.getFrom())
      83             :             );
      84             :         }
      85             :     }
      86             : 
      87           1 :     return demand;
      88             : }

Generated by: LCOV version 1.14