Skip to content

Commit 50612cf

Browse files
committed
fix state index
1 parent af92236 commit 50612cf

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

include/maxplus/base/fsm/fsm.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,13 +552,13 @@ class FiniteStateMachine : public Abstract::FiniteStateMachine {
552552

553553
State<StateLabelType, EdgeLabelType> *checkStateLabeled(const StateLabelType &s) {
554554
// try the index first
555-
if (this->states.stateIndex.find(s) != this->states.stateIndex.end()) {
556-
return this->states.stateIndex[s];
555+
if (this->states.withLabel(s) != nullptr) {
556+
return this->states.withLabel(s);
557557
}
558558
// for now just a linear search
559-
typename SetOfStates<StateLabelType, EdgeLabelType>::CIter i = this->states.begin();
559+
auto i = this->states.begin();
560560
while (i != this->states.end()) {
561-
auto &t = *(i.second);
561+
auto &t = dynamic_cast<State<StateLabelType, EdgeLabelType>&>(*((*i).second));
562562
if ((t.stateLabel) == s) {
563563
this->states.addToStateIndex(s, &t);
564564
return &t;

src/testbench/graph/mpautomatontest.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ void MPAutomatonTest::testCreateFSM() {
2929
std::cout << "Running test: CreateFSM" << std::endl;
3030

3131
MaxPlusAutomatonWithRewards mpa;
32-
// One FSM state, three tokens:
33-
CId fsm_s0 = 0;
3432

35-
MPARState *s1 = mpa.addState(makeMPAStateLabel(fsm_s0, 0));
36-
MPARState *s2 = mpa.addState(makeMPAStateLabel(fsm_s0, 1));
37-
MPARState *s3 = mpa.addState(makeMPAStateLabel(fsm_s0, 2));
33+
MPARState *s1 = mpa.addState(makeMPAStateLabel(0, 0));
34+
MPARState *s2 = mpa.addState(makeMPAStateLabel(0, 1));
35+
MPARState *s3 = mpa.addState(makeMPAStateLabel(0, 2));
3836

3937
mpa.addEdge(*s1, makeRewardEdgeLabel(MPTime(3.0), CString("A"), 1.0), *s2);
4038
mpa.addEdge(*s1, makeRewardEdgeLabel(MPTime(3.0), CString("A"), 1.0), *s3);
@@ -51,6 +49,9 @@ void MPAutomatonTest::testCreateFSM() {
5149

5250
mpa.setInitialState(*s1);
5351

52+
auto s = mpa.checkStateLabeled(makeMPAStateLabel(0, 1));
53+
ASSERT_THROW(s != nullptr);
54+
5455
ASSERT_EQUAL_NOPRINT(s1, &(mpa.getInitialState()));
5556
}
5657

0 commit comments

Comments
 (0)