Skip to content

Commit c826a7c

Browse files
committed
sync
1 parent a850e53 commit c826a7c

34 files changed

+2010
-2220
lines changed

include/maxplus/algebra/mpmatrix.h

Lines changed: 37 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -81,36 +81,36 @@ class Vector {
8181

8282
Vector &operator=(const Vector &);
8383

84-
MPTime norm();
84+
[[nodiscard]] MPTime norm() const;
8585

8686
void negate();
8787
MPTime normalize();
8888

89-
[[nodiscard]] Vector *add(MPTime increase) const;
89+
[[nodiscard]] Vector add(MPTime increase) const;
9090

91-
void add(MPTime increase, Vector *result) const;
91+
void add(MPTime increase, Vector& result) const;
9292

93-
void maximum(const Vector *matB, Vector *result) const;
93+
void maximum(const Vector& vecB, Vector& result) const;
9494

95-
Vector *add(const Vector *vecB) const;
95+
[[nodiscard]] Vector add(const Vector& vecB) const;
9696

97-
void add(const Vector *vecB, Vector *res) const;
97+
void add(const Vector& vecB, Vector& res) const;
9898

9999
Vector &operator+=(MPTime increase) {
100-
this->add(increase, this);
100+
this->add(increase, *this);
101101
return *this;
102102
}
103103

104104
Vector &operator-=(MPTime decrease) {
105105
assert(!decrease.isMinusInfinity());
106-
this->add(-decrease, this);
106+
this->add(-decrease, *this);
107107
return *this;
108108
}
109109

110-
bool compare(const Vector &v);
110+
[[nodiscard]] bool compare(const Vector &v) const;
111111

112-
Vector &incrementalMaximum(const Vector *vec) {
113-
this->maximum(vec, this);
112+
Vector &incrementalMaximum(const Vector& vec) {
113+
this->maximum(vec, *this);
114114
return *this;
115115
}
116116

@@ -145,10 +145,13 @@ class Matrix {
145145
*/
146146
Matrix(unsigned int nr_rows, unsigned int nr_cols, MatrixFill fill = MatrixFill::MinusInfinity);
147147

148-
Matrix(unsigned int nrows, unsigned int nr_cols, unsigned int nr_el);
148+
Matrix(unsigned int nr_rows, unsigned int nr_cols, unsigned int nr_el);
149149

150150
Matrix(Matrix &&) = default;
151151
Matrix &operator=(Matrix &&) = default;
152+
Matrix(const Matrix &)=default;
153+
154+
Matrix &operator=(const Matrix &);
152155

153156
virtual ~Matrix();
154157

@@ -167,16 +170,16 @@ class Matrix {
167170

168171
void pasteRowVector(unsigned int top_row, unsigned int left_column, const Vector *pastedVector);
169172

170-
[[nodiscard]] virtual Matrix *createCopy() const;
173+
// [[nodiscard]] virtual Matrix *createCopy() const;
171174

172-
[[nodiscard]] Matrix *getTransposedCopy() const;
175+
[[nodiscard]] Matrix transpose() const;
173176

174-
[[nodiscard]] virtual Matrix *getSubMatrix(const std::list<unsigned int> &rowIndices,
177+
[[nodiscard]] virtual Matrix getSubMatrix(const std::list<unsigned int> &rowIndices,
175178
const std::list<unsigned int> &colIndices) const;
176179

177-
[[nodiscard]] Matrix *getSubMatrix(const std::list<unsigned int> &indices) const;
180+
[[nodiscard]] Matrix getSubMatrix(const std::list<unsigned int> &indices) const;
178181

179-
[[nodiscard]] Matrix *getSubMatrixNonSquare(const std::list<unsigned int> &indices) const;
182+
[[nodiscard]] Matrix getSubMatrixNonSquare(const std::list<unsigned int> &indices) const;
180183

181184
/**
182185
* Increases the number of rows of the matrix by n and fills the new elements with -\infty.
@@ -188,21 +191,21 @@ class Matrix {
188191
void toLaTeXString(CString &outString, CDouble scale = 1.0) const;
189192

190193
// Algebraic operations.
191-
[[nodiscard]] Matrix *add(MPTime increase) const;
194+
[[nodiscard]] Matrix add(MPTime increase) const;
192195

193-
void add(MPTime increase, Matrix *result) const;
196+
void add(MPTime increase, Matrix& result) const;
194197

195-
[[nodiscard]] Matrix *mp_sub(const Matrix &m) const;
198+
[[nodiscard]] Matrix mp_sub(const Matrix &m) const;
196199

197-
[[nodiscard]] Matrix *mp_maximum(const Matrix &m) const;
200+
[[nodiscard]] Matrix mp_maximum(const Matrix &m) const;
198201

199-
void maximum(const Matrix *matB, Matrix *result) const;
202+
void maximum(const Matrix& matB, Matrix& result) const;
200203

201-
[[nodiscard]] Vector *mp_multiply(const Vector &v) const;
204+
[[nodiscard]] Vector mp_multiply(const Vector &v) const;
202205

203-
[[nodiscard]] Matrix *mp_multiply(const Matrix &m) const;
206+
[[nodiscard]] Matrix mp_multiply(const Matrix &m) const;
204207

205-
[[nodiscard]] Matrix *mp_power(unsigned int p) const;
208+
[[nodiscard]] Matrix mp_power(unsigned int p) const;
206209

207210
[[nodiscard]] CDouble mp_eigenvalue() const;
208211

@@ -213,19 +216,18 @@ class Matrix {
213216
[[nodiscard]] EigenvectorList mpEigenvectors() const;
214217

215218
Matrix &operator+=(MPTime increase) {
216-
this->add(increase, this);
219+
this->add(increase, *this);
217220
return *this;
218221
}
219222

220223
Matrix &operator-=(MPTime decrease) {
221224
assert(!decrease.isMinusInfinity());
222-
this->add(-decrease, this);
225+
this->add(-decrease, *this);
223226
return *this;
224227
}
225228

226-
Matrix &incrementalMaximum(const Matrix *matrix) {
227-
this->maximum(matrix, this);
228-
return *this;
229+
void incrementalMaximum(const Matrix& matrix) {
230+
this->maximum(matrix, *this);
229231
}
230232

231233
bool operator==(const Matrix &other);
@@ -237,26 +239,21 @@ class Matrix {
237239
[[nodiscard]] MPTime largestFiniteElement() const;
238240
[[nodiscard]] MPTime minimalFiniteElement() const;
239241

240-
[[nodiscard]] Matrix *plusClosureMatrix(MPTime posCycleThreshold = MP_EPSILON) const;
242+
[[nodiscard]] Matrix plusClosureMatrix(MPTime posCycleThreshold = MP_EPSILON) const;
241243

242-
[[nodiscard]] Matrix *starClosureMatrix(MPTime posCycleThreshold = MP_EPSILON) const;
244+
[[nodiscard]] Matrix starClosureMatrix(MPTime posCycleThreshold = MP_EPSILON) const;
243245

244-
[[nodiscard]] Matrix *allPairLongestPathMatrix(MPTime posCycleThreshold,
246+
[[nodiscard]] Matrix allPairLongestPathMatrix(MPTime posCycleThreshold,
245247
bool implyZeroSelfEdges) const;
246248
bool
247249
allPairLongestPathMatrix(MPTime posCycleThreshold, bool implyZeroSelfEdges, Matrix &res) const;
248250

249251
[[nodiscard]] MCMgraph mpMatrixToPrecedenceGraph() const;
250252

251-
// factory methods
252-
[[nodiscard]] virtual Matrix *makeMatrix(unsigned int nr_rows, unsigned int nr_cols) const;
253+
// // factory methods
254+
// [[nodiscard]] virtual Matrix *makeMatrix(unsigned int nr_rows, unsigned int nr_cols) const;
253255

254256
private:
255-
// Implicit copying is not allowed
256-
// => Intentionally private and not implemented
257-
Matrix(const Matrix &);
258-
259-
Matrix &operator=(const Matrix &);
260257

261258
void init(MatrixFill fill);
262259
void init();
@@ -268,44 +265,6 @@ class Matrix {
268265
unsigned int szCols;
269266
};
270267

271-
class ExtendedMatrix : public Matrix {
272-
public:
273-
ExtendedMatrix(unsigned int nrows, unsigned int nr_cols) : Matrix(nrows, nr_cols) {
274-
unsigned int nr_els = this->getRows() * this->getCols();
275-
this->bufferSets.resize(nr_els);
276-
}
277-
278-
// Creates a matrix with reserved memory for nr_el expected entities
279-
ExtendedMatrix(unsigned int nrows, unsigned int nr_cols, unsigned int nr_el) :
280-
Matrix(nrows, nr_cols, nr_el) {
281-
this->bufferSets.reserve(nr_el);
282-
}
283-
explicit ExtendedMatrix(unsigned int N) : Matrix(N) {}
284-
285-
[[nodiscard]] Matrix *createCopy() const override {
286-
Matrix *newMatrix = Matrix::createCopy();
287-
auto *newExtendedMatrix = dynamic_cast<ExtendedMatrix *>(newMatrix);
288-
289-
unsigned int nr_els = this->getRows() * this->getCols();
290-
for (unsigned int pos = 0; pos < nr_els; pos++) {
291-
newExtendedMatrix->bufferSets[pos] = this->bufferSets[pos];
292-
}
293-
294-
return newExtendedMatrix;
295-
}
296-
297-
void put(unsigned int row, unsigned int column, MPTime value, std::unordered_set<int> &);
298-
[[nodiscard]] Matrix *getSubMatrix(const std::list<unsigned int> &rowIndices,
299-
const std::list<unsigned int> &colIndices) const override;
300-
301-
// factory methods
302-
[[nodiscard]] Matrix *makeMatrix(unsigned int nr_rows, unsigned int nr_cols) const override;
303-
304-
[[nodiscard]] std::unordered_set<int> getBufferSet(unsigned int row, unsigned int column) const;
305-
306-
private:
307-
std::vector<std::unordered_set<int>> bufferSets;
308-
};
309268

310269
/****************************************************
311270
* VectorList: usually represents a set of eigenvectors

include/maxplus/algebra/mpsparsematrix.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class SparseVector {
101101

102102
[[nodiscard]] SparseVector add(MPTime increase) const;
103103

104-
[[nodiscard]] SparseVector maximum(const SparseVector &matB) const;
104+
[[nodiscard]] SparseVector maximum(const SparseVector &vecB) const;
105105

106106
[[nodiscard]] SparseVector add(const SparseVector &vecB) const;
107107

@@ -184,7 +184,7 @@ class SparseMatrix {
184184
SparseMatrix maximum(const SparseMatrix &M);
185185

186186
SparseMatrix multiply(const SparseMatrix &M);
187-
SparseVector multiply(const SparseVector &M);
187+
SparseVector multiply(const SparseVector &v);
188188

189189
void compress();
190190

@@ -210,9 +210,9 @@ class SparseMatrix {
210210
std::vector<std::pair<unsigned int, SparseVector>> table;
211211
std::pair<unsigned int, unsigned int> find(unsigned int col);
212212
void doTranspose();
213-
SparseMatrix combine(const SparseMatrix &vecB, MPTime f(MPTime a, MPTime b));
214-
Matrix *reduceRows();
215-
std::pair<Matrix *, Sizes> reduceRowsAndColumns();
213+
SparseMatrix combine(const SparseMatrix &M, MPTime f(MPTime a, MPTime b));
214+
Matrix reduceRows();
215+
std::pair<Matrix, Sizes> reduceRowsAndColumns();
216216
static SparseMatrix expand(const Matrix &M, const Sizes &rszs, const Sizes &cszs);
217217
[[nodiscard]] Sizes sizes() const;
218218
};

include/maxplus/base/analysis/mcm/mcm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace Graphs {
5555
* algorithm.
5656
*/
5757
CDouble maximumCycleMeanKarp(const MCMgraph& g);
58-
CDouble maximumCycleMeanKarpDouble(const MCMgraph& g, MCMnode **criticalNode = nullptr);
58+
CDouble maximumCycleMeanKarpDouble(const MCMgraph& g, const MCMnode **criticalNode = nullptr);
5959

6060
/**
6161
* mcmGetAdjacentActors ()

0 commit comments

Comments
 (0)