Skip to content

Commit 7bd8841

Browse files
committed
Fix
1 parent d1b7f7b commit 7bd8841

File tree

7 files changed

+30
-23
lines changed

7 files changed

+30
-23
lines changed

benchmark/Bench_Network.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ static void BM_RoadNetwork_AllPathsTo(benchmark::State& state) {
6363
network.importNodeProperties((DATA_FOLDER / "forlì_nodes.csv").string());
6464
auto itNode = network.nodes().cbegin();
6565
for (auto _ : state) {
66-
auto paths = network.allPathsTo(itNode->first,
67-
[](auto const& pEdge) { return pEdge->length(); });
66+
auto paths =
67+
network.allPathsTo(itNode->first, [](auto const& edge) { return edge.length(); });
6868
++itNode;
6969
}
7070
}
@@ -75,9 +75,8 @@ static void BM_RoadNetwork_ShortestPath(benchmark::State& state) {
7575
auto itSource = network.nodes().cbegin();
7676
auto itTarget = std::next(network.nodes().cbegin(), network.nodes().size() / 2);
7777
for (auto _ : state) {
78-
auto path = network.shortestPath(itSource->first,
79-
itTarget->first,
80-
[](auto const& pEdge) { return pEdge->length(); });
78+
auto path = network.shortestPath(
79+
itSource->first, itTarget->first, [](auto const& edge) { return edge.length(); });
8180
benchmark::DoNotOptimize(path);
8281
++itSource;
8382
++itTarget;

examples/stalingrado.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ int main() {
101101
++it;
102102
}
103103
if (progress % 300 == 0) {
104-
ofs << progress << ';' << coil->counts() << std::endl;
105-
coil->resetCounter();
104+
ofs << progress << ';' << coil.counts() << std::endl;
105+
coil.resetCounter();
106106
}
107107
dynamics.addAgents(*it, pItinerary, 0);
108108
}

profiling/parse_massif.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,17 @@ std::vector<long> parse_massif(const std::string& file_path) {
1616

1717
const char equal{'='};
1818
std::string buffer;
19-
while (getline(file, buffer)) {
19+
while (std::getline(file, buffer)) {
2020
if (buffer.find("mem_heap_B") != std::string::npos) {
2121
std::stringstream buffer_stream(buffer);
2222
std::string value;
23-
getline(buffer_stream, value, equal);
23+
std::getline(buffer_stream, value, equal);
2424
if (value == "mem_heap_B") {
25-
getline(buffer_stream, value);
25+
std::getline(buffer_stream, value);
2626
mem_values.push_back(std::stol(value));
2727
}
2828
}
2929
}
30-
31-
file.close();
3230
return mem_values;
3331
};
3432

@@ -39,7 +37,12 @@ int main(int argc, char* argv[]) {
3937
}
4038

4139
auto mem_values{parse_massif(argv[1])};
42-
long long int integral{std::accumulate(mem_values.begin(), mem_values.end(), 0)};
40+
if (mem_values.empty()) {
41+
std::cerr << "No mem_heap_B values found in file: " << argv[1] << '\n';
42+
return 1;
43+
}
44+
45+
long long integral{std::accumulate(mem_values.begin(), mem_values.end(), 0LL)};
4346
long max_mem{*std::max_element(mem_values.begin(), mem_values.end())};
4447

4548
std::cout << "integral: " << integral << " B\n";

src/dsf/base/Dynamics.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ namespace dsf {
119119
/// @brief Get the graph
120120
/// @return const network_t&, The graph
121121
inline auto const& graph() const { return m_graph; };
122+
/// @brief Get the graph (mutable)
123+
/// @return network_t&, The graph
124+
inline auto& graph() { return m_graph; };
122125
/// @brief Get the id of the simulation
123126
/// @return const Id&, The id of the simulation
124127
inline auto const& id() const { return m_id; };

src/dsf/base/Network.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,20 @@ namespace dsf {
6565

6666
/// @brief Get a node by id
6767
/// @param nodeId The node's id
68-
/// @return node_t& A reference to the node
69-
inline node_t& node(Id nodeId) const { return *m_nodes.at(nodeId); };
68+
/// @return const node_t& A reference to the node
69+
inline const auto& node(Id nodeId) const { return *m_nodes.at(nodeId); };
7070
/// @brief Get a node by id
7171
/// @param nodeId The node's id
7272
/// @return node_t& A reference to the node
73-
inline node_t& node(Id nodeId) { return *m_nodes.at(nodeId); };
73+
inline auto& node(Id nodeId) { return *m_nodes.at(nodeId); };
7474
/// @brief Get an edge by id
7575
/// @param edgeId The edge's id
76-
/// @return edge_t& A reference to the edge
77-
inline edge_t& edge(Id edgeId) const { return *m_edges.at(edgeId); };
76+
/// @return const edge_t& A reference to the edge
77+
inline const auto& edge(Id edgeId) const { return *m_edges.at(edgeId); };
7878
/// @brief Get an edge by id
7979
/// @param edgeId The edge's id
8080
/// @return edge_t& A reference to the edge
81-
inline edge_t& edge(Id edgeId) { return *m_edges.at(edgeId); }
81+
inline auto& edge(Id edgeId) { return *m_edges.at(edgeId); }
8282

8383
edge_t& edge(Id source, Id target) const;
8484
/// @brief Get a node by id

src/dsf/bindings.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,10 +468,9 @@ PYBIND11_MODULE(dsf_cpp, m) {
468468
reinterpret_cast<double (*)(double, double)>(arg.cast<uintptr_t>());
469469
self.setSpeedFunction(
470470
dsf::SpeedFunction::CUSTOM,
471-
[func_ptr](
472-
std::unique_ptr<dsf::mobility::Street> const& pStreet) -> double {
471+
[func_ptr](dsf::mobility::Street const& street) -> double {
473472
// No GIL needed — this is pure C
474-
return func_ptr(pStreet->maxSpeed(), pStreet->density(true));
473+
return func_ptr(street.maxSpeed(), street.density(true));
475474
});
476475
break;
477476
}
@@ -655,7 +654,9 @@ PYBIND11_MODULE(dsf_cpp, m) {
655654
dsf::g_docstrings.at("dsf::mobility::FirstOrderDynamics::optimizeTrafficLights")
656655
.c_str())
657656
.def("graph",
658-
&dsf::mobility::FirstOrderDynamics::graph,
657+
static_cast<const dsf::mobility::RoadNetwork& (
658+
dsf::mobility::FirstOrderDynamics::*)() const>(
659+
&dsf::mobility::FirstOrderDynamics::graph),
659660
pybind11::return_value_policy::reference_internal,
660661
dsf::g_docstrings.at("dsf::Dynamics::graph").c_str())
661662
.def("nAgents",

src/dsf/mobility/Street.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ namespace dsf::mobility {
165165
movingAgents() {
166166
return m_movingAgents;
167167
}
168+
inline const auto& movingAgents() const { return m_movingAgents; }
168169
static inline auto agentData() {
169170
if (!m_agentData.has_value()) {
170171
throw std::runtime_error(

0 commit comments

Comments
 (0)