Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dsm/dsm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

static constexpr uint8_t DSM_VERSION_MAJOR = 2;
static constexpr uint8_t DSM_VERSION_MINOR = 3;
static constexpr uint8_t DSM_VERSION_PATCH = 16;
static constexpr uint8_t DSM_VERSION_PATCH = 17;

static auto const DSM_VERSION =
std::format("{}.{}.{}", DSM_VERSION_MAJOR, DSM_VERSION_MINOR, DSM_VERSION_PATCH);
Expand Down
16 changes: 16 additions & 0 deletions src/dsm/headers/Dynamics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <format>
#include <thread>
#include <exception>
#include <fstream>
#include <filesystem>

#include "DijkstraWeights.hpp"
#include "Itinerary.hpp"
Expand All @@ -31,6 +33,8 @@
#include "../utility/Logger.hpp"
#include "../utility/Typedef.hpp"

static auto constexpr g_cacheFolder = "./.dsmcache/";

namespace dsm {
/// @brief The Measurement struct represents the mean of a quantity and its standard deviation
/// @tparam T The type of the quantity
Expand Down Expand Up @@ -81,6 +85,13 @@
/// @brief Update the path of a single itinerary using Dijsktra's algorithm
/// @param pItinerary An std::unique_prt to the itinerary
void m_updatePath(const std::unique_ptr<Itinerary>& pItinerary) {
auto const& file = std::format("{}it{}.dsmcache", g_cacheFolder, pItinerary->id());
if (std::filesystem::exists(file)) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 14.4 rule Note

MISRA 14.4 rule
auto path = SparseMatrix<bool>{};
path.load(file);
pItinerary->setPath(std::move(path));
return;
}
Size const dimension = m_graph.adjMatrix().getRowDim();
auto const destinationID = pItinerary->destination();
SparseMatrix<bool> path{dimension, dimension};
Expand Down Expand Up @@ -125,6 +136,8 @@
pItinerary->destination()));
}
pItinerary->setPath(path);
pItinerary->path().cache(
std::format("{}it{}.dsmcache", g_cacheFolder, pItinerary->id()));
}

public:
Expand Down Expand Up @@ -288,6 +301,9 @@

template <typename agent_t>
void Dynamics<agent_t>::updatePaths() {
if (!std::filesystem::exists(g_cacheFolder)) {
std::filesystem::create_directory(g_cacheFolder);
}
std::vector<std::thread> threads;
threads.reserve(m_itineraries.size());
std::exception_ptr pThreadException;
Expand Down Expand Up @@ -492,7 +508,7 @@
auto meanDensity{std::accumulate(densities.begin(), densities.end(), 0.) / sum};
return Measurement(meanDensity, 0.);
}
return Measurement<double>(densities);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.5 rule Note

MISRA 15.5 rule
}

template <typename agent_t>
Expand Down
Loading