LCOV - code coverage report
Current view: top level - app/src/Static/supply - Network.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 25 29 86.2 %
Date: 2023-08-17 16:45:52 Functions: 4 5 80.0 %

          Line data    Source code
       1             : #include "Static/supply/Network.hpp"
       2             : 
       3             : #include "Static/Solution.hpp"
       4             : #include "utils/strong_hash.hpp"
       5             : 
       6             : using namespace std;
       7             : using namespace Static;
       8             : using namespace Alg;
       9             : 
      10             : typedef Network::Edge Edge;
      11             : 
      12       21116 : Network::Edge::Edge(ID id_, Node u_, Node v_):
      13             :     id(id_),
      14             :     u(u_),
      15       21116 :     v(v_) {}
      16             : 
      17           0 : Time Network::Edge::calculateDelay(const Solution &x) const {
      18           0 :     Time fft = calculateCost(SolutionBase());
      19           0 :     Time t   = calculateCost(x);
      20           0 :     return (fft > 0.0 ? t / fft : 1.0);
      21             : }
      22             : 
      23          13 : Graph Network::toGraph(const Solution &solution) const {
      24          13 :     Graph G;
      25             : 
      26          13 :     const vector<Node> &nodes = getNodes();
      27       15344 :     for(const Node &u: nodes)
      28       15331 :         G.addNode(u);
      29             : 
      30       15344 :     for(const Node &u: nodes) {
      31       30662 :         const vector<Edge *> &adj = getAdj(u);
      32       36456 :         for(const Edge *e: adj) {
      33       21125 :             Time c = e->calculateCost(solution);
      34       21125 :             G.addEdge(e->id, u, e->v, c);
      35             :         }
      36             :     }
      37             : 
      38          26 :     return G;
      39             : }
      40             : 
      41         158 : Time Network::evaluate(const Solution &solution) const {
      42         158 :     Time c = 0;
      43             : 
      44         158 :     unordered_set<Edge::ID> edgeIDs = solution.getEdges();
      45         534 :     for(const Edge::ID &eid: edgeIDs) {
      46         376 :         Edge &e = getEdge(eid);
      47         376 :         c += e.calculateCostGlobal(solution);
      48             :     }
      49             : 
      50         158 :     return c;
      51             : }
      52             : 
      53          25 : size_t hash<Network::Path>::operator()(const Network::Path &v) const {
      54             :     // From:
      55             :     // - https://stackoverflow.com/a/72073933/12283316
      56             :     // This hash function only uses the size, first and last elements of vector.
      57             :     // It should be a somewhat bad but reasonable hash, that is lightning-fast
      58             :     // to calculate.
      59          25 :     size_t seed = v.size();
      60          25 :     seed ^= v.front() + 0x9e3779b9 + (seed << 6) + (seed >> 2);
      61          25 :     seed ^= v.back() + 0x9e3779b9 + (seed << 6) + (seed >> 2);
      62          25 :     return seed;
      63             : }

Generated by: LCOV version 1.14