From cd27039af9cff4a0251649e35304e612e618f38c Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Mon, 27 Oct 2014 07:59:01 +0100
Subject: [PATCH] transform pop symbols in correct order

---
 alib2algo/src/automaton/transform/PDAToRHPDA.cpp | 8 ++++----
 alib2algo/src/automaton/transform/RHPDAToPDA.cpp | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/alib2algo/src/automaton/transform/PDAToRHPDA.cpp b/alib2algo/src/automaton/transform/PDAToRHPDA.cpp
index e29078e5d0..099e32a14f 100644
--- a/alib2algo/src/automaton/transform/PDAToRHPDA.cpp
+++ b/alib2algo/src/automaton/transform/PDAToRHPDA.cpp
@@ -58,7 +58,7 @@ automaton::RealTimeHeightDeterministicDPDA PDAToRHPDA::convert( const automaton:
 			int popPushSymbols = std::get<2>(transition.first).size() + to.second.size();
 
 			automaton::State lastUS = automaton::createUniqueState(automaton::State(us + std::to_string(i)), res.getStates());
-			for(const alphabet::Symbol& pop : std::get<2>(transition.first)) {
+			std::for_each (std::get<2>(transition.first).rbegin(), std::get<2>(transition.first).rend(), [&](const alphabet::Symbol& pop) {
 				automaton::State fromState = (popPushIndex == 0) ? std::get<0>(transition.first) : lastUS;
 				if(popPushIndex != 0) lastUS = automaton::createUniqueState(automaton::State(us + std::to_string(++i)), res.getStates());
 				automaton::State toState = (popPushIndex == popPushSymbols - 1) ? to.first : lastUS;
@@ -71,7 +71,7 @@ automaton::RealTimeHeightDeterministicDPDA PDAToRHPDA::convert( const automaton:
 				else
 					res.addReturnTransition(fromState, pop, toState);
 				popPushIndex++;
-			}
+			});
 			for(const alphabet::Symbol& push : to.second) {
 				automaton::State fromState = (popPushIndex == 0) ? std::get<0>(transition.first) : lastUS;
 				if(popPushIndex != 0) lastUS = automaton::createUniqueState(automaton::State(us + std::to_string(++i)), res.getStates());
@@ -125,7 +125,7 @@ automaton::RealTimeHeightDeterministicNPDA PDAToRHPDA::convert( const automaton:
 				int popPushSymbols = std::get<2>(transition.first).size() + to.second.size();
 
 				automaton::State lastUS = automaton::createUniqueState(automaton::State(us + std::to_string(i)), res.getStates());
-				for(const alphabet::Symbol& pop : std::get<2>(transition.first)) {
+				std::for_each (std::get<2>(transition.first).rbegin(), std::get<2>(transition.first).rend(), [&](const alphabet::Symbol& pop) {
 					automaton::State fromState = (popPushIndex == 0) ? std::get<0>(transition.first) : lastUS;
 					if(popPushIndex != 0) lastUS = automaton::createUniqueState(automaton::State(us + std::to_string(++i)), res.getStates());
 					automaton::State toState = (popPushIndex == popPushSymbols - 1) ? to.first : lastUS;
@@ -138,7 +138,7 @@ automaton::RealTimeHeightDeterministicNPDA PDAToRHPDA::convert( const automaton:
 					else
 						res.addReturnTransition(fromState, pop, toState);
 					popPushIndex++;
-				}
+				});
 				for(const alphabet::Symbol& push : to.second) {
 					automaton::State fromState = (popPushIndex == 0) ? std::get<0>(transition.first) : lastUS;
 					if(popPushIndex != 0) lastUS = automaton::createUniqueState(automaton::State(us + std::to_string(++i)), res.getStates());
diff --git a/alib2algo/src/automaton/transform/RHPDAToPDA.cpp b/alib2algo/src/automaton/transform/RHPDAToPDA.cpp
index cb28fba1be..c6da5d9977 100644
--- a/alib2algo/src/automaton/transform/RHPDAToPDA.cpp
+++ b/alib2algo/src/automaton/transform/RHPDAToPDA.cpp
@@ -113,7 +113,7 @@ automaton::DPDA RHPDAToPDA::convert( const automaton::RealTimeHeightDeterministi
 			while(!epsilonTransitions[toState].empty()) {
 				const auto& epsilonT = *epsilonTransitions[toState].begin();
 
-				pops.insert(pops.end(), std::get<0>(epsilonT).begin(), std::get<0>(epsilonT).end());
+				pops.insert(pops.begin(), std::get<0>(epsilonT).begin(), std::get<0>(epsilonT).end());
 				pushes.insert(pushes.end(), std::get<2>(epsilonT).begin(), std::get<2>(epsilonT).end());
 
 				toState = std::get<1>(epsilonT);
@@ -231,7 +231,7 @@ automaton::NPDA RHPDAToPDA::convert( const automaton::RealTimeHeightDeterministi
 			while(!epsilonTransitions[toState].empty()) {
 				const auto& epsilonT = *epsilonTransitions[toState].begin();
 
-				pops.insert(pops.end(), std::get<0>(epsilonT).begin(), std::get<0>(epsilonT).end());
+				pops.insert(pops.begin(), std::get<0>(epsilonT).begin(), std::get<0>(epsilonT).end());
 				pushes.insert(pushes.end(), std::get<2>(epsilonT).begin(), std::get<2>(epsilonT).end());
 
 				toState = std::get<1>(epsilonT);
-- 
GitLab