Skip to content

Commit 18482cc

Browse files
committed
Change saveTravelSpeeds -> saveTravelData
1 parent 202db42 commit 18482cc

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ cmake --install build
4949
```
5050

5151
## Installation via Pybind11
52-
If you want to use the library from Python, you can build the Python bindings using [pybind11](https://github.com/pybind/pybind11). Make sure you have Python and pybind11 installed:
52+
If you want to use the library from Python, you can build the Python bindings using [pybind11](https://github.com/pybind/pybind11). Make sure you have doxygen installed to generate the docstrings:
5353
```shell
54-
pip install pybind11
54+
sudo apt install doxygen
5555
```
5656

5757
Then, the installation is automatic via `pip`:

src/dsf/binding.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,11 @@ PYBIND11_MODULE(dsf, m) {
396396
pybind11::arg("reset") = false,
397397
pybind11::arg("separator") = ';',
398398
dsf::g_docstrings.at("dsf::RoadDynamics::saveOutputStreetCounts").c_str())
399-
.def("saveTravelSpeeds",
400-
&dsf::FirstOrderDynamics::saveTravelSpeeds,
399+
.def("saveTravelData",
400+
&dsf::FirstOrderDynamics::saveTravelData,
401401
pybind11::arg("filename"),
402402
pybind11::arg("reset") = false,
403-
dsf::g_docstrings.at("dsf::RoadDynamics::saveTravelSpeeds").c_str())
403+
dsf::g_docstrings.at("dsf::RoadDynamics::saveTravelData").c_str())
404404
.def("saveMacroscopicObservables",
405405
&dsf::FirstOrderDynamics::saveMacroscopicObservables,
406406
pybind11::arg("filename"),

src/dsf/dsf.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <format>
66

77
static constexpr uint8_t DSF_VERSION_MAJOR = 3;
8-
static constexpr uint8_t DSF_VERSION_MINOR = 2;
8+
static constexpr uint8_t DSF_VERSION_MINOR = 3;
99
static constexpr uint8_t DSF_VERSION_PATCH = 0;
1010

1111
static auto const DSF_VERSION =

src/dsf/headers/RoadDynamics.hpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,15 @@ namespace dsf {
344344
void saveOutputStreetCounts(const std::string& filename,
345345
bool reset = false,
346346
char const separator = ';');
347-
/// @brief Save the travel speeds of the agents in csv format
347+
/// @brief Save the travel data of the agents in csv format.
348+
/// @details The file contains the following columns:
349+
/// - time: the time of the simulation
350+
/// - distances: the travel distances of the agents
351+
/// - times: the travel times of the agents
352+
/// - speeds: the travel speeds of the agents
348353
/// @param filename The name of the file
349354
/// @param reset If true, the travel speeds are cleared after the computation
350-
void saveTravelSpeeds(const std::string& filename, bool reset = false);
355+
void saveTravelData(const std::string& filename, bool reset = false);
351356
/// @brief Save the main macroscopic observables in csv format
352357
/// @param filename The name of the file
353358
/// @param separator The separator character (default is ';')
@@ -2326,22 +2331,37 @@ namespace dsf {
23262331
}
23272332
template <typename delay_t>
23282333
requires(is_numeric_v<delay_t>)
2329-
void RoadDynamics<delay_t>::saveTravelSpeeds(const std::string& filename, bool reset) {
2334+
void RoadDynamics<delay_t>::saveTravelData(const std::string& filename, bool reset) {
23302335
bool bEmptyFile{false};
23312336
{
23322337
std::ifstream file(filename);
23332338
bEmptyFile = file.peek() == std::ifstream::traits_type::eof();
23342339
}
23352340
std::ofstream file(filename, std::ios::app);
23362341
if (!file.is_open()) {
2337-
Logger::error(std::format("Error opening file \"{}\" for writing.", filename));
2342+
throw std::runtime_error(Logger::buildExceptionMessage(
2343+
"Error opening file \"" + filename + "\" for writing."));
23382344
}
23392345
if (bEmptyFile) {
2340-
file << "time;speeds" << std::endl;
2346+
file << "time;distances;times;speeds" << std::endl;
23412347
}
23422348
file << this->time() << ';';
23432349
for (auto it = m_travelDTs.cbegin(); it != m_travelDTs.cend(); ++it) {
2344-
file << std::fixed << std::setprecision(2) << it->first / it->second;
2350+
file << std::format("{:.2f}", it->first);
2351+
if (it != m_travelDTs.cend() - 1) {
2352+
file << ',';
2353+
}
2354+
}
2355+
file << ';';
2356+
for (auto it = m_travelDTs.cbegin(); it != m_travelDTs.cend(); ++it) {
2357+
file << it->second;
2358+
if (it != m_travelDTs.cend() - 1) {
2359+
file << ',';
2360+
}
2361+
}
2362+
file << ';';
2363+
for (auto it = m_travelDTs.cbegin(); it != m_travelDTs.cend(); ++it) {
2364+
file << std::format("{:.2f}", it->first / it->second);
23452365
if (it != m_travelDTs.cend() - 1) {
23462366
file << ',';
23472367
}

0 commit comments

Comments
 (0)