From 4de06f320b94978447930dae7398beb8bb2ab4e9 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Sat, 27 Sep 2014 16:26:55 +0200
Subject: [PATCH] use ObjectLabel to simplify vpa determinisation

---
 .../src/determinize/vpa/VPADeterminizer.cpp   | 24 +++++++++++--------
 .../src/determinize/vpa/VPADeterminizer.h     |  4 ++--
 alib2data/src/label/LabelToStringComposer.cpp |  6 +++--
 3 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/alib2algo/src/determinize/vpa/VPADeterminizer.cpp b/alib2algo/src/determinize/vpa/VPADeterminizer.cpp
index 4a2d195876..b2f859f316 100644
--- a/alib2algo/src/determinize/vpa/VPADeterminizer.cpp
+++ b/alib2algo/src/determinize/vpa/VPADeterminizer.cpp
@@ -6,6 +6,8 @@
 #include "label/Label.h"
 #include "label/LabelSetLabel.h"
 #include "label/LabelPairLabel.h"
+#include "label/ObjectLabel.h"
+#include "object/Object.h"
 #include <std/set.hpp>
 #include <iostream>
 
@@ -27,20 +29,24 @@ std::set<std::pair<label::Label, label::Label>> VPADeterminizer::unpackFromDVPAS
 	return res;
 }
 
-label::Label VPADeterminizer::packToDVPAStackSymbolLabel(std::pair<std::set<std::pair<label::Label, label::Label>>, label::Label>&& data) {
+label::Label VPADeterminizer::packToDVPAStackSymbolLabel(std::pair<std::set<std::pair<label::Label, label::Label>>, alphabet::Symbol>&& data) {
 	std::set<label::Label> res;
 	for(auto&& subData : std::move(data.first)) {
 		res.insert(label::Label(label::LabelPairLabel(std::move(subData))));
 	}
-	return label::Label(label::LabelPairLabel(std::make_pair(label::Label(label::LabelSetLabel(std::move(res))), std::move(data.second))));
+	return label::Label(label::LabelPairLabel(std::make_pair(label::Label(label::LabelSetLabel(std::move(res))), label::Label(label::ObjectLabel(alib::Object(std::move(data.second.getData())))))));
 }
 
-std::pair<std::set<std::pair<label::Label, label::Label>>, label::Label> VPADeterminizer::unpackFromDVPAStackSymbolLabel(const label::Label& data) {
+std::pair<std::set<std::pair<label::Label, label::Label>>, alphabet::Symbol> VPADeterminizer::unpackFromDVPAStackSymbolLabel(const label::Label& data) {
 	std::set<std::pair<label::Label, label::Label>> res;
-	for (const auto& subData : static_cast<const label::LabelSetLabel&>(static_cast<const label::LabelPairLabel&>(data.getData()).getData().first.getData()).getData()) {
+	const label::Label& labelPairFirst = static_cast<const label::LabelPairLabel&>(data.getData()).getData().first;
+	for (const auto& subData : static_cast<const label::LabelSetLabel&>(labelPairFirst.getData()).getData()) {
 		res.insert(static_cast<const label::LabelPairLabel&>(subData.getData()).getData());
 	}
-	return std::make_pair(res, static_cast<const label::LabelPairLabel&>(data.getData()).getData().second);
+
+	const label::Label& labelPairSecond = static_cast<const label::LabelPairLabel&>(data.getData()).getData().second;
+	const alib::Object& object = static_cast<const label::ObjectLabel&>(labelPairSecond.getData()).getData();
+	return std::make_pair(res, alphabet::Symbol(static_cast<const alphabet::SymbolBase&>(object.getData())));
 }
 
 void addRetTransition(const automaton::State& from, const alphabet::Symbol& input, const alphabet::Symbol& dvpdaSymbol, const automaton::State& to, automaton::VisiblyPushdownNPDA& deterministic) {
@@ -76,13 +82,13 @@ void retInitial(const automaton::State& state, const alphabet::Symbol& pdaSymbol
 
 void ret(const automaton::State& state, const alphabet::Symbol& pdaSymbol, const alphabet::Symbol& input, const automaton::VisiblyPushdownNPDA& nondeterministic, automaton::VisiblyPushdownNPDA& deterministic) {
 	std::set<std::pair<label::Label, label::Label>> S = VPADeterminizer::unpackFromDVPAStateLabel(state.getName());
-	std::pair<std::set<std::pair<label::Label, label::Label>>, label::Label> pdaSymbolUnpack = VPADeterminizer::unpackFromDVPAStackSymbolLabel(static_cast<const alphabet::LabeledSymbol&>(pdaSymbol.getData()).getLabel());
+	std::pair<std::set<std::pair<label::Label, label::Label>>, alphabet::Symbol> pdaSymbolUnpack = VPADeterminizer::unpackFromDVPAStackSymbolLabel(static_cast<const alphabet::LabeledSymbol&>(pdaSymbol.getData()).getLabel());
 	const std::set<std::pair<label::Label, label::Label>>& S1 = pdaSymbolUnpack.first;
 
 	std::set<std::pair<label::Label, label::Label>> update;
 
 	for(const auto& transition : nondeterministic.getCallTransitions()) {
-		if(pdaSymbolUnpack.second != static_cast<const alphabet::LabeledSymbol&>(std::get<1>(transition.first).getData()).getLabel()) continue;
+		if(pdaSymbolUnpack.second != std::get<1>(transition.first)) continue;
 
 		const label::Label& q = std::get<0>(transition.first).getName();
 		for(const auto& to : transition.second) {
@@ -167,9 +173,7 @@ void call(const automaton::State& state, const alphabet::Symbol& input, const au
 		}
 	}
 
-	label::Label inputLabel = static_cast<const alphabet::LabeledSymbol&>(input.getData()).getLabel();
-
-	addCallTransition(state, input, automaton::State(VPADeterminizer::packToDVPAStateLabel(createIdentity(std::move(R1)))), alphabet::Symbol(alphabet::LabeledSymbol(VPADeterminizer::packToDVPAStackSymbolLabel(std::make_pair(std::move(S), std::move(inputLabel))))), deterministic);
+	addCallTransition(state, input, automaton::State(VPADeterminizer::packToDVPAStateLabel(createIdentity(std::move(R1)))), alphabet::Symbol(alphabet::LabeledSymbol(VPADeterminizer::packToDVPAStackSymbolLabel(std::make_pair(std::move(S), input)))), deterministic);
 }
 
 void addLocalTransition(const automaton::State& from, const alphabet::Symbol& input, const automaton::State& to, automaton::VisiblyPushdownNPDA& deterministic) {
diff --git a/alib2algo/src/determinize/vpa/VPADeterminizer.h b/alib2algo/src/determinize/vpa/VPADeterminizer.h
index 5b40763060..0910496ee8 100644
--- a/alib2algo/src/determinize/vpa/VPADeterminizer.h
+++ b/alib2algo/src/determinize/vpa/VPADeterminizer.h
@@ -14,9 +14,9 @@ public:
 
 	static std::set<std::pair<label::Label, label::Label>> unpackFromDVPAStateLabel(const label::Label& data);
 
-	static label::Label packToDVPAStackSymbolLabel(std::pair<std::set<std::pair<label::Label, label::Label>>, label::Label>&& data);
+	static label::Label packToDVPAStackSymbolLabel(std::pair<std::set<std::pair<label::Label, label::Label>>, alphabet::Symbol>&& data);
 
-	static std::pair<std::set<std::pair<label::Label, label::Label>>, label::Label> unpackFromDVPAStackSymbolLabel(const label::Label& data);
+	static std::pair<std::set<std::pair<label::Label, label::Label>>, alphabet::Symbol> unpackFromDVPAStackSymbolLabel(const label::Label& data);
 	/**
 	 * Runs determinization algorithm on nondeterministic vpa given in constructor.
 	 *
diff --git a/alib2data/src/label/LabelToStringComposer.cpp b/alib2data/src/label/LabelToStringComposer.cpp
index 97f8f7df93..404424d7cd 100644
--- a/alib2data/src/label/LabelToStringComposer.cpp
+++ b/alib2data/src/label/LabelToStringComposer.cpp
@@ -10,6 +10,7 @@
 #include "IntegerLabel.h"
 #include "StringLabel.h"
 #include "CharacterLabel.h"
+#include "ObjectLabel.h"
 #include "LabelSetLabel.h"
 #include "LabelPairLabel.h"
 
@@ -45,8 +46,9 @@ void LabelToStringComposer::Visit(void* userData, const IntegerLabel& label) {
 	out << label.getData();
 }
 
-void LabelToStringComposer::Visit(void*, const ObjectLabel&) {
-	throw exception::AlibException("Unsupported type in conversion to string (ObjectLabel)");
+void LabelToStringComposer::Visit(void* userData, const ObjectLabel& label) {
+	std::stringstream &out = *((std::stringstream*) userData);
+	out << (std::string) label;
 }
 
 void LabelToStringComposer::Visit(void* userData, const LabelSetLabel& label) {
-- 
GitLab