Skip to content

Commit 6e2b354

Browse files
authored
Rework SparseMatrix class (#299)
* Remove useless things * Init SparseMatrix rework * End SparseMatrix implementation * Add copy and move constructors. Add normalize function * Enchance tests * typo * Using reduce * fixes * Add sparsematrix import from csv
1 parent 15f03a8 commit 6e2b354

File tree

10 files changed

+424
-1492
lines changed

10 files changed

+424
-1492
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,7 @@ images
3838
examples/debug
3939
examples/release
4040

41+
test/data/*dsm
42+
4143

4244
webapp/data/*

benchmark/Adj/BenchAdj.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ int main() {
1717
graph.buildAdj();
1818
auto const& adj{graph.adjacencyMatrix()};
1919
auto const N{adj.n()};
20-
SparseMatrix<bool> sm(N, N);
20+
SparseMatrix<bool> sm;
2121
for (const auto& [srcId, dstId] : adj.elements()) {
22-
sm.insert(srcId, dstId);
22+
sm.insert(srcId, dstId, true);
2323
}
2424

2525

@@ -28,14 +28,14 @@ int main() {
2828
Logger::info("Benchmarking SparseMatrix::getCol");
2929
b1.benchmark([&sm, &N]() -> void {
3030
for (size_t i{0}; i < N; ++i) {
31-
sm.getCol(i);
31+
sm.col(i);
3232
}
3333
});
3434
b1.print<sb::microseconds>();
3535
Logger::info("Benchmarking SparseMatrix::getRow");
3636
b2.benchmark([&sm, &N]() -> void {
3737
for (size_t i{0}; i < N; ++i) {
38-
sm.getRow(i);
38+
sm.row(i);
3939
}
4040
});
4141
b2.print<sb::microseconds>();

src/dsm/dsm.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
static constexpr uint8_t DSM_VERSION_MAJOR = 2;
88
static constexpr uint8_t DSM_VERSION_MINOR = 6;
9-
static constexpr uint8_t DSM_VERSION_PATCH = 23;
9+
static constexpr uint8_t DSM_VERSION_PATCH = 24;
1010

1111
static auto const DSM_VERSION =
1212
std::format("{}.{}.{}", DSM_VERSION_MAJOR, DSM_VERSION_MINOR, DSM_VERSION_PATCH);

src/dsm/headers/AdjacencyMatrix.hpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ namespace dsm {
2828
/// It is defined as \f$A = (a_{ij})\f$, where \f$a_{ij} \in \{0, 1\}\f$.
2929
/// Moreover, \f$a_{ij} = 1\f$ if there is an edge from node \f$i\f$ to node \f$j\f$ and \f$a_{ij} = 0\f$ otherwise.
3030
/// It is used to store the adjacency matrix of the network and to perform operations on it.
31-
/// The adjacency matrix is stored in compressed sparse row format.
31+
/// The adjacency matrix is stored in both CSR and CSC formats, to optimize access to rows and columns.
32+
/// Thus, this matrix has very fast access, using double the memory of a standard CSR/CSC one.
3233
class AdjacencyMatrix {
3334
private:
3435
// CSR format
@@ -44,15 +45,6 @@ namespace dsm {
4445
friend std::vector<Id> test::indices(const AdjacencyMatrix& adj);
4546

4647
public:
47-
using value_type = Id;
48-
using difference_type = std::ptrdiff_t;
49-
using reference = Id&;
50-
using const_reference = const Id&;
51-
using iterator = std::vector<Id>::iterator;
52-
using const_iterator = std::vector<Id>::const_iterator;
53-
using reverse_iterator = std::vector<Id>::reverse_iterator;
54-
using const_reverse_iterator = std::vector<Id>::const_reverse_iterator;
55-
5648
/// @brief Construct a new AdjacencyMatrix object
5749
AdjacencyMatrix();
5850
/// @brief Construct a new AdjacencyMatrix object using the @ref read method

src/dsm/headers/RoadNetwork.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ namespace dsm {
272272
std::optional<DijkstraResult> RoadNetwork::shortestPath(const Node& source,
273273
const Node& destination,
274274
Func f) const {
275-
return this->shortestPath(source.id(), destination.id());
275+
return this->shortestPath(source.id(), destination.id(), f);
276276
}
277277

278278
template <typename Func>

0 commit comments

Comments
 (0)