Skip to content

Commit a5322d8

Browse files
committed
cleanup and fix test
1 parent 05ce88c commit a5322d8

File tree

14 files changed

+146
-197
lines changed

14 files changed

+146
-197
lines changed

include/maxplus/algebra/mpmatrix.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ using namespace Graphs;
5858
*/
5959
class Vector {
6060
public:
61-
explicit Vector(unsigned int size = 0, MPTime value = MP_MINUSINFINITY);
61+
explicit Vector(unsigned int size = 0, MPTime value = MP_MINUS_INFINITY);
6262

6363
explicit Vector(std::vector<MPTime> *v);
6464

@@ -117,7 +117,7 @@ class Vector {
117117
/**
118118
* Get minimal finite element
119119
* returns the smallest among the finite elements in the vector or
120-
* MP_MINUSINFINITY if no finite elements exist
120+
* MP_MINUS_INFINITY if no finite elements exist
121121
* itsPosition returns the index of the (a) smallest finite element is set
122122
* to a pointer to unsigned int, otherwise set or defaults to NULL
123123
*/
@@ -335,7 +335,7 @@ inline unsigned int VectorList::getSize() const { return static_cast<unsigned in
335335
inline void VectorList::grow() {
336336
auto last = static_cast<unsigned int>(this->size());
337337
this->resize(static_cast<size_t>(last + 1));
338-
this->insert(this->begin() + last, std::make_unique<Vector>(oneVectorSize, MP_MINUSINFINITY));
338+
this->insert(this->begin() + last, std::make_unique<Vector>(oneVectorSize, MP_MINUS_INFINITY));
339339
}
340340

341341
} // namespace MaxPlus

include/maxplus/algebra/mpsparsematrix.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ using Ranges = std::vector<std::pair<unsigned int, unsigned int>>;
6464
*/
6565
class SparseVector {
6666
public:
67-
explicit SparseVector(unsigned int size = 0, MPTime value = MP_MINUSINFINITY);
67+
explicit SparseVector(unsigned int size = 0, MPTime value = MP_MINUS_INFINITY);
6868

6969
explicit SparseVector(const std::vector<MPTime> &v);
7070

@@ -137,7 +137,7 @@ class SparseMatrix {
137137
public:
138138
explicit SparseMatrix(unsigned int rowSize = 0,
139139
unsigned int colSize = 0,
140-
MPTime value = MP_MINUSINFINITY);
140+
MPTime value = MP_MINUS_INFINITY);
141141

142142
SparseMatrix(const SparseMatrix &);
143143

@@ -213,7 +213,7 @@ class SparseMatrix {
213213
SparseMatrix combine(const SparseMatrix &M, MPTime f(MPTime a, MPTime b));
214214
Matrix reduceRows();
215215
std::pair<Matrix, Sizes> reduceRowsAndColumns();
216-
static SparseMatrix expand(const Matrix &M, const Sizes &rszs, const Sizes &cszs);
216+
static SparseMatrix expand(const Matrix &M, const Sizes &rsz_s, const Sizes &csz_s);
217217
[[nodiscard]] Sizes sizes() const;
218218
};
219219

include/maxplus/algebra/mptype.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ inline CDouble MP_MIN(CDouble a, CDouble b) { return CDouble(MP_MIN(MPTime(a), M
116116
//==============================
117117

118118
// the quick and dirty way of representing -infinity
119-
const MPTime MP_MINUSINFINITY = MPTime(-1.0e+30);
120-
const MPTime MP_MINUSINFINITY_THR = MPTime(-0.5e+30);
119+
const MPTime MP_MINUS_INFINITY = MPTime(-1.0e+30);
120+
const MPTime MP_MINUS_INFINITY_THR = MPTime(-0.5e+30);
121121
const CDouble MPTIME_MIN_INF_VALPTHR = -0.5e+30;
122-
inline bool MP_ISMINUSINFINITY(CDouble a) { return a <= MPTIME_MIN_INF_VALPTHR; }
123-
inline bool MP_ISMINUSINFINITY(MPTime a) { return a <= MP_MINUSINFINITY_THR; }
122+
inline bool MP_IS_MINUS_INFINITY(CDouble a) { return a <= MPTIME_MIN_INF_VALPTHR; }
123+
inline bool MP_IS_MINUS_INFINITY(MPTime a) { return a <= MP_MINUS_INFINITY_THR; }
124124

125125
inline MPTime MP_PLUS(CDouble a, CDouble b) {
126-
return (MP_ISMINUSINFINITY(a) || MP_ISMINUSINFINITY(b))
127-
? MP_MINUSINFINITY
126+
return (MP_IS_MINUS_INFINITY(a) || MP_IS_MINUS_INFINITY(b))
127+
? MP_MINUS_INFINITY
128128
: MPTime(static_cast<CDouble>(a) + static_cast<CDouble>(b));
129129
}
130130

@@ -162,11 +162,11 @@ inline MPTime &MPTime::operator-() {
162162
inline MPTime operator*(MPTime a, MPTime b) {
163163
if (a.isMinusInfinity()) {
164164
assert(((CDouble)b) > 0.0);
165-
return MP_MINUSINFINITY;
165+
return MP_MINUS_INFINITY;
166166
}
167167
if (b.isMinusInfinity()) {
168168
assert(((CDouble)a) > 0.0);
169-
return MP_MINUSINFINITY;
169+
return MP_MINUS_INFINITY;
170170
}
171171
return MPTime(static_cast<CDouble>(a) * static_cast<CDouble>(b));
172172
}
@@ -198,7 +198,7 @@ inline bool MPTime::operator<=(MPTime a) const { return this->myVal <= a.myVal;
198198

199199
inline bool MPTime::operator>=(MPTime a) const { return this->myVal >= a.myVal; }
200200

201-
inline bool MPTime::isMinusInfinity() const { return MP_ISMINUSINFINITY(this->myVal); }
201+
inline bool MPTime::isMinusInfinity() const { return MP_IS_MINUS_INFINITY(this->myVal); }
202202

203203
inline MPTime MPTime::fabs() const { return MPTime(std::fabs(this->myVal)); }
204204

include/maxplus/base/fsm/iofsm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ using InputAction = CString;
1111
using OutputAction = CString;
1212
using IOAEdgeLabel = std::pair<InputAction, OutputAction>;
1313
using IOAState = ::FSM::Labeled::State<CId, IOAEdgeLabel>;
14+
using IOAStateRef = const IOAState*;
1415
using IOAEdge = ::FSM::Labeled::Edge<CId, IOAEdgeLabel>;
1516
using IOASetOfStates = ::FSM::Labeled::SetOfStates<CId, CString>;
1617
using IOASetOfStateRefs = ::FSM::Labeled::SetOfStateRefs<CId, CString>;

include/maxplus/game/policyiteration.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ template <typename SL, typename EL> class PolicyIteration {
118118
PolicyIterationResult policyIteration(RatioGame<SL, EL> &game,
119119
std::shared_ptr<StrategyVector<SL, EL>> initialStrategy,
120120
CDouble epsilon) {
121-
SetOfStates<SL, EL> &states = game.getStates();
121+
const SetOfStates<SL, EL> &states = game.getStates();
122122

123123
bool improvement = true;
124124

@@ -366,7 +366,7 @@ template <typename SL, typename EL> class PolicyIteration {
366366
CycleResult findCyclesInRestrictedGraph(RatioGame<SL, EL> &game,
367367
std::shared_ptr<StrategyVector<SL, EL>> currentStrategy,
368368
std::map<const State<SL, EL> *, CDouble> &stateIds) {
369-
SetOfStates<SL, EL> &states = game.getStates();
369+
const SetOfStates<SL, EL> &states = game.getStates();
370370
const State<SL, EL> *BOTTOM_VERTEX = nullptr;
371371

372372
std::shared_ptr<FSM::Abstract::SetOfStateRefs> selectedVertices =
@@ -455,7 +455,7 @@ template <typename SL, typename EL> class PolicyIteration {
455455
std::map<const State<SL, EL> *, CDouble> &r_prev,
456456
std::map<const State<SL, EL> *, CDouble> &dw2_prev,
457457
CDouble epsilon) {
458-
SetOfStates<SL, EL> &states = game.getStates();
458+
const SetOfStates<SL, EL> &states = game.getStates();
459459

460460
std::stack<const State<SL, EL> *> stack;
461461
// Initialize visited vector.

include/maxplus/graph/smpls.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class EdgeLabeledModeFSM : public ::FSM::Labeled::FiniteStateMachine<CId, CStrin
6060
public:
6161
// put the destructor deliberately into the cc sourc to ensure the class vtable is accessible
6262
// see: <https://stackoverflow.com/questions/3065154/undefined-reference-to-vtable>
63-
virtual ~EdgeLabeledModeFSM();
63+
~EdgeLabeledModeFSM() override;
6464
virtual void removeDanglingStates();
6565
};
6666

@@ -89,6 +89,7 @@ class DissectedModeMatrix {
8989

9090
using Mode = InputAction;
9191
using Event = OutputAction;
92+
using EventList = std::list<Event>;
9293
using EventOutcome = CString;
9394

9495
using ModeEventPair = std::pair<Mode,Event>;
@@ -153,18 +154,18 @@ class SMPLSwithEvents : public SMPLS {
153154
* recursive part of isConsistent
154155
*/
155156
void isConsistentUtil(const IOAState &s,
156-
std::list<Event> &eventList,
157+
EventList &eventList,
157158
const IOASetOfStates &finalStates,
158159
CString &errMsg,
159-
std::map<const IOAState *, std::list<Event> *> &visited);
160+
std::map<IOAStateRef,EventList> &visited);
160161

161162
void determinizeUtil(const IOAState &s,
162163
IOASetOfStateRefs& visited,
163164
const IOASetOfStates &finalStates,
164-
CString *errMsg,
165+
CString &errMsg,
165166
std::ofstream &outfile);
166167

167-
static bool compareEventLists(std::list<Event>& l1, std::list<Event>& l2);
168+
static bool compareEventLists(EventList& l1, EventList& l2);
168169

169170
void dissectModeMatrices();
170171
};

0 commit comments

Comments
 (0)