Skip to content

Commit 7be5079

Browse files
committed
fix find edge
1 parent 50612cf commit 7be5079

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

include/maxplus/base/fsm/fsm.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -580,25 +580,23 @@ class FiniteStateMachine : public Abstract::FiniteStateMachine {
580580
// check if there exists a transition e = (q1,alpha,q2)
581581
const Edge<StateLabelType, EdgeLabelType> *
582582
findEdge(StateLabelType src, EdgeLabelType lbl, StateLabelType dst) {
583-
Edge<StateLabelType, EdgeLabelType> *found = nullptr;
584583

585584
// get all labels
586585
SetOfStates<StateLabelType, EdgeLabelType> &allStates = this->getStates();
587586

588587
for (auto iter : allStates) {
589-
auto s = *iter;
590-
if (s->stateLabel == src) {
588+
auto s = dynamic_cast<State<StateLabelType, EdgeLabelType>&>(*(iter.second));
589+
if (s.stateLabel == src) {
591590
State<StateLabelType, EdgeLabelType> &srcState = this->getStateLabeled(src);
592591

593592
const auto &outgoingEdges =
594593
static_cast<const Abstract::SetOfEdgeRefs &>(srcState.getOutgoingEdges());
595594

596595
for (const auto &it : outgoingEdges) {
597596
auto e = dynamic_cast<const Edge<StateLabelType, EdgeLabelType> *>(it);
598-
auto dstState = e->getDestination();
599-
if (e->label == lbl && dstState->getLabel() == dst) {
600-
found = e;
601-
return found;
597+
auto dstState = dynamic_cast<const State<StateLabelType, EdgeLabelType>&>(e->getDestination());
598+
if (e->getLabel() == lbl && dstState.getLabel() == dst) {
599+
return e;
602600
}
603601
}
604602
}

src/testbench/graph/mpautomatontest.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ void MPAutomatonTest::testCreateFSM() {
5252
auto s = mpa.checkStateLabeled(makeMPAStateLabel(0, 1));
5353
ASSERT_THROW(s != nullptr);
5454

55+
auto e = mpa.findEdge(makeMPAStateLabel(0, 0), makeRewardEdgeLabel(MPTime(3.0), CString("A"), 1.0), makeMPAStateLabel(0, 1));
56+
ASSERT_THROW(e != nullptr);
57+
5558
ASSERT_EQUAL_NOPRINT(s1, &(mpa.getInitialState()));
5659
}
5760

0 commit comments

Comments
 (0)