Skip to content

Commit 91605e1

Browse files
author
Marc Geilen
committed
cleaned up
1 parent c826a7c commit 91605e1

File tree

24 files changed

+425
-853
lines changed

24 files changed

+425
-853
lines changed

include/maxplus/algebra/mptype.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,21 +224,21 @@ inline CString timeToString(MPTime val) {
224224
// so that we can expose the unwanted "impure" infinities here.
225225
//
226226
if (static_cast<CDouble>(val)==MPTIME_MIN_INF_VAL) {
227-
return {"-mp_inf"};
227+
return CString("-mp_inf");
228228
}
229-
return {static_cast<CDouble>(val)};
229+
return CString(static_cast<CDouble>(val));
230230
}
231231
inline CString timeToMatlabString(MPTime val) {
232232
if (val.isMinusInfinity()) {
233-
return {"-Inf"};
233+
return CString("-Inf");
234234
}
235-
return {static_cast<CDouble>(val)};
235+
return CString(static_cast<CDouble>(val));
236236
}
237237
inline CString timeToLaTeXString(MPTime val) {
238238
if (val.isMinusInfinity()) {
239-
return {"-\\infty{}"};
239+
return CString("-\\infty{}");
240240
}
241-
return {static_cast<CDouble>(val)};
241+
return CString(static_cast<CDouble>(val));
242242
}
243243

244244
} // namespace MaxPlus

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ namespace Graphs {
5454
* The function computes the maximum cycle mean of an MCMgraph using Karp's
5555
* algorithm.
5656
*/
57-
CDouble maximumCycleMeanKarp(const MCMgraph& g);
58-
CDouble maximumCycleMeanKarpDouble(const MCMgraph& g, const MCMnode **criticalNode = nullptr);
57+
CDouble maximumCycleMeanKarp(MCMgraph& g);
58+
CDouble maximumCycleMeanKarpDouble(MCMgraph& g, const MCMnode **criticalNode = nullptr);
5959

6060
/**
6161
* mcmGetAdjacentActors ()

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

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,16 @@ class MCMnode;
5252
class MCMedge {
5353
public:
5454
// Constructor
55-
MCMedge(CId eId, MCMnode &src, MCMnode &dst, bool eVisible);
55+
MCMedge(CId eId, MCMnode &src, MCMnode &dst, CDouble w, CDouble d, bool eVisible);
5656
CId id;
5757
bool visible;
5858
MCMnode *src;
5959
MCMnode *dst;
6060
CDouble w;
6161
CDouble d;
62+
bool operator==(const MCMedge& e) const {
63+
return this->id == e.id;
64+
}
6265
};
6366

6467
using MCMedges = std::list<MCMedge>;
@@ -72,14 +75,17 @@ class MCMnode {
7275
bool visible;
7376
MCMedgeRefs in;
7477
MCMedgeRefs out;
78+
bool operator==(const MCMnode& n) const {
79+
return this->id == n.id;
80+
}
7581
};
7682

77-
// struct MCMNodeLess {
78-
// bool operator()(std::shared_ptr<MCMnode> const &lhs,
79-
// std::shared_ptr<MCMnode> const &rhs) const {
80-
// return lhs->id < rhs->id;
81-
// };
82-
// };
83+
struct MCMNodeLess {
84+
bool operator()(const MCMnode* const &lhs,
85+
const MCMnode* const &rhs) const {
86+
return lhs->id < rhs->id;
87+
};
88+
};
8389

8490
using MCMnodes = std::list<MCMnode>;
8591
using MCMnodeRefs = std::list<MCMnode *>;
@@ -99,7 +105,9 @@ class MCMgraph {
99105
MCMgraph &operator=(MCMgraph &&) = delete;
100106
MCMgraph &operator=(const MCMgraph &other) = delete;
101107

102-
[[nodiscard]] const MCMnodes &getNodes() const { return nodes; };
108+
[[nodiscard]] MCMnodes &getNodes() { return nodes; };
109+
[[nodiscard]] MCMnodeRefs getNodeRefs();
110+
[[nodiscard]] MCMedgeRefs getEdgeRefs();
103111

104112
[[nodiscard]] uint nrVisibleNodes() const {
105113
uint nrNodes = 0;
@@ -119,7 +127,7 @@ class MCMgraph {
119127
return nullptr;
120128
};
121129

122-
[[nodiscard]] const MCMedges &getEdges() const { return edges; };
130+
[[nodiscard]] MCMedges &getEdges() { return edges; };
123131

124132
MCMedge *getEdge(CId id) {
125133
for (auto &edge : edges) {
@@ -169,17 +177,12 @@ class MCMgraph {
169177
while (!n.out.empty()) {
170178
this->removeEdge(**(n.out.begin()));
171179
}
172-
173180
this->nodes.remove(n);
174181
}
175182

176183
// Add an edge to the MCMgraph.
177-
MCMedge *addEdge(CId id, MCMnode &src, MCMnode &dst, CDouble w, CDouble d) {
178-
MCMedge& e = this->edges.emplace_back(id, true);
179-
e.src = &src;
180-
e.dst = &dst;
181-
e.w = w;
182-
e.d = d;
184+
MCMedge *addEdge(CId id, MCMnode &src, MCMnode &dst, CDouble w, CDouble d, bool visible = true) {
185+
MCMedge& e = this->edges.emplace_back(id, src, dst, w, d, visible);
183186
src.out.push_back(&e);
184187
dst.in.push_back(&e);
185188
return &e;
@@ -202,12 +205,12 @@ class MCMgraph {
202205
// Note this algorithm does currently not distinguish visible and invisible edges!
203206
std::shared_ptr<MCMgraph> pruneEdges();
204207

205-
[[nodiscard]] CDouble calculateMaximumCycleMeanKarp() const;
208+
[[nodiscard]] CDouble calculateMaximumCycleMeanKarp();
206209
[[nodiscard]] CDouble
207-
calculateMaximumCycleMeanKarpDouble(const MCMnode **criticalNode = nullptr) const;
210+
calculateMaximumCycleMeanKarpDouble(const MCMnode **criticalNode = nullptr);
208211

209212
[[nodiscard]] CDouble calculateMaximumCycleRatioAndCriticalCycleYoungTarjanOrlin(
210-
std::shared_ptr<std::vector<MCMedge*>> *cycle = nullptr) const;
213+
std::shared_ptr<std::vector<const MCMedge*>> *cycle = nullptr);
211214

212215
[[nodiscard]] std::shared_ptr<MCMgraph> normalize(CDouble mu) const;
213216
[[nodiscard]] std::shared_ptr<MCMgraph> normalize(const std::map<CId, CDouble> &mu) const;
@@ -238,7 +241,7 @@ using MCMgraphsIter = MCMgraphs::iterator;
238241
* MCM algorithms work also on this graph (which reduces the execution time
239242
* needed in some of the conversion algorithms).
240243
*/
241-
void stronglyConnectedMCMgraph(const MCMgraph &g,
244+
void stronglyConnectedMCMgraph(MCMgraph &g,
242245
MCMgraphs &components,
243246
bool includeComponentsWithoutEdges = false);
244247

@@ -253,7 +256,7 @@ void relabelMCMgraph(std::shared_ptr<MCMgraph> g);
253256
* addLongestDelayEdgesToMCMgraph ()
254257
* The function adds additional edges to the graph which express the
255258
* longest path between two nodes crossing one edge with a delay. Edges
256-
* with no delay are removed and edges with more then one delay element
259+
* with no delay are removed and edges with more than one delay element
257260
* are converted into a sequence of edges with one delay element.
258261
*/
259262
void addLongestDelayEdgesToMCMgraph(std::shared_ptr<MCMgraph> g);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ CDouble maxCycleMeanYoungTarjanOrlin(const MCMgraph& mcmGraph);
117117
* in due time.
118118
*/
119119
CDouble
120-
maxCycleMeanAndCriticalCycleYoungTarjanOrlin(const MCMgraph& mcmGraph, std::shared_ptr<std::vector<const MCMedge*>> *cycle);
120+
maxCycleMeanAndCriticalCycleYoungTarjanOrlin(MCMgraph& mcmGraph, std::shared_ptr<std::vector<const MCMedge*>> *cycle);
121121

122122
/**
123123
* maxCycleRatioYoungTarjanOrlin ()
@@ -137,14 +137,14 @@ CDouble maxCycleRatioYoungTarjanOrlin(const MCMgraph& mcmGraph);
137137
* in due time.
138138
*/
139139
CDouble
140-
maxCycleRatioAndCriticalCycleYoungTarjanOrlin(const MCMgraph& mcmGraph, std::shared_ptr<std::vector<const MCMedge*>> *cycle);
140+
maxCycleRatioAndCriticalCycleYoungTarjanOrlin(MCMgraph& mcmGraph, std::shared_ptr<std::vector<const MCMedge*>> *cycle);
141141

142142
/**
143143
* minCycleRatioYoungTarjanOrlin ()
144144
* The function computes the minimum cycle ratio of edge weight over delay of
145145
* an MCMgraph using Young-Tarjan-Orlin's algorithm.
146146
*/
147-
CDouble minCycleRatioYoungTarjanOrlin(const MCMgraph& mcmGraph);
147+
CDouble minCycleRatioYoungTarjanOrlin(MCMgraph& mcmGraph);
148148

149149
/**
150150
* minCycleRatioAndCriticalCycleYoungTarjanOrlin ()
@@ -157,7 +157,7 @@ CDouble minCycleRatioYoungTarjanOrlin(const MCMgraph& mcmGraph);
157157
* in due time.
158158
*/
159159
CDouble
160-
minCycleRatioAndCriticalCycleYoungTarjanOrlin(const MCMgraph& mcmGraph, std::shared_ptr<std::vector<const MCMedge*>> *cycle);
160+
minCycleRatioAndCriticalCycleYoungTarjanOrlin(MCMgraph& mcmGraph, std::shared_ptr<std::vector<const MCMedge*>> *cycle);
161161

162162
/**
163163
* getDelay ()

include/maxplus/base/base.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,4 @@
5151
/* Math */
5252
#include "math/cmath.h"
5353

54-
/* Lookups (i.e. hash tables) */
55-
#include "lookup/clookup.h"
56-
5754
#endif

include/maxplus/base/basic_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
#ifndef BASE_BASIC_TYPES_H_INCLUDED
4343
#define BASE_BASIC_TYPES_H_INCLUDED
4444

45+
#include <cassert>
4546
#include <cfloat>
46-
#include <assert.h>
4747

4848

4949
/* STL functionality */

include/maxplus/base/fraction/fraction.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ class CFraction {
6666

6767
explicit CFraction(CString &f) {
6868
if (f.find('/') == CString::npos) {
69-
num = f;
69+
num = std::int64_t(f);
7070
den = 1;
7171
} else {
72-
num = CString(f.substr(0, f.find('/')));
73-
den = CString(f.substr(f.find('/') + 1));
72+
num = std::int64_t(CString(f.substr(0, f.find('/'))));
73+
den = std::int64_t(CString(f.substr(f.find('/') + 1)));
7474
}
7575
val = static_cast<CDouble>(num) / static_cast<CDouble>(den);
7676
};

0 commit comments

Comments
 (0)