Skip to content

Commit c3ce63a

Browse files
committed
some efficiency improvements
1 parent 0f16a3f commit c3ce63a

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/graph/smpls.cc

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,16 @@ std::shared_ptr<MaxPlusAutomaton> SMPLS::convertToMaxPlusAutomaton() const {
131131
const auto &I = dynamic_cast<const ELSSetOfStateRefs &>(this->elsFSM.getInitialStates());
132132
const auto &F = dynamic_cast<const ELSSetOfStateRefs &>(this->elsFSM.getFinalStates());
133133
const auto &Q = dynamic_cast<const ELSSetOfStates &>(this->elsFSM.getStates());
134+
134135
for (const auto &q : Q) {
135136
auto &qq = *(q.second);
136137
const auto &e = qq.getOutgoingEdges();
137138
unsigned int nrTokens = 0;
138139
if (!e.empty()) {
139140
MPString label = (dynamic_cast<ELSEdgeRef>(*e.begin()))->getLabel();
140-
141-
for (const auto &smIt : this->mm) {
142-
if ((smIt).first == label) {
143-
nrTokens = (smIt).second->getCols();
144-
break;
145-
}
146-
}
141+
auto it = this->mm.find(MPString(label));
142+
assert(it != this->mm.end());
143+
nrTokens = it->second->getCols();
147144
} else {
148145
nrTokens = (*this->mm.begin()).second->getCols();
149146
}
@@ -191,6 +188,8 @@ std::shared_ptr<MaxPlusAutomaton> SMPLS::convertToMaxPlusAutomaton() const {
191188
auto &q1 = dynamic_cast<ELSState &>(*(q.second));
192189
CId q1Id = q1.getLabel();
193190

191+
std::map<int, MPAStateRef> q1StateMap;
192+
194193
// for every outgoing edge of the state
195194
const auto &t = dynamic_cast<const ELSSetOfEdgeRefs &>(q1.getOutgoingEdges());
196195
for (const auto *e : t) {
@@ -203,15 +202,20 @@ std::shared_ptr<MaxPlusAutomaton> SMPLS::convertToMaxPlusAutomaton() const {
203202

204203
// for every entry in the mode matrix of that edge
205204
for (size_t row = 0; row < r; row++) {
205+
MPAStateRef dst = mpa->getStateLabeled(
206+
makeMPAStateLabel(q2Id, static_cast<unsigned int>(row)));
206207
for (size_t col = 0; col < c; col++) {
207208
const MPDelay d =
208209
Ms->get(static_cast<unsigned int>(row), static_cast<unsigned int>(col));
209-
210210
if (!MP_IS_MINUS_INFINITY(d)) {
211-
MPAStateRef src = mpa->getStateLabeled(
212-
makeMPAStateLabel(q1Id, static_cast<unsigned int>(col)));
213-
MPAStateRef dst = mpa->getStateLabeled(
214-
makeMPAStateLabel(q2Id, static_cast<unsigned int>(row)));
211+
MPAStateRef src = nullptr;
212+
if (q1StateMap.find(col) != q1StateMap.end()) {
213+
src = q1StateMap.at(col);
214+
} else {
215+
src = mpa->getStateLabeled(
216+
makeMPAStateLabel(q1Id, static_cast<unsigned int>(col)));
217+
q1StateMap[col] = src;
218+
}
215219
MPAEdgeLabel el = makeMPAEdgeLabel(d, sc);
216220
el.mode = MPString(tr->getLabel());
217221
mpa->addEdge(*src, el, *dst);
@@ -276,8 +280,7 @@ bool SMPLSwithEvents::isConsistent() {
276280
std::map<IOAStateRef, EventList> visited;
277281
MPString errMsg = "";
278282
for (const auto &i : I) {
279-
isConsistentUtil(
280-
*dynamic_cast<IOAStateRef>(i), eventList, finalStates, errMsg, visited);
283+
isConsistentUtil(*dynamic_cast<IOAStateRef>(i), eventList, finalStates, errMsg, visited);
281284
}
282285

283286
if (!errMsg.empty()) {

0 commit comments

Comments
 (0)