Skip to content

Commit 52a3dea

Browse files
committed
some fixes
1 parent 7ee0396 commit 52a3dea

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

include/maxplus/base/fsm/fsm.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ class FiniteStateMachine : public Abstract::FiniteStateMachine {
771771

772772
Abstract::SetOfStateRefs getStateRefs() {
773773
Abstract::SetOfStateRefs result;
774-
for (auto i : this->states) {
774+
for (const auto& i : this->states) {
775775
result.insert(&(*(i.second)));
776776
}
777777
return result;
@@ -801,8 +801,8 @@ class FiniteStateMachine : public Abstract::FiniteStateMachine {
801801
};
802802

803803
void setEdgeLabel(const EdgeRef<StateLabelType, EdgeLabelType> &e, const EdgeLabelType &l) {
804-
auto ee = std::dynamic_pointer_cast<Edge<StateLabelType, EdgeLabelType>>(
805-
(*this->edges.find(e->getId())).second);
804+
auto ee = dynamic_cast<Edge<StateLabelType, EdgeLabelType>*>(
805+
(*this->edges.find(e->getId())).second.get());
806806
ee->setLabel(l);
807807
}
808808

@@ -829,7 +829,7 @@ class FiniteStateMachine : public Abstract::FiniteStateMachine {
829829
// get all labels
830830
const SetOfStates<StateLabelType, EdgeLabelType> &allStates = this->getStates();
831831

832-
for (auto iter : allStates) {
832+
for (const auto& iter : allStates) {
833833
auto s = dynamic_cast<State<StateLabelType, EdgeLabelType> &>(*(iter.second));
834834
if (s.stateLabel == src) {
835835
const StateRef<StateLabelType, EdgeLabelType> srcState = this->getStateLabeled(src);
@@ -856,7 +856,7 @@ class FiniteStateMachine : public Abstract::FiniteStateMachine {
856856
std::unique_ptr<FiniteStateMachine<StateLabelType, EdgeLabelType>> determinizeEdgeLabels() {
857857
std::unique_ptr<FiniteStateMachine<StateLabelType, EdgeLabelType>> result =
858858
std::unique_ptr<FiniteStateMachine<StateLabelType, EdgeLabelType>>(
859-
this->newInstance());
859+
dynamic_cast<FiniteStateMachine<StateLabelType, EdgeLabelType>*>(this->newInstance().release()));
860860

861861
// maintain map of sets of states to the corresponding new states.
862862
std::map<const Abstract::SetOfStateRefs, const State<StateLabelType, EdgeLabelType> *>
@@ -876,7 +876,7 @@ class FiniteStateMachine : public Abstract::FiniteStateMachine {
876876
result->setInitialState(si);
877877

878878
// add initial state to list of unprocessed state sets
879-
unprocessed.push_back(initialStateSet);
879+
unprocessed.push_back(std::move(initialStateSet));
880880

881881
while (!unprocessed.empty()) {
882882
Abstract::SetOfStateRefs *Q = (unprocessed.begin())->get();
@@ -1003,8 +1003,7 @@ class FiniteStateMachine : public Abstract::FiniteStateMachine {
10031003
changed = true;
10041004
}
10051005
}
1006-
auto tempEqClasses = eqClasses;
1007-
eqClasses = newEqClasses;
1006+
eqClasses = std::move(newEqClasses);
10081007
} while (changed);
10091008
}
10101009

@@ -1054,12 +1053,12 @@ class FiniteStateMachine : public Abstract::FiniteStateMachine {
10541053
changed = true;
10551054
}
10561055
}
1057-
auto tempEqClasses = eqClasses;
1058-
eqClasses = newEqClasses;
1056+
eqClasses = std::move(newEqClasses);
10591057
} while (changed);
10601058

10611059
std::unique_ptr<FiniteStateMachine<StateLabelType, EdgeLabelType>> result =
1062-
this->newInstance();
1060+
std::unique_ptr<FiniteStateMachine<StateLabelType, EdgeLabelType>>(
1061+
dynamic_cast<FiniteStateMachine<StateLabelType, EdgeLabelType>*>(this->newInstance().release()));
10631062

10641063
// make a state for every equivalence class
10651064
std::map<Abstract::SetOfStateRefs *, StateRef<StateLabelType, EdgeLabelType>> newStateMap;
@@ -1069,7 +1068,7 @@ class FiniteStateMachine : public Abstract::FiniteStateMachine {
10691068
const State<StateLabelType, EdgeLabelType> *s =
10701069
dynamic_cast<const State<StateLabelType, EdgeLabelType> *>(*(cli->begin()));
10711070
auto ns = result->addState(s->stateLabel);
1072-
newStateMap[cli] = ns;
1071+
newStateMap[cli.get()] = ns;
10731072
sid++;
10741073
}
10751074

@@ -1081,7 +1080,7 @@ class FiniteStateMachine : public Abstract::FiniteStateMachine {
10811080
// for every outgoing edge
10821081
for (const auto *edi : es) {
10831082
auto ed = dynamic_cast<EdgeRef<StateLabelType, EdgeLabelType>>(edi);
1084-
result->addEdge(*(newStateMap[cli]),
1083+
result->addEdge(*(newStateMap[cli.get()]),
10851084
ed->getLabel(),
10861085
*(newStateMap[eqMap[ed->getDestination()]]));
10871086
}

include/maxplus/game/policyiteration.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ template <typename SL, typename EL> class PolicyIteration {
115115
std::make_unique<StrategyVector<SL, EL>>();
116116
initialStrategy->initializeRandomStrategy(game);
117117

118-
return policyIteration(game, initialStrategy, epsilon);
118+
return policyIteration(game, std::move(initialStrategy), epsilon);
119119
}
120120

121121
private:
@@ -250,7 +250,7 @@ template <typename SL, typename EL> class PolicyIteration {
250250
improvement = false;
251251
// Evaluate the current strategies of both players.
252252
StrategyEvaluation evalResult =
253-
evaluateStrategy(game, s_i_t, d_prev, r_prev, dw2_prev, stateIds, epsilon);
253+
evaluateStrategy(game, *s_i_t, d_prev, r_prev, dw2_prev, stateIds, epsilon);
254254

255255
// Update the current vectors.
256256
d_i_t = evalResult.d_i_t;
@@ -339,7 +339,7 @@ template <typename SL, typename EL> class PolicyIteration {
339339
// and the ratio of each cycle.
340340
DistanceResult dr = computeDistances(game,
341341
currentStrategy,
342-
cycleResult.states,
342+
*(cycleResult.states),
343343
r_i_t,
344344
distanceVector,
345345
ratioVector,
@@ -392,14 +392,14 @@ template <typename SL, typename EL> class PolicyIteration {
392392
const State<SL, EL> *u = v;
393393
while (visited[u] == BOTTOM_VERTEX) { // NOLINT(*pointer-arithmetic)
394394
visited[u] = v; // NOLINT(*pointer-arithmetic)
395-
u = currentStrategy->getSuccessor(u);
395+
u = currentStrategy.getSuccessor(u);
396396
}
397397
if (visited[u] == v) { // NOLINT(*pointer-arithmetic)
398398
const State<SL, EL> *v_s = u;
399-
const State<SL, EL> *x = currentStrategy->getSuccessor(u);
399+
const State<SL, EL> *x = currentStrategy.getSuccessor(u);
400400

401401
// Initialize both numerator and denominator.
402-
EdgeRef<SL, EL> e = game.getEdge(*u, *(currentStrategy->getSuccessor(u)));
402+
EdgeRef<SL, EL> e = game.getEdge(*u, *(currentStrategy.getSuccessor(u)));
403403
auto w1sum = static_cast<CDouble>(game.getWeight1(e));
404404
auto w2sum = static_cast<CDouble>(game.getWeight2(e));
405405

@@ -411,13 +411,13 @@ template <typename SL, typename EL> class PolicyIteration {
411411
v_s = x;
412412
}
413413
EdgeRef<SL, EL> x_succ =
414-
game.getEdge(*x, *(currentStrategy->getSuccessor(x)));
414+
game.getEdge(*x, *(currentStrategy.getSuccessor(x)));
415415
auto w1 = static_cast<CDouble>(game.getWeight1(x_succ));
416416
auto w2 = static_cast<CDouble>(game.getWeight2(x_succ));
417417

418418
w1sum += w1;
419419
w2sum += w2;
420-
x = currentStrategy->getSuccessor(x);
420+
x = currentStrategy.getSuccessor(x);
421421
}
422422
// Store the cycle ratio for the cycle containing v_s.
423423
r_i_t[v_s] = w1sum / w2sum; // NOLINT(*pointer-arithmetic)
@@ -427,7 +427,7 @@ template <typename SL, typename EL> class PolicyIteration {
427427
}
428428

429429
CycleResult result;
430-
result.states = selectedVertices;
430+
result.states = std::move(selectedVertices);
431431
result.valueMap = r_i_t;
432432

433433
return result;
@@ -492,7 +492,7 @@ template <typename SL, typename EL> class PolicyIteration {
492492
while (!visited[u]) { // NOLINT(*pointer-arithmetic)
493493
visited[u] = true; // NOLINT(*pointer-arithmetic)
494494
stack.push(u);
495-
u = currentStrategy->getSuccessor(u);
495+
u = currentStrategy.getSuccessor(u);
496496
}
497497
while (!stack.empty()) {
498498
const State<SL, EL> *x = stack.top();

src/base/analysis/mcm/mcmyto.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include <algorithm>
5252
#include <cassert>
5353
#include <cfloat>
54+
#include <cmath>
5455
#include <cstdint>
5556

5657
namespace MaxPlus::Graphs {

src/testbench/graph/mpautomatontest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void MPAutomatonTest::testMinimizeFSM() { // NOLINT(*to-static)
122122
fsa.setInitialState(*s0);
123123

124124
const auto fsaMin = std::unique_ptr<FSM::Labeled::FiniteStateMachine<int, int>>(
125-
fsa.minimizeEdgeLabels());
125+
dynamic_cast<FSM::Labeled::FiniteStateMachine<int, int>*>(fsa.minimizeEdgeLabels().release()));
126126

127127
std::cout << "Nr states: " << fsaMin->getStates().size() << "\n";
128128
std::cout << "Nr edges: " << fsaMin->getEdges().size() << "\n";

0 commit comments

Comments
 (0)