LCOV - code coverage report
Current view: top level - app/include/Static/algos - IterativeEquilibration.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 38 0.0 %
Date: 2023-08-17 16:45:52 Functions: 0 2 0.0 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include "Log/ProgressLogger.hpp"
       4             : #include "Static/Demand.hpp"
       5             : #include "Static/Solution.hpp"
       6             : #include "Static/algos/FrankWolfe.hpp"
       7             : 
       8             : namespace Static {
       9             : template<typename NetworkType, typename FrankWolfeType>
      10             : class IterativeEquilibration {
      11             :     FrankWolfeType &fw;
      12             : 
      13             :     Log::ProgressLogger &logger;
      14             : 
      15             :     double epsilon;
      16             :     size_t iterations = 1000;
      17             : 
      18             :    public:
      19           0 :     IterativeEquilibration(
      20             :         FrankWolfeType      &fw_,
      21             :         Log::ProgressLogger &logger_
      22             :     ):
      23           0 :         fw(fw_), logger(logger_) {}
      24             : 
      25           0 :     void setIterations(size_t it) {
      26           0 :         iterations = it;
      27             :     }
      28             : 
      29             :     void setStopCriteria(double stopCriteria) {
      30             :         epsilon = stopCriteria;
      31             :     }
      32             : 
      33           0 :     Solution solve(
      34             :         const NetworkType &network,
      35             :         const Demand      &demand,
      36             :         const Solution    &startingSolution
      37             :     ) {
      38             :         typedef std::chrono::high_resolution_clock hrc;
      39             : 
      40           0 :         logger << Log::ProgressLogger::Elapsed(0)
      41           0 :                << Log::ProgressLogger::Progress(0)
      42           0 :                << Log::ProgressLogger::StartText()
      43           0 :                << "it\tzn"
      44           0 :                << Log::ProgressLogger::EndMessage();
      45             : 
      46           0 :         const hrc::time_point tStart = hrc::now();
      47             : 
      48           0 :         Solution xn = startingSolution;
      49             : 
      50           0 :         double zn = network.evaluate(xn);
      51             : 
      52           0 :         Solution xBest = xn;
      53           0 :         double   zBest = zn;
      54             : 
      55           0 :         logger << Log::ProgressLogger::Elapsed(0)
      56           0 :                << Log::ProgressLogger::Progress(0)
      57           0 :                << Log::ProgressLogger::StartText()
      58           0 :                << 0
      59           0 :                << "\t" << zn
      60           0 :                << Log::ProgressLogger::EndMessage();
      61             : 
      62           0 :         for(size_t it = 1; it <= iterations; it++) {
      63           0 :             Solution xPrev = xn;
      64             : 
      65           0 :             xn = fw.solve(
      66             :                 network.makeConvex(xn),
      67             :                 demand,
      68             :                 xn
      69             :             );
      70             : 
      71           0 :             zn = network.evaluate(xn);
      72             : 
      73           0 :             const hrc::time_point t = hrc::now();
      74             : 
      75           0 :             double elapsed = (double)std::chrono::duration_cast<std::chrono::nanoseconds>(t - tStart).count() * 1e-9;
      76             : 
      77           0 :             double progress = (double)it / (double)iterations;
      78             : 
      79           0 :             logger << Log::ProgressLogger::Elapsed(elapsed)
      80           0 :                    << Log::ProgressLogger::Progress(progress)
      81           0 :                    << Log::ProgressLogger::StartText()
      82           0 :                    << it
      83           0 :                    << "\t" << zn
      84           0 :                    << Log::ProgressLogger::EndMessage();
      85             : 
      86           0 :             if(zn < zBest) {
      87           0 :                 xBest = xn;
      88           0 :                 zBest = zn;
      89             :             }
      90             :         }
      91           0 :         return xBest;
      92             :     }
      93             : };
      94             : }  // namespace Static

Generated by: LCOV version 1.14