Skip to content

Commit 2d67238

Browse files
author
Marc Geilen
committed
sync
1 parent 64f3c55 commit 2d67238

File tree

33 files changed

+1000
-936
lines changed

33 files changed

+1000
-936
lines changed

documentation/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/html/
1+
/html/
2+
Doxyfile.doc

include/maxplus/algebra/mpmatrix.h

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#include <unordered_set>
4848
#include <vector>
4949

50-
5150
class CString;
5251

5352
namespace MaxPlus {
@@ -66,7 +65,7 @@ class Vector {
6665
~Vector();
6766

6867
Vector(Vector &&) = default;
69-
Vector &operator=(Vector &&) = default;
68+
Vector &operator=(Vector &&) = delete;
7069

7170
[[nodiscard]] inline unsigned int getSize() const {
7271
return static_cast<unsigned int>(this->table.size());
@@ -76,7 +75,7 @@ class Vector {
7675

7776
void put(unsigned int row, MPTime value);
7877

79-
void toString(CString &outString, double scale = 1.0) const;
78+
void toString(CString &outString, CDouble scale = 1.0) const;
8079

8180
Vector(const Vector &);
8281

@@ -125,7 +124,7 @@ class Vector {
125124
MPTime minimalFiniteElement(unsigned int *itsPosition_Ptr = nullptr) const;
126125

127126
private:
128-
vector<MPTime> table;
127+
std::vector<MPTime> table;
129128
};
130129

131130
enum class MatrixFill { MinusInfinity, Zero, Identity };
@@ -172,21 +171,21 @@ class Matrix {
172171

173172
[[nodiscard]] Matrix *getTransposedCopy() const;
174173

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

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

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

182181
/**
183182
* Increases the number of rows of the matrix by n and fills the new elements with -\infty.
184183
*/
185184
void addRows(uint n);
186185

187-
void toString(CString &outString, double scale = 1.0) const;
188-
void toMatlabString(CString &outString, double scale = 1.0) const;
189-
void toLaTeXString(CString &outString, double scale = 1.0) const;
186+
void toString(CString &outString, CDouble scale = 1.0) const;
187+
void toMatlabString(CString &outString, CDouble scale = 1.0) const;
188+
void toLaTeXString(CString &outString, CDouble scale = 1.0) const;
190189

191190
// Algebraic operations.
192191
[[nodiscard]] Matrix *add(MPTime increase) const;
@@ -264,7 +263,7 @@ class Matrix {
264263

265264
Matrix();
266265

267-
vector<MPTime> table;
266+
std::vector<MPTime> table;
268267
unsigned int szRows;
269268
unsigned int szCols;
270269
};
@@ -296,16 +295,16 @@ class ExtendedMatrix : public Matrix {
296295
}
297296

298297
void put(unsigned int row, unsigned int column, MPTime value, std::unordered_set<int> &);
299-
[[nodiscard]] Matrix *getSubMatrix(const list<unsigned int> &rowIndices,
300-
const list<unsigned int> &colIndices) const override;
298+
[[nodiscard]] Matrix *getSubMatrix(const std::list<unsigned int> &rowIndices,
299+
const std::list<unsigned int> &colIndices) const override;
301300

302301
// factory methods
303302
[[nodiscard]] Matrix *makeMatrix(unsigned int nr_rows, unsigned int nr_cols) const override;
304303

305304
[[nodiscard]] std::unordered_set<int> getBufferSet(unsigned int row, unsigned int column) const;
306305

307306
private:
308-
vector<std::unordered_set<int>> bufferSets;
307+
std::vector<std::unordered_set<int>> bufferSets;
309308
};
310309

311310
/****************************************************
@@ -320,11 +319,11 @@ class VectorList : private std::vector<std::unique_ptr<Vector>> {
320319

321320
VectorList(VectorList &&) = default;
322321
VectorList &operator=(VectorList &&) = delete;
323-
322+
324323
// Implicit copying is not allowed
325324
// => Intentionally private and not implemented
326-
VectorList(const VectorList &)=delete;
327-
VectorList &operator=(const VectorList &)=delete;
325+
VectorList(const VectorList &) = delete;
326+
VectorList &operator=(const VectorList &) = delete;
328327

329328
[[nodiscard]] const Vector &vectorRefAt(unsigned int n) const; // vector at index 'n'
330329
Vector &vectorRefAt(unsigned int n);
@@ -337,9 +336,9 @@ class VectorList : private std::vector<std::unique_ptr<Vector>> {
337336

338337
void grow(); // append one vector place
339338

340-
void toString(CString &outString, double scale = 1.0) const;
339+
void toString(CString &outString, CDouble scale = 1.0) const;
341340

342-
// bool findSimilar(const Vector& vec, double threshold) const;
341+
// bool findSimilar(const Vector& vec, CDouble threshold) const;
343342
// similar - differs by a constant within a threshold
344343

345344
private:
@@ -358,14 +357,12 @@ inline const Vector &VectorList::lastVectorRef() const { return *this->at(this->
358357

359358
inline Vector &VectorList::lastVectorRef() { return *this->at(this->size() - 1); }
360359

361-
inline unsigned int VectorList::getSize() const {
362-
return static_cast<unsigned int>(this->size());
363-
}
360+
inline unsigned int VectorList::getSize() const { return static_cast<unsigned int>(this->size()); }
364361

365362
inline void VectorList::grow() {
366363
auto last = static_cast<unsigned int>(this->size());
367364
this->resize(last + 1);
368-
this->insert(this->begin()+last, std::make_unique<Vector>(oneVectorSize, MP_MINUSINFINITY));
365+
this->insert(this->begin() + last, std::make_unique<Vector>(oneVectorSize, MP_MINUSINFINITY));
369366
}
370367

371368
} // namespace MaxPlus

include/maxplus/algebra/mpsparsematrix.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
#include "mptype.h"
4545
#include <vector>
4646

47-
4847
class CString;
4948

5049
namespace MaxPlus {
@@ -88,9 +87,9 @@ class SparseVector {
8887
void putAll(unsigned int startRow, unsigned int endRow, MPTime value);
8988
void insertVector(unsigned int startRow, const SparseVector &v);
9089

91-
void toString(CString &outString, double scale = 1.0) const;
90+
void toString(CString &outString, CDouble scale = 1.0) const;
9291

93-
SparseVector& operator=(const SparseVector &);
92+
SparseVector &operator=(const SparseVector &);
9493

9594
[[nodiscard]] MPTime norm() const;
9695

@@ -137,8 +136,8 @@ class SparseVector {
137136
class SparseMatrix {
138137
public:
139138
explicit SparseMatrix(unsigned int rowSize = 0,
140-
unsigned int colSize = 0,
141-
MPTime value = MP_MINUSINFINITY);
139+
unsigned int colSize = 0,
140+
MPTime value = MP_MINUSINFINITY);
142141

143142
SparseMatrix(const SparseMatrix &);
144143

@@ -173,7 +172,7 @@ class SparseMatrix {
173172

174173
void insertMatrix(unsigned int startRow, unsigned int startColumn, const SparseMatrix &M);
175174

176-
SparseMatrix& operator=(const SparseMatrix &);
175+
SparseMatrix &operator=(const SparseMatrix &);
177176

178177
[[nodiscard]] MPTime norm() const;
179178

@@ -189,7 +188,7 @@ class SparseMatrix {
189188

190189
void compress();
191190

192-
void toString(CString &outString, double scale = 1.0) const;
191+
void toString(CString &outString, CDouble scale = 1.0) const;
193192

194193
MPTime mpEigenvalue();
195194

@@ -208,7 +207,7 @@ class SparseMatrix {
208207
bool isTransposed;
209208
// table contains column vectors (if isTransposed is false)
210209
// a pair (n, v) means that the vector v is repeated n times.
211-
vector<std::pair<unsigned int, SparseVector>> table;
210+
std::vector<std::pair<unsigned int, SparseVector>> table;
212211
std::pair<unsigned int, unsigned int> find(unsigned int col);
213212
void doTranspose();
214213
SparseMatrix combine(const SparseMatrix &vecB, MPTime f(MPTime a, MPTime b));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ CDouble maximumCycleMeanKarpDouble(const MCMgraph& g, MCMnode **criticalNode = n
6363
* actor a.
6464
*/
6565
v_uint
66-
mcmGetAdjacentActors(uint a, v_uint &nodeId, v_uint &actorId, vector<v_uint> &graph, uint nrNodes);
66+
mcmGetAdjacentActors(uint a, const v_uint &nodeId, const v_uint &actorId, const std::vector<v_uint> &graph, uint nrNodes);
6767

6868
} // namespace Graphs
6969
#endif

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class MCMedge {
6161
CDouble d;
6262
};
6363

64-
using MCMedges = list<std::shared_ptr<MCMedge>>;
64+
using MCMedges = std::list<std::shared_ptr<MCMedge>>;
6565

6666
class MCMnode {
6767
public:
@@ -77,7 +77,7 @@ struct MCMNodeLess {
7777
bool operator()(std::shared_ptr<MCMnode> const &lhs, std::shared_ptr<MCMnode> const &rhs) const { return lhs->id < rhs->id; };
7878
};
7979

80-
using MCMnodes = list<std::shared_ptr<MCMnode>>;
80+
using MCMnodes = std::list<std::shared_ptr<MCMnode>>;
8181

8282
class MCMgraph {
8383
public:
@@ -90,11 +90,15 @@ class MCMgraph {
9090
// Copy Constructor
9191
MCMgraph(const MCMgraph &g);
9292

93-
const MCMnodes &getNodes() const { return nodes; };
93+
MCMgraph(MCMgraph &&) = default;
94+
MCMgraph &operator=(MCMgraph &&) = delete;
95+
MCMgraph& operator=(const MCMgraph& other) = delete;
9496

95-
uint nrVisibleNodes() const {
97+
[[nodiscard]] const MCMnodes &getNodes() const { return nodes; };
98+
99+
[[nodiscard]] uint nrVisibleNodes() const {
96100
uint nrNodes = 0;
97-
for (auto &node : nodes) {
101+
for (const auto &node : nodes) {
98102
if (node->visible) {
99103
nrNodes++;
100104
}
@@ -110,7 +114,7 @@ class MCMgraph {
110114
return nullptr;
111115
};
112116

113-
const MCMedges &getEdges() const { return edges; };
117+
[[nodiscard]] const MCMedges &getEdges() const { return edges; };
114118

115119
std::shared_ptr<MCMedge> getEdge(CId id) {
116120
for (auto &edge : edges) {
@@ -180,15 +184,15 @@ class MCMgraph {
180184
}
181185

182186
// Add an edge to the MCMgraph.
183-
void addEdge(std::shared_ptr<MCMedge> e) {
187+
void addEdge(const std::shared_ptr<MCMedge>& e) {
184188
this->edges.push_back(e);
185189
e->src->out.push_back(e);
186190
e->dst->in.push_back(e);
187191
}
188192

189193
// Remove an edge from the MCMgraph.
190194
// Note: containers of edges are lists, so remove is expensive!
191-
void removeEdge(std::shared_ptr<MCMedge> e) {
195+
void removeEdge(const std::shared_ptr<MCMedge>& e) {
192196
this->edges.remove(e);
193197
e->src->out.remove(e);
194198
e->dst->in.remove(e);
@@ -224,7 +228,7 @@ class MCMgraph {
224228
MCMedges edges;
225229
};
226230

227-
using MCMgraphs = list<std::shared_ptr<MCMgraph>>;
231+
using MCMgraphs = std::list<std::shared_ptr<MCMgraph>>;
228232
using MCMgraphsIter = MCMgraphs::iterator;
229233

230234
/**

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace Graphs {
5959
* The function converts a weighted directed graph used in the MCM algorithms
6060
* to a sparse matrix input for Howard's algorithm.
6161
*/
62-
void convertMCMgraphToMatrix(MCMgraph *g, int *ij, double *A);
62+
void convertMCMgraphToMatrix(MCMgraph *g, int *ij, CDouble *A);
6363

6464
/**
6565
* Howard ()
@@ -77,11 +77,11 @@ void convertMCMgraphToMatrix(MCMgraph *g, int *ij, double *A);
7777
*
7878
*/
7979
void Howard(int *ij,
80-
double *A,
80+
CDouble *A,
8181
int nr_nodes,
8282
int nr_arcs,
83-
double *chi,
84-
double *v,
83+
CDouble *chi,
84+
CDouble *v,
8585
int *policy,
8686
int *nr_iterations,
8787
int *nr_components);

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@
4949
#define BASE_ANALYSIS_MCM_MCMYTO_H_INCLUDED
5050

5151
#include "base/analysis/mcm/mcmgraph.h"
52+
#include <cstdint>
5253
namespace Graphs {
5354

54-
typedef struct Node {
55+
using node = struct Node {
5556
// index into nodes array of graph structure is id - 1
56-
long id;
57+
std::int32_t id;
5758
struct Arc *first_arc_out;
5859
struct Arc *first_arc_in;
5960
struct Node *link; // for one way linked list
@@ -66,31 +67,31 @@ typedef struct Node {
6667
struct Node *right_sibling;
6768

6869
// next entries for maintenance of edge keys
69-
long level;
70-
double cost_t; // sum of costs on edges of tree path to node with
70+
std::int32_t level;
71+
CDouble cost_t; // sum of costs on edges of tree path to node with
7172
// respect to original edge costs
72-
double transit_time_t; // sum of transit time on edges of tree path
73+
CDouble transit_time_t; // sum of transit time on edges of tree path
7374
// to node
7475
struct Arc *v_key; // pointer to incoming arc with minimum key
75-
} node;
76+
};
7677

7778
using arc = struct Arc {
7879
node *tail;
7980
node *head;
8081
struct Arc *next_out; // in incidence list of tail node
8182
struct Arc *next_in; // in incidence list of head node
8283
bool in_tree;
83-
double cost;
84-
double transit_time;
85-
double key;
86-
long h_pos; // of arc in heap
84+
CDouble cost;
85+
CDouble transit_time;
86+
CDouble key;
87+
std::int32_t h_pos; // of arc in heap
8788
std::shared_ptr<MCMedge> mcmEdge; // MCMedge from which the arc was constructed in the conversion
8889
};
8990

9091
using graph = struct Graph {
91-
long n_nodes;
92+
std::int32_t n_nodes;
9293
node *nodes;
93-
long n_arcs;
94+
std::int32_t n_arcs;
9495
arc *arcs;
9596
node *vs; // additional node with zero cost outgoing edges
9697
};
@@ -159,13 +160,13 @@ minCycleRatioAndCriticalCycleYoungTarjanOrlin(const MCMgraph& mcmGraph, std::sha
159160
* getDelay ()
160161
* The function returns the delay associated with an edge.
161162
*/
162-
double getDelay(std::shared_ptr<MCMedge> e);
163+
CDouble getDelay(std::shared_ptr<MCMedge> e);
163164

164165
/**
165166
* getWeight ()
166167
* The function returns the weight associated with an edge.
167168
*/
168-
double getWeight(std::shared_ptr<MCMedge> e);
169+
CDouble getWeight(std::shared_ptr<MCMedge> e);
169170

170171
/**
171172
* convertMCMgraphToYTOgraph ()
@@ -175,8 +176,8 @@ double getWeight(std::shared_ptr<MCMedge> e);
175176
*/
176177
void convertMCMgraphToYTOgraph(const MCMgraph& g,
177178
graph *gr,
178-
double (*costFunction)(std::shared_ptr<MCMedge> e),
179-
double (*transit_timeFunction)(std::shared_ptr<MCMedge> e));
179+
CDouble (*costFunction)(std::shared_ptr<MCMedge> e),
180+
CDouble (*transit_timeFunction)(std::shared_ptr<MCMedge> e));
180181

181182
/**
182183
* mmcycle ()
@@ -186,7 +187,7 @@ void convertMCMgraphToYTOgraph(const MCMgraph& g,
186187
* edges, alternatively called "length" or "weight".
187188
*/
188189

189-
void mmcycle(graph *gr, double *lambda, arc **cycle, long *len);
190+
void mmcycle(graph *gr, CDouble *lambda, arc **cycle, std::int32_t *len);
190191

191192
} // namespace Graphs
192193

0 commit comments

Comments
 (0)