Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
TikZConverter.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <ext/ostream>
9#include <ext/sstream>
10
11#include <ext/typeinfo>
12#include <ext/utility>
13
14#include <alib/set>
15#include <alib/list>
16#include <alib/vector>
17#include <alib/map>
18
20#include <string/String.h>
21
22#include <automaton/FSM/NFA.h>
25#include <automaton/FSM/DFA.h>
28#include <automaton/TA/NFTA.h>
29#include <automaton/TA/DFTA.h>
30#include <automaton/PDA/NPDA.h>
38#include <automaton/PDA/DPDA.h>
41#include <grid/GridClasses.hpp>
44
46
50
51namespace convert {
52
54 static constexpr const size_t CAPTION_LENGTH_LIMIT = 100;
55
56 template < class SymbolType, class StateType >
57 static void transitions(const automaton::DFA < SymbolType, StateType > & fsm, const ext::map < StateType, int > & states, ext::ostream & out);
58
59 template < class SymbolType, class StateType >
60 static void transitions(const automaton::NFA < SymbolType, StateType > & fsm, const ext::map < StateType, int > & states, ext::ostream & out);
61
62 template < class SymbolType, class StateType >
63 static void transitions(const automaton::MultiInitialStateNFA < SymbolType, StateType > & fsm, const ext::map < StateType, int > & states, ext::ostream & out);
64
65 template < class SymbolType, class StateType >
66 static void transitions(const automaton::EpsilonNFA < SymbolType, StateType > & fsm, const ext::map < StateType, int > & states, ext::ostream & out);
67
68 template < class SymbolType, class StateType >
69 static void transitions(const automaton::ExtendedNFA < SymbolType, StateType > & fsm, const ext::map < StateType, int > & states, ext::ostream & out);
70
71 template < class SymbolType, class StateType >
72 static void transitions(const automaton::CompactNFA < SymbolType, StateType > & fsm, const ext::map < StateType, int > & states, ext::ostream & out);
73
74 template < class SymbolType, class StateType >
75 static void transitions(const automaton::NFTA < SymbolType, StateType > & fta, const ext::map < StateType, int > & states, ext::ostream & out);
76
77 template < class SymbolType, class StateType >
78 static void transitions(const automaton::DFTA < SymbolType, StateType > & fta, const ext::map < StateType, int > & states, ext::ostream & out);
79
80 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
82
83 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
85
86 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
88
89 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
91
92 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
94
95 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
97
98 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
100
101 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
103
104 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
106
107 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
109
110 template < class SymbolType, class StateType >
111 static void transitions(const automaton::OneTapeDTM < SymbolType, StateType > & tm, const ext::map < StateType, int > & states, ext::ostream & out);
112
113 template<typename TGrid>
114 static void grid(ext::ostream &out, const TGrid &a);
115
116public:
117 template < class SymbolType, class StateType >
119
120 template < class SymbolType, class StateType >
122
123 template < class SymbolType, class StateType >
125
126 template < class SymbolType, class StateType >
128
129 template < class SymbolType, class StateType >
131
132 template < class SymbolType, class StateType >
134
135 template < class SymbolType, class StateType >
137
138 template < class SymbolType, class StateType >
140
141 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
143
144 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
146
147 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
149
150 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
152
153 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
155
156 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
158
159 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
161
162 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
164
165 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
167
168 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
170
171 template < class SymbolType, class StateType >
173
174 template<typename TCoordinate, typename TEdge>
176 return grid(out, a);
177 }
178
179 template<typename TCoordinate, typename TEdge>
181 return grid(out, a);
182 }
183
184 template<typename TCoordinate, typename TEdge>
186 return grid(out, a);
187 }
188
189 template<typename TCoordinate, typename TEdge>
191 return grid(out, a);
192 }
193
194 template < class T >
195 static std::string convert ( const T & automaton ) {
197 convert ( ss, automaton );
198 return ss.str ( );
199 }
200
201 template < class SymbolType >
203 public:
206 static void visit ( const rte::FormalRTEIteration < SymbolType > & node, ext::ostream & out );
209 static void visit ( const rte::FormalRTEEmpty < SymbolType > & node, ext::ostream & out );
210 };
211 template < class SymbolType >
212 static void convert ( ext::ostream& out, const rte::FormalRTE < SymbolType > & rte );
213};
214
215template<class SymbolType, class StateType>
217 out << "\\begin{tikzpicture}\n";
218 int cnt = 1;
219
220 // Map states to indices
222
223 for ( const StateType & state : a.getStates ( ) )
224 states.insert ( std::make_pair ( state, cnt++ ) );
225
226 // Print states
227 for ( const auto & state : states ) {
228 std::string mods;
229
230 if ( a.getFinalStates ( ).count ( state.first ) )
231 mods += ",accepting";
232
233 if ( a.getInitialState ( ) == state.first )
234 mods += ",initial";
235
236 out << "\\node[state" + mods + "] (" << state.second << ") {" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "}\n";
237 }
238
239 transitions ( a, states, out );
240 out << "\\end{tikzpicture}";
241}
242
243template<class SymbolType, class StateType>
245 out << "\\begin{tikzpicture}\n";
246 int cnt = 1;
247
248 // Map states to indices
250
251 for ( const StateType & state : a.getStates ( ) )
252 states.insert ( std::make_pair ( state, cnt++ ) );
253
254 // Print states
255 for ( const auto & state : states ) {
256 std::string mods;
257
258 if ( a.getFinalStates ( ).count ( state.first ) )
259 mods += ",accepting";
260
261 if ( a.getInitialStates ( ).count ( state.first ) )
262 mods += ",initial";
263
264 out << "\\node[state" + mods + "] (" << state.second << ") {" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "}\n";
265 }
266
267 transitions ( a, states, out );
268 out << "\\end{tikzpicture}";
269}
270
271template<class SymbolType, class StateType>
273 out << "\\begin{tikzpicture}\n";
274 int cnt = 1;
275
276 // Map states to indices
278
279 for ( const StateType & state : a.getStates ( ) )
280 states.insert ( std::make_pair ( state, cnt++ ) );
281
282 // Print states
283 for ( const auto & state : states ) {
284 std::string mods;
285
286 if ( a.getFinalStates ( ).count ( state.first ) )
287 mods += ",accepting";
288
289 if ( a.getInitialState ( ) == state.first )
290 mods += ",initial";
291
292 out << "\\node[state" + mods + "] (" << state.second << ") {" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "}\n";
293 }
294
295 transitions ( a, states, out );
296 out << "\\end{tikzpicture}";
297}
298
299template<class SymbolType, class StateType>
301 out << "\\begin{tikzpicture}\n";
302 int cnt = 1;
303
304 // Map states to indices
306
307 for ( const StateType & state : a.getStates ( ) )
308 states.insert ( std::make_pair ( state, cnt++ ) );
309
310 // Print states
311 for ( const auto & state : states ) {
312 std::string mods;
313
314 if ( a.getFinalStates ( ).count ( state.first ) )
315 mods += ",accepting";
316
317 if ( a.getInitialState ( ) == state.first )
318 mods += ",initial";
319
320 out << "\\node[state" + mods + "] (" << state.second << ") {" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "}\n";
321 }
322
323 transitions ( a, states, out );
324 out << "\\end{tikzpicture}";
325}
326
327template<class SymbolType, class StateType>
329 out << "\\begin{tikzpicture}\n";
330 int cnt = 1;
331
332 // Map states to indices
334
335 for ( const StateType & state : a.getStates ( ) )
336 states.insert ( std::make_pair ( state, cnt++ ) );
337
338 // Print states
339 for ( const auto & state : states ) {
340 std::string mods;
341
342 if ( a.getFinalStates ( ).count ( state.first ) )
343 mods += ",accepting";
344
345 if ( a.getInitialState ( ) == state.first )
346 mods += ",initial";
347
348 out << "\\node[state" + mods + "] (" << state.second << ") {" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "}\n";
349 }
350
351 transitions ( a, states, out );
352 out << "\\end{tikzpicture}";
353}
354
355template<class SymbolType, class StateType>
357 out << "\\begin{tikzpicture}\n";
358 int cnt = 1;
359
360 // Map states to indices
362
363 for ( const StateType & state : a.getStates ( ) )
364 states.insert ( std::make_pair ( state, cnt++ ) );
365
366 // Print states
367 for ( const auto & state : states ) {
368 std::string mods;
369
370 if ( a.getFinalStates ( ).count ( state.first ) )
371 mods += ",accepting";
372
373 if ( a.getInitialState ( ) == state.first )
374 mods += ",initial";
375
376 out << "\\node[state" + mods + "] (" << state.second << ") {" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "}\n";
377 }
378
379 transitions ( a, states, out );
380 out << "\\end{tikzpicture}";
381}
382
383template<class SymbolType, class StateType>
385 out << "\\begin{tikzpicture}\n";
386 int cnt = 1;
387
388 // Map states to indices
390
391 for ( const StateType & state : a.getStates ( ) )
392 states.insert ( std::make_pair ( state, cnt++ ) );
393
394 // Print states
395 for ( const auto & state : states ) {
396 std::string mods;
397
398 if ( a.getFinalStates ( ).count ( state.first ) )
399 mods += ",accepting";
400
401 out << "\\node[state" + mods + "] (" << state.second << ") {" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "}\n";
402 }
403
404 transitions ( a, states, out );
405 out << "\\end{tikzpicture}";
406}
407
408template<class SymbolType, class StateType>
410 out << "\\begin{tikzpicture}\n";
411 int cnt = 1;
412
413 // Map states to indices
415
416 for ( const StateType & state : a.getStates ( ) )
417 states.insert ( std::make_pair ( state, cnt++ ) );
418
419 // Print states
420 for ( const auto & state : states ) {
421 std::string mods;
422
423 if ( a.getFinalStates ( ).count ( state.first ) )
424 mods += ",accepting";
425
426 out << "\\node[state" + mods + "] (" << state.second << ") {" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "}\n";
427 }
428
429 transitions ( a, states, out );
430 out << "\\end{tikzpicture}";
431}
432
433template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
435 out << "\\begin{tikzpicture}\n";
436 int cnt = 1;
437
438 // Map states to indices
440
441 for ( const StateType & state : a.getStates ( ) )
442 states.insert ( std::make_pair ( state, cnt++ ) );
443
444 // Print states
445 for ( const auto & state : states ) {
446 std::string mods;
447
448 if ( a.getFinalStates ( ).count ( state.first ) )
449 mods += ",accepting";
450
451 if ( a.getInitialState ( ) == state.first )
452 mods += ",initial";
453
454 out << "\\node[state" + mods + "] (" << state.second << ") {" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "}\n";
455 }
456
457 transitions ( a, states, out );
458 out << "\\end{tikzpicture}";
459}
460
461template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
463 out << "\\begin{tikzpicture}\n";
464 int cnt = 1;
465
466 // Map states to indices
468
469 for ( const StateType & state : a.getStates ( ) )
470 states.insert ( std::make_pair ( state, cnt++ ) );
471
472 // Print states
473 for ( const auto & state : states ) {
474 std::string mods;
475
476 if ( a.getFinalStates ( ).count ( state.first ) )
477 mods += ",accepting";
478
479 if ( a.getInitialState ( ) == state.first )
480 mods += ",initial";
481
482 out << "\\node[state" + mods + "] (" << state.second << ") {" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "}\n";
483 }
484
485 transitions ( a, states, out );
486 out << "\\end{tikzpicture}";
487}
488
489template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
491 out << "\\begin{tikzpicture}\n";
492 int cnt = 1;
493
494 // Map states to indices
496
497 for ( const StateType & state : a.getStates ( ) )
498 states.insert ( std::make_pair ( state, cnt++ ) );
499
500 // Print states
501 for ( const auto & state : states ) {
502 std::string mods;
503
504 if ( a.getFinalStates ( ).count ( state.first ) )
505 mods += ",accepting";
506
507 if ( a.getInitialState ( ) == state.first )
508 mods += ",initial";
509
510 out << "\\node[state" + mods + "] (" << state.second << ") {" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "}\n";
511 }
512
513 transitions ( a, states, out );
514 out << "\\end{tikzpicture}";
515}
516
517template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
519 out << "\\begin{tikzpicture}\n";
520 int cnt = 1;
521
522 // Map states to indices
524
525 for ( const StateType & state : a.getStates ( ) )
526 states.insert ( std::make_pair ( state, cnt++ ) );
527
528 // Print states
529 for ( const auto & state : states ) {
530 std::string mods;
531
532 if ( a.getFinalStates ( ).count ( state.first ) )
533 mods += ",accepting";
534
535 if ( a.getInitialState ( ) == state.first )
536 mods += ",initial";
537
538 out << "\\node[state" + mods + "] (" << state.second << ") {" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "}\n";
539 }
540
541 transitions ( a, states, out );
542 out << "\\end{tikzpicture}";
543}
544
545template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
547 out << "\\begin{tikzpicture}\n";
548 int cnt = 1;
549
550 // Map states to indices
552
553 for ( const StateType & state : a.getStates ( ) )
554 states.insert ( std::make_pair ( state, cnt++ ) );
555
556 // Print states
557 for ( const auto & state : states ) {
558 std::string mods;
559
560 if ( a.getFinalStates ( ).count ( state.first ) )
561 mods += ",accepting";
562
563 if ( a.getInitialState ( ) == state.first )
564 mods += ",initial";
565
566 out << "\\node[state" + mods + "] (" << state.second << ") {" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "}\n";
567 }
568
569 transitions ( a, states, out );
570 out << "\\end{tikzpicture}";
571}
572
573template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
575 out << "\\begin{tikzpicture}\n";
576 int cnt = 1;
577
578 // Map states to indices
580
581 for ( const StateType & state : a.getStates ( ) )
582 states.insert ( std::make_pair ( state, cnt++ ) );
583
584 // Print states
585 for ( const auto & state : states ) {
586 std::string mods;
587
588 if ( a.getFinalStates ( ).count ( state.first ) )
589 mods += ",accepting";
590
591 if ( a.getInitialStates ( ).count ( state.first ) )
592 mods += ",initial";
593
594 out << "\\node[state" + mods + "] (" << state.second << ") {" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "}\n";
595 }
596
597 transitions ( a, states, out );
598 out << "\\end{tikzpicture}";
599}
600
601template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
603 out << "\\begin{tikzpicture}\n";
604 int cnt = 1;
605
606 // Map states to indices
608
609 for ( const StateType & state : a.getStates ( ) )
610 states.insert ( std::make_pair ( state, cnt++ ) );
611
612 // Print states
613 for ( const auto & state : states ) {
614 std::string mods;
615
616 if ( a.getFinalStates ( ).count ( state.first ) )
617 mods += ",accepting";
618
619 if ( a.getInitialState ( ) == state.first )
620 mods += ",initial";
621
622 out << "\\node[state" + mods + "] (" << state.second << ") {" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "}\n";
623 }
624
625 transitions ( a, states, out );
626 out << "\\end{tikzpicture}";
627}
628
629template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
631 out << "\\begin{tikzpicture}\n";
632 int cnt = 1;
633
634 // Map states to indices
636
637 for ( const StateType & state : a.getStates ( ) )
638 states.insert ( std::make_pair ( state, cnt++ ) );
639
640 // Print states
641 for ( const auto & state : states ) {
642 std::string mods;
643
644 if ( a.getFinalStates ( ).count ( state.first ) )
645 mods += ",accepting";
646
647 if ( a.getInitialStates ( ).count ( state.first ) )
648 mods += ",initial";
649
650 out << "\\node[state" + mods + "] (" << state.second << ") {" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "}\n";
651 }
652
653 transitions ( a, states, out );
654 out << "\\end{tikzpicture}";
655}
656
657template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
659 out << "\\begin{tikzpicture}\n";
660 int cnt = 1;
661
662 // Map states to indices
664
665 for ( const StateType & state : a.getStates ( ) )
666 states.insert ( std::make_pair ( state, cnt++ ) );
667
668 // Print states
669 for ( const auto & state : states ) {
670 std::string mods;
671
672 if ( a.getFinalStates ( ).count ( state.first ) )
673 mods += ",accepting";
674
675 if ( a.getInitialState ( ) == state.first )
676 mods += ",initial";
677
678 out << "\\node[state" + mods + "] (" << state.second << ") {" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "}\n";
679 }
680
681 transitions ( a, states, out );
682 out << "\\end{tikzpicture}";
683}
684
685template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
687 out << "\\begin{tikzpicture}\n";
688 int cnt = 1;
689
690 // Map states to indices
692
693 for ( const StateType & state : a.getStates ( ) )
694 states.insert ( std::make_pair ( state, cnt++ ) );
695
696 // Print states
697 for ( const auto & state : states ) {
698 std::string mods;
699
700 if ( a.getFinalStates ( ).count ( state.first ) )
701 mods += ",accepting";
702
703 if ( a.getInitialState ( ) == state.first )
704 mods += ",initial";
705
706 out << "\\node[state" + mods + "] (" << state.second << ") {" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "}\n";
707 }
708
709 transitions ( a, states, out );
710 out << "\\end{tikzpicture}";
711}
712
713template<class SymbolType, class StateType>
715 out << "\\begin{tikzpicture}\n";
716 int cnt = 1;
717
718 // Map states to indices
720
721 for ( const StateType & state : a.getStates ( ) )
722 states.insert ( std::make_pair ( state, cnt++ ) );
723
724 // Print states
725 for ( const auto & state : states ) {
726 std::string mods;
727
728 if ( a.getFinalStates ( ).count ( state.first ) )
729 mods += ",accepting";
730
731 if ( a.getInitialState ( ) == state.first )
732 mods += ",initial";
733
734 out << "\\node[state" + mods + "] (" << state.second << ") {" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "}\n";
735 }
736
737 transitions ( a, states, out );
738 out << "\\end{tikzpicture}";
739}
740
741template<class SymbolType, class StateType>
742void TikZConverter::transitions ( const automaton::EpsilonNFA < SymbolType, StateType > & fsm, const ext::map < StateType, int > & states, ext::ostream & out ) {
743 ext::map < std::pair < int, int >, std::string > transitions;
744
745 // put transitions from automaton to "transitions"
746 for ( const auto & transition : fsm.getTransitions ( ) ) {
747 std::string symbol;
748
749 if ( transition.first.second.is_epsilon ( ) )
750 symbol = "&epsilon;";
751 else
752 symbol = replace ( factory::StringDataFactory::toString ( std::get < 1 > ( transition.first ).getSymbol ( ) ), "\"", "\\\"" );
753
754 std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second )->second );
755 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
756
757 if ( mapit == transitions.end ( ) ) {
758 transitions.insert ( std::make_pair ( key, symbol ) );
759 } else {
760 mapit->second += ",";
761
762 size_t pos = mapit->second.find_last_of ( "\n" );
763
764 if ( pos == std::string::npos ) pos = 0;
765
766 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
767 mapit->second += "\n";
768 else
769 mapit->second += " ";
770
771 mapit->second += symbol;
772 }
773 }
774
775 out << "\\path[->]";
776
777 // print the map
778 for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) {
779 replaceInplace ( transition.second, "\n", "\\n" );
780
781 out << "(" << transition.first.first << ") edge [left] node [align=center] ";
782 out << "{$" << transition.second << "$}";
783 out << "(" << transition.first.second << ")\n";
784 }
785}
786
787template<class SymbolType, class StateType>
788void TikZConverter::transitions ( const automaton::MultiInitialStateNFA < SymbolType, StateType > & fsm, const ext::map < StateType, int > & states, ext::ostream & out ) {
789 ext::map < std::pair < int, int >, std::string > transitions;
790
791 // put transitions from automaton to "transitions"
792 for ( const auto & transition : fsm.getTransitions ( ) ) {
793 std::string symbol = replace ( factory::StringDataFactory::toString ( transition.first.second ), "\"", "\\\"" );
794
795 std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second )->second );
796 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
797
798 if ( mapit == transitions.end ( ) ) {
799 transitions.insert ( std::make_pair ( key, symbol ) );
800 } else {
801 mapit->second += ",";
802
803 size_t pos = mapit->second.find_last_of ( "\n" );
804
805 if ( pos == std::string::npos ) pos = 0;
806
807 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
808 mapit->second += "\n";
809 else
810 mapit->second += " ";
811
812 mapit->second += symbol;
813 }
814 }
815
816 out << "\\path[->]";
817
818 // print the map
819 for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) {
820 replaceInplace ( transition.second, "\n", "\\n" );
821
822 out << "(" << transition.first.first << ") edge [left] node [align=center] ";
823 out << "{$" << transition.second << "$}";
824 out << "(" << transition.first.second << ")\n";
825 }
826}
827
828template<class SymbolType, class StateType>
829void TikZConverter::transitions ( const automaton::NFA < SymbolType, StateType > & fsm, const ext::map < StateType, int > & states, ext::ostream & out ) {
830 ext::map < std::pair < int, int >, std::string > transitions;
831
832 // put transitions from automaton to "transitions"
833 for ( const auto & transition : fsm.getTransitions ( ) ) {
834 std::string symbol = replace ( factory::StringDataFactory::toString ( transition.first.second ), "\"", "\\\"" );
835
836 std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second )->second );
837 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
838
839 if ( mapit == transitions.end ( ) ) {
840 transitions.insert ( std::make_pair ( key, symbol ) );
841 } else {
842 mapit->second += ",";
843
844 size_t pos = mapit->second.find_last_of ( "\n" );
845
846 if ( pos == std::string::npos ) pos = 0;
847
848 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
849 mapit->second += "\n";
850 else
851 mapit->second += " ";
852
853 mapit->second += symbol;
854 }
855 }
856
857 out << "\\path[->]";
858
859 // print the map
860 for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) {
861 replaceInplace ( transition.second, "\n", "\\n" );
862
863 out << "(" << transition.first.first << ") edge [left] node [align=center] ";
864 out << "{$" << transition.second << "$}";
865 out << "(" << transition.first.second << ")\n";
866 }
867}
868
869template<class SymbolType, class StateType>
870void TikZConverter::transitions ( const automaton::DFA < SymbolType, StateType > & fsm, const ext::map < StateType, int > & states, ext::ostream & out ) {
871 ext::map < std::pair < int, int >, std::string > transitions;
872
873 // put transitions from automaton to "transitions"
874 for ( const auto & transition : fsm.getTransitions ( ) ) {
875 std::string symbol = replace ( factory::StringDataFactory::toString ( transition.first.second ), "\"", "\\\"" );
876
877 std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second )->second );
878 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
879
880 if ( mapit == transitions.end ( ) ) {
881 transitions.insert ( std::make_pair ( key, symbol ) );
882 } else {
883 mapit->second += ",";
884
885 size_t pos = mapit->second.find_last_of ( "\n" );
886
887 if ( pos == std::string::npos ) pos = 0;
888
889 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
890 mapit->second += "\n";
891 else
892 mapit->second += " ";
893
894 mapit->second += symbol;
895 }
896 }
897
898 out << "\\path[->]";
899
900 // print the map
901 for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) {
902 replaceInplace ( transition.second, "\n", "\\n" );
903
904 out << "(" << transition.first.first << ") edge [left] node [align=center] ";
905 out << "{$" << transition.second << "$}";
906 out << "(" << transition.first.second << ")\n";
907 }
908}
909
910template<class SymbolType, class StateType>
911void TikZConverter::transitions ( const automaton::ExtendedNFA < SymbolType, StateType > & fsm, const ext::map < StateType, int > & states, ext::ostream & out ) {
912 ext::map < std::pair < int, int >, std::string > transitions;
913
914 // put transitions from automaton to "transitions"
915 for ( const auto & transition : fsm.getTransitions ( ) ) {
916 std::string symbol = replace ( factory::StringDataFactory::toString ( transition.first.second ), "\"", "\\\"" );
917
918 std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second )->second );
919 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
920
921 if ( mapit == transitions.end ( ) ) {
922 transitions.insert ( std::make_pair ( key, symbol ) );
923 } else {
924 mapit->second += ",";
925
926 size_t pos = mapit->second.find_last_of ( "\n" );
927
928 if ( pos == std::string::npos ) pos = 0;
929
930 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
931 mapit->second += "\n";
932 else
933 mapit->second += " ";
934
935 mapit->second += symbol;
936 }
937 }
938
939 out << "\\path[->]";
940
941 // print the map
942 for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) {
943 replaceInplace ( transition.second, "\n", "\\n" );
944
945 out << "(" << transition.first.first << ") edge [left] node [align=center] ";
946 out << "{$" << transition.second << "$}";
947 out << "(" << transition.first.second << ")\n";
948 }
949}
950
951template<class SymbolType, class StateType>
952void TikZConverter::transitions ( const automaton::CompactNFA < SymbolType, StateType > & fsm, const ext::map < StateType, int > & states, ext::ostream & out ) {
953 ext::map < std::pair < int, int >, std::string > transitions;
954
955 // put transitions from automaton to "transitions"
956 for ( const auto & transition : fsm.getTransitions ( ) ) {
957 std::string symbol = replace ( factory::StringDataFactory::toString ( string::stringFrom ( transition.first.second ) ), "\"", "\\\"" );
958
959 std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second )->second );
960 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
961
962 if ( mapit == transitions.end ( ) ) {
963 transitions.insert ( std::make_pair ( key, symbol ) );
964 } else {
965 mapit->second += ",";
966
967 size_t pos = mapit->second.find_last_of ( "\n" );
968
969 if ( pos == std::string::npos ) pos = 0;
970
971 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
972 mapit->second += "\n";
973 else
974 mapit->second += " ";
975
976 mapit->second += symbol;
977 }
978 }
979
980 out << "\\path[->]";
981
982 // print the map
983 for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) {
984 replaceInplace ( transition.second, "\n", "\\n" );
985
986 out << "(" << transition.first.first << ") edge [left] node [align=center] ";
987 out << "{$" << transition.second << "$}";
988 out << "(" << transition.first.second << ")\n";
989 }
990}
991
992template<class SymbolType, class StateType>
993void TikZConverter::transitions ( const automaton::NFTA < SymbolType, StateType > & fta, const ext::map < StateType, int > & states, ext::ostream & out ) {
994 ext::map < std::pair < int, ext::vector < int > >, std::string > transitions;
995
996 // put transitions from automaton to "transitions"
997 for ( const auto & transition : fta.getTransitions ( ) ) {
998 std::string symbol = replace ( factory::StringDataFactory::toString ( transition.first.first.getSymbol ( ) ), "\"", "\\\"" );
999 symbol += ext::to_string ( transition.first.first.getRank ( ) );
1000
1001 std::pair < int, ext::vector < int > > key ( states.find ( transition.second )->second, { } );
1002
1003 for ( const StateType & state : transition.first.second )
1004 key.second.push_back ( states.find ( state )->second );
1005
1006 ext::map < std::pair < int, ext::vector < int > >, std::string >::iterator mapit = transitions.find ( key );
1007
1008 if ( mapit == transitions.end ( ) ) {
1009 transitions.insert ( std::make_pair ( key, symbol ) );
1010 } else {
1011 mapit->second += ",";
1012
1013 size_t pos = mapit->second.find_last_of ( "\n" );
1014
1015 if ( pos == std::string::npos ) pos = 0;
1016
1017 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1018 mapit->second += "\n";
1019 else
1020 mapit->second += " ";
1021
1022 mapit->second += symbol;
1023 }
1024 }
1025
1026 // Print auxilary dots
1027 for ( unsigned i = 1; i < transitions.size ( ); i++ )
1028 out << "\\node[draw=none,fill=none] (" << states.size ( ) + i << ") {}\n";
1029
1030 out << "\\path[->]";
1031
1032 // print the map
1033 unsigned i = states.size ( ) + 1;
1034
1035 for ( std::pair < const std::pair < int, ext::vector < int > >, std::string > & transition : transitions ) {
1036 replaceInplace ( transition.second, "\n", "\\n" );
1037
1038 out << "(" << i << ") edge [left] node [align=center] ";
1039 out << "{$" << transition.second << "$}";
1040 out << "(" << transition.first.first << ")\n";
1041
1042 unsigned j = 0;
1043
1044 for ( int from : transition.first.second ) {
1045 out << "(" << from << ") edge [left] node [align=center] ";
1046 out << "{$" << j << "$}";
1047 out << "(" << i << ")\n";
1048
1049 j++;
1050 }
1051
1052 i++;
1053 }
1054}
1055
1056template<class SymbolType, class StateType>
1057void TikZConverter::transitions ( const automaton::DFTA < SymbolType, StateType > & fta, const ext::map < StateType, int > & states, ext::ostream & out ) {
1058 ext::map < std::pair < int, ext::vector < int > >, std::string > transitions;
1059
1060 // put transitions from automaton to "transitions"
1061 for ( const auto & transition : fta.getTransitions ( ) ) {
1062 std::string symbol = replace ( factory::StringDataFactory::toString ( transition.first.first.getSymbol ( ) ), "\"", "\\\"" );
1063 symbol += ext::to_string ( transition.first.first.getRank ( ) );
1064
1065 std::pair < int, ext::vector < int > > key ( states.find ( transition.second )->second, { } );
1066
1067 for ( const StateType & state : transition.first.second )
1068 key.second.push_back ( states.find ( state )->second );
1069
1070 ext::map < std::pair < int, ext::vector < int > >, std::string >::iterator mapit = transitions.find ( key );
1071
1072 if ( mapit == transitions.end ( ) ) {
1073 transitions.insert ( std::make_pair ( key, symbol ) );
1074 } else {
1075 mapit->second += ",";
1076
1077 size_t pos = mapit->second.find_last_of ( "\n" );
1078
1079 if ( pos == std::string::npos ) pos = 0;
1080
1081 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1082 mapit->second += "\n";
1083 else
1084 mapit->second += " ";
1085
1086 mapit->second += symbol;
1087 }
1088 }
1089
1090 // Print auxilary dots
1091 for ( unsigned i = 1; i < transitions.size ( ); i++ )
1092 out << "\\node[draw=none,fill=none] (" << states.size ( ) + i << ") {}\n";
1093
1094 out << "\\path[->]";
1095
1096 // print the map
1097 unsigned i = states.size ( ) + 1;
1098
1099 for ( std::pair < const std::pair < int, ext::vector < int > >, std::string > & transition : transitions ) {
1100 replaceInplace ( transition.second, "\n", "\\n" );
1101
1102 out << "(" << i << ") edge [left] node [align=center] ";
1103 out << "{$" << transition.second << "$}";
1104 out << "(" << transition.first.first << ")\n";
1105
1106 unsigned j = 0;
1107
1108 for ( int from : transition.first.second ) {
1109 out << "(" << from << ") edge [left] node [align=center] ";
1110 out << "{$" << j << "$}";
1111 out << "(" << i << ")\n";
1112
1113 j++;
1114 }
1115
1116 i++;
1117 }
1118}
1119
1120template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
1121void TikZConverter::transitions ( const automaton::DPDA < InputSymbolType, PushdownStoreSymbolType, StateType > & pda, const ext::map < StateType, int > & states, ext::ostream & out ) {
1122 ext::map < std::pair < int, int >, std::string > transitions;
1123
1124 for ( const auto & transition : pda.getTransitions ( ) ) {
1125 std::string symbol;
1126
1127 // input symbol
1128 if ( std::get < 1 > ( transition.first ).is_epsilon ( ) )
1129 symbol = "&epsilon;";
1130 else
1131 symbol = replace ( factory::StringDataFactory::toString ( std::get < 1 > ( transition.first ).getSymbol ( ) ), "\"", "\\\"" );
1132
1133 symbol += " |";
1134
1135 // Pop part
1136 if ( std::get < 2 > ( transition.first ).empty ( ) )
1137 symbol += " &epsilon;";
1138 else
1139 for ( const PushdownStoreSymbolType & symb : std::get < 2 > ( transition.first ) )
1140 symbol += " " + replace ( factory::StringDataFactory::toString ( symb ), "\"", "\\\"" );
1141
1142 symbol += " ->";
1143
1144 // Push part
1145 if ( transition.second.second.empty ( ) )
1146 symbol += " &epsilon;";
1147 else
1148 for ( const PushdownStoreSymbolType & symb : transition.second.second )
1149 symbol += " " + replace ( factory::StringDataFactory::toString ( symb ), "\"", "\\\"" );
1150
1151 // Insert into map
1152 std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( transition.second.first )->second );
1153 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
1154
1155 if ( mapit == transitions.end ( ) ) {
1156 transitions.insert ( std::make_pair ( key, symbol ) );
1157 } else {
1158 mapit->second += ",";
1159
1160 size_t pos = mapit->second.find_last_of ( "\n" );
1161
1162 if ( pos == std::string::npos ) pos = 0;
1163
1164 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1165 mapit->second += "\n";
1166 else
1167 mapit->second += " ";
1168
1169 mapit->second += symbol;
1170 }
1171 }
1172
1173 out << "\\path[->]";
1174
1175 // print the map
1176 for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) {
1177 replaceInplace ( transition.second, "\n", "\\n" );
1178
1179 out << "(" << transition.first.first << ") edge [left] node [align=center] ";
1180 out << "{$" << transition.second << "$}";
1181 out << "(" << transition.first.second << ")\n";
1182 }
1183}
1184
1185template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
1186void TikZConverter::transitions ( const automaton::SinglePopDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > & pda, const ext::map < StateType, int > & states, ext::ostream & out ) {
1187 ext::map < std::pair < int, int >, std::string > transitions;
1188
1189 for ( const auto & transition : pda.getTransitions ( ) ) {
1190 std::string symbol;
1191
1192 // input symbol
1193 if ( std::get < 1 > ( transition.first ).is_epsilon ( ) )
1194 symbol = "&epsilon;";
1195 else
1196 symbol = replace ( factory::StringDataFactory::toString ( std::get < 1 > ( transition.first ).getSymbol ( ) ), "\"", "\\\"" );
1197
1198 symbol += " |";
1199
1200 // Pop part
1201 symbol += " " + replace ( factory::StringDataFactory::toString ( std::get < 2 > ( transition.first ) ), "\"", "\\\"" );
1202
1203 symbol += " ->";
1204
1205 // Push part
1206 if ( transition.second.second.empty ( ) )
1207 symbol += " &epsilon;";
1208 else
1209 for ( const PushdownStoreSymbolType & symb : transition.second.second )
1210 symbol += " " + replace ( factory::StringDataFactory::toString ( symb ), "\"", "\\\"" );
1211
1212 // Insert into map
1213 std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( transition.second.first )->second );
1214 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
1215
1216 if ( mapit == transitions.end ( ) ) {
1217 transitions.insert ( std::make_pair ( key, symbol ) );
1218 } else {
1219 mapit->second += ",";
1220
1221 size_t pos = mapit->second.find_last_of ( "\n" );
1222
1223 if ( pos == std::string::npos ) pos = 0;
1224
1225 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1226 mapit->second += "\n";
1227 else
1228 mapit->second += " ";
1229
1230 mapit->second += symbol;
1231 }
1232 }
1233
1234 out << "\\path[->]";
1235
1236 // print the map
1237 for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) {
1238 replaceInplace ( transition.second, "\n", "\\n" );
1239
1240 out << "(" << transition.first.first << ") edge [left] node [align=center] ";
1241 out << "{$" << transition.second << "$}";
1242 out << "(" << transition.first.second << ")\n";
1243 }
1244}
1245
1246template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
1248 ext::map < std::pair < int, int >, std::string > transitions;
1249
1250 const auto & symbolToPDSOperation = pda.getPushdownStoreOperations ( );
1251
1252 for ( const auto & transition : pda.getTransitions ( ) ) {
1253 const auto & pop = symbolToPDSOperation.find ( transition.first.second )->second.first;
1254 const auto & push = symbolToPDSOperation.find ( transition.first.second )->second.second;
1255
1256 // input symbol
1257 std::string symbol = replace ( factory::StringDataFactory::toString ( transition.first.second ), "\"", "\\\"" );
1258
1259 symbol += " |";
1260
1261 // Pop part
1262 if ( pop.empty ( ) )
1263 symbol += " &epsilon;";
1264 else
1265 for ( const PushdownStoreSymbolType & symb : pop )
1266 symbol += " " + replace ( factory::StringDataFactory::toString ( symb ), "\"", "\\\"" );
1267
1268 symbol += " ->";
1269
1270 const auto & to = transition.second;
1271
1272 // Push part
1273 if ( push.empty ( ) )
1274 symbol += " &epsilon;";
1275 else
1276 for ( const PushdownStoreSymbolType & symb : push )
1277 symbol += " " + replace ( factory::StringDataFactory::toString ( symb ), "\"", "\\\"" );
1278
1279 // Insert into map
1280 std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to )->second );
1281 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
1282
1283 if ( mapit == transitions.end ( ) ) {
1284 transitions.insert ( std::make_pair ( key, symbol ) );
1285 } else {
1286 mapit->second += ",";
1287
1288 size_t pos = mapit->second.find_last_of ( "\n" );
1289
1290 if ( pos == std::string::npos ) pos = 0;
1291
1292 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1293 mapit->second += "\n";
1294 else
1295 mapit->second += " ";
1296
1297 mapit->second += symbol;
1298 }
1299 }
1300
1301 out << "\\path[->]";
1302
1303 // print the map
1304 for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) {
1305 replaceInplace ( transition.second, "\n", "\\n" );
1306
1307 out << "(" << transition.first.first << ") edge [left] node [align=center] ";
1308 out << "{$" << transition.second << "$}";
1309 out << "(" << transition.first.second << ")\n";
1310 }
1311}
1312
1313template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
1315 ext::map < std::pair < int, int >, std::string > transitions;
1316
1317 const auto & symbolToPDSOperation = pda.getPushdownStoreOperations ( );
1318
1319 for ( const auto & transition : pda.getTransitions ( ) ) {
1320 const auto & pop = symbolToPDSOperation.find ( transition.first.second )->second.first;
1321 const auto & push = symbolToPDSOperation.find ( transition.first.second )->second.second;
1322
1323 // input symbol
1324 std::string symbol = replace ( factory::StringDataFactory::toString ( transition.first.second ), "\"", "\\\"" );
1325
1326 symbol += " |";
1327
1328 // Pop part
1329 if ( pop.empty ( ) )
1330 symbol += " &epsilon;";
1331 else
1332 for ( const PushdownStoreSymbolType & symb : pop )
1333 symbol += " " + replace ( factory::StringDataFactory::toString ( symb ), "\"", "\\\"" );
1334
1335 symbol += " ->";
1336
1337 // Push part
1338 if ( push.empty ( ) )
1339 symbol += " &epsilon;";
1340 else
1341 for ( const PushdownStoreSymbolType & symb : push )
1342 symbol += " " + replace ( factory::StringDataFactory::toString ( symb ), "\"", "\\\"" );
1343
1344 // Insert into map
1345 std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second )->second );
1346 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
1347
1348 if ( mapit == transitions.end ( ) ) {
1349 transitions.insert ( std::make_pair ( key, symbol ) );
1350 } else {
1351 mapit->second += ",";
1352
1353 size_t pos = mapit->second.find_last_of ( "\n" );
1354
1355 if ( pos == std::string::npos ) pos = 0;
1356
1357 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1358 mapit->second += "\n";
1359 else
1360 mapit->second += " ";
1361
1362 mapit->second += symbol;
1363 }
1364 }
1365
1366 out << "\\path[->]";
1367
1368 // print the map
1369 for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) {
1370 replaceInplace ( transition.second, "\n", "\\n" );
1371
1372 out << "(" << transition.first.first << ") edge [left] node [align=center] ";
1373 out << "{$" << transition.second << "$}";
1374 out << "(" << transition.first.second << ")\n";
1375 }
1376}
1377
1378template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
1380 ext::map < std::pair < int, int >, std::string > transitions;
1381
1382 for ( const auto & transition : pda.getCallTransitions ( ) ) {
1383 // input symbol
1384 std::string symbol = replace ( factory::StringDataFactory::toString ( transition.first.second ), "\"", "\\\"" );
1385
1386 symbol += " |";
1387
1388 // Pop part
1389 symbol += " &epsilon;";
1390 symbol += " ->";
1391
1392 symbol += " " + replace ( factory::StringDataFactory::toString ( transition.second.second ), "\"", "\\\"" );
1393
1394 // Insert into map
1395 std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second.first )->second );
1396 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
1397
1398 if ( mapit == transitions.end ( ) ) {
1399 transitions.insert ( std::make_pair ( key, symbol ) );
1400 } else {
1401 mapit->second += ",";
1402
1403 size_t pos = mapit->second.find_last_of ( "\n" );
1404
1405 if ( pos == std::string::npos ) pos = 0;
1406
1407 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1408 mapit->second += "\n";
1409 else
1410 mapit->second += " ";
1411
1412 mapit->second += symbol;
1413 }
1414 }
1415
1416 for ( const auto & transition : pda.getReturnTransitions ( ) ) {
1417 // input symbol
1418 std::string symbol = replace ( factory::StringDataFactory::toString ( std::get < 1 > ( transition.first ) ), "\"", "\\\"" );
1419
1420 symbol += " |";
1421
1422 // Pop part
1423 symbol += " " + replace ( factory::StringDataFactory::toString ( std::get < 2 > ( transition.first ) ), "\"", "\\\"" );
1424 symbol += " ->";
1425
1426 symbol += " &epsilon;";
1427
1428 // Insert into map
1429 std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( transition.second )->second );
1430 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
1431
1432 if ( mapit == transitions.end ( ) ) {
1433 transitions.insert ( std::make_pair ( key, symbol ) );
1434 } else {
1435 mapit->second += ",";
1436
1437 size_t pos = mapit->second.find_last_of ( "\n" );
1438
1439 if ( pos == std::string::npos ) pos = 0;
1440
1441 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1442 mapit->second += "\n";
1443 else
1444 mapit->second += " ";
1445
1446 mapit->second += symbol;
1447 }
1448 }
1449
1450 for ( const auto & transition : pda.getLocalTransitions ( ) ) {
1451 // input symbol
1452 std::string symbol = replace ( factory::StringDataFactory::toString ( transition.first.second ), "\"", "\\\"" );
1453
1454 symbol += " |";
1455
1456 // Pop part
1457 symbol += " &epsilon;";
1458 symbol += " ->";
1459
1460 symbol += " &epsilon;";
1461
1462 // Insert into map
1463 std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second )->second );
1464 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
1465
1466 if ( mapit == transitions.end ( ) ) {
1467 transitions.insert ( std::make_pair ( key, symbol ) );
1468 } else {
1469 mapit->second += ",";
1470
1471 size_t pos = mapit->second.find_last_of ( "\n" );
1472
1473 if ( pos == std::string::npos ) pos = 0;
1474
1475 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1476 mapit->second += "\n";
1477 else
1478 mapit->second += " ";
1479
1480 mapit->second += symbol;
1481 }
1482 }
1483
1484 out << "\\path[->]";
1485
1486 // print the map
1487 for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) {
1488 replaceInplace ( transition.second, "\n", "\\n" );
1489
1490 out << "(" << transition.first.first << ") edge [left] node [align=center] ";
1491 out << "{$" << transition.second << "$}";
1492 out << "(" << transition.first.second << ")\n";
1493 }
1494}
1495
1496template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
1498 ext::map < std::pair < int, int >, std::string > transitions;
1499
1500 for ( const auto & transition : pda.getCallTransitions ( ) ) {
1501 // input symbol
1502 std::string symbol = replace ( factory::StringDataFactory::toString ( transition.first.second ), "\"", "\\\"" );
1503
1504 symbol += " |";
1505
1506 // Pop part
1507 symbol += " &epsilon;";
1508 symbol += " ->";
1509
1510 symbol += " " + replace ( factory::StringDataFactory::toString ( transition.second.second ), "\"", "\\\"" );
1511
1512 // Insert into map
1513 std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second.first )->second );
1514 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
1515
1516 if ( mapit == transitions.end ( ) ) {
1517 transitions.insert ( std::make_pair ( key, symbol ) );
1518 } else {
1519 mapit->second += ",";
1520
1521 size_t pos = mapit->second.find_last_of ( "\n" );
1522
1523 if ( pos == std::string::npos ) pos = 0;
1524
1525 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1526 mapit->second += "\n";
1527 else
1528 mapit->second += " ";
1529
1530 mapit->second += symbol;
1531 }
1532 }
1533
1534 for ( const auto & transition : pda.getReturnTransitions ( ) ) {
1535 // input symbol
1536 std::string symbol = replace ( factory::StringDataFactory::toString ( std::get < 1 > ( transition.first ) ), "\"", "\\\"" );
1537
1538 symbol += " |";
1539
1540 // Pop part
1541 symbol += " " + replace ( factory::StringDataFactory::toString ( std::get < 2 > ( transition.first ) ), "\"", "\\\"" );
1542 symbol += " ->";
1543
1544 symbol += " &epsilon;";
1545
1546 // Insert into map
1547 std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( transition.second )->second );
1548 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
1549
1550 if ( mapit == transitions.end ( ) ) {
1551 transitions.insert ( std::make_pair ( key, symbol ) );
1552 } else {
1553 mapit->second += ",";
1554
1555 size_t pos = mapit->second.find_last_of ( "\n" );
1556
1557 if ( pos == std::string::npos ) pos = 0;
1558
1559 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1560 mapit->second += "\n";
1561 else
1562 mapit->second += " ";
1563
1564 mapit->second += symbol;
1565 }
1566 }
1567
1568 for ( const auto & transition : pda.getLocalTransitions ( ) ) {
1569 std::string symbol;
1570
1571 // input symbol
1572 symbol = replace ( factory::StringDataFactory::toString ( transition.first.second ), "\"", "\\\"" );
1573
1574 symbol += " |";
1575
1576 // Pop part
1577 symbol += " &epsilon;";
1578 symbol += " ->";
1579
1580 symbol += " &epsilon;";
1581
1582 // Insert into map
1583 std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second )->second );
1584 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
1585
1586 if ( mapit == transitions.end ( ) ) {
1587 transitions.insert ( std::make_pair ( key, symbol ) );
1588 } else {
1589 mapit->second += ",";
1590
1591 size_t pos = mapit->second.find_last_of ( "\n" );
1592
1593 if ( pos == std::string::npos ) pos = 0;
1594
1595 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1596 mapit->second += "\n";
1597 else
1598 mapit->second += " ";
1599
1600 mapit->second += symbol;
1601 }
1602 }
1603
1604 out << "\\path[->]";
1605
1606 // print the map
1607 for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) {
1608 replaceInplace ( transition.second, "\n", "\\n" );
1609
1610 out << "(" << transition.first.first << ") edge [left] node [align=center] ";
1611 out << "{$" << transition.second << "$}";
1612 out << "(" << transition.first.second << ")\n";
1613 }
1614}
1615
1616template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
1618 ext::map < std::pair < int, int >, std::string > transitions;
1619
1620 for ( const auto & transition : pda.getCallTransitions ( ) ) {
1621 std::string symbol;
1622
1623 // input symbol
1624 if ( transition.first.second.is_epsilon ( ) )
1625 symbol = "&epsilon";
1626 else
1627 symbol = replace ( factory::StringDataFactory::toString ( transition.first.second.getSymbol ( ) ), "\"", "\\\"" );
1628
1629 symbol += " |";
1630
1631 // Pop part
1632 symbol += " &epsilon;";
1633 symbol += " ->";
1634
1635 symbol += " " + replace ( factory::StringDataFactory::toString ( transition.second.second ), "\"", "\\\"" );
1636
1637 // Insert into map
1638 std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second.first )->second );
1639 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
1640
1641 if ( mapit == transitions.end ( ) ) {
1642 transitions.insert ( std::make_pair ( key, symbol ) );
1643 } else {
1644 mapit->second += ",";
1645
1646 size_t pos = mapit->second.find_last_of ( "\n" );
1647
1648 if ( pos == std::string::npos ) pos = 0;
1649
1650 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1651 mapit->second += "\n";
1652 else
1653 mapit->second += " ";
1654
1655 mapit->second += symbol;
1656 }
1657 }
1658
1659 for ( const auto & transition : pda.getReturnTransitions ( ) ) {
1660 std::string symbol;
1661
1662 // input symbol
1663 if ( std::get < 1 > ( transition.first ).is_epsilon ( ) )
1664 symbol = "&epsilon";
1665 else
1666 symbol = replace ( factory::StringDataFactory::toString ( std::get < 1 > ( transition.first ).getSymbol ( ) ), "\"", "\\\"" );
1667
1668 symbol += " |";
1669
1670 // Pop part
1671 symbol += " " + replace ( factory::StringDataFactory::toString ( std::get < 2 > ( transition.first ) ), "\"", "\\\"" );
1672 symbol += " ->";
1673
1674 symbol += " &epsilon;";
1675
1676 // Insert into map
1677 std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( transition.second )->second );
1678 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
1679
1680 if ( mapit == transitions.end ( ) ) {
1681 transitions.insert ( std::make_pair ( key, symbol ) );
1682 } else {
1683 mapit->second += ",";
1684
1685 size_t pos = mapit->second.find_last_of ( "\n" );
1686
1687 if ( pos == std::string::npos ) pos = 0;
1688
1689 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1690 mapit->second += "\n";
1691 else
1692 mapit->second += " ";
1693
1694 mapit->second += symbol;
1695 }
1696 }
1697
1698 for ( const auto & transition : pda.getLocalTransitions ( ) ) {
1699 std::string symbol;
1700
1701 // input symbol
1702 if ( transition.first.second.is_epsilon ( ) )
1703 symbol = "&epsilon";
1704 else
1705 symbol = replace ( factory::StringDataFactory::toString ( transition.first.second.getSymbol ( ) ), "\"", "\\\"" );
1706
1707 symbol += " |";
1708
1709 // Pop part
1710 symbol += " &epsilon;";
1711 symbol += " ->";
1712
1713 symbol += " &epsilon;";
1714
1715 // Insert into map
1716 std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second )->second );
1717 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
1718
1719 if ( mapit == transitions.end ( ) ) {
1720 transitions.insert ( std::make_pair ( key, symbol ) );
1721 } else {
1722 mapit->second += ",";
1723
1724 size_t pos = mapit->second.find_last_of ( "\n" );
1725
1726 if ( pos == std::string::npos ) pos = 0;
1727
1728 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1729 mapit->second += "\n";
1730 else
1731 mapit->second += " ";
1732
1733 mapit->second += symbol;
1734 }
1735 }
1736
1737 out << "\\path[->]";
1738
1739 // print the map
1740 for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) {
1741 replaceInplace ( transition.second, "\n", "\\n" );
1742
1743 out << "(" << transition.first.first << ") edge [left] node [align=center] ";
1744 out << "{$" << transition.second << "$}";
1745 out << "(" << transition.first.second << ")\n";
1746 }
1747}
1748
1749template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
1751 ext::map < std::pair < int, int >, std::string > transitions;
1752
1753 for ( const auto & transition : pda.getCallTransitions ( ) ) {
1754 std::string symbol;
1755
1756 // input symbol
1757 if ( transition.first.second.is_epsilon ( ) )
1758 symbol = "&epsilon";
1759 else
1760 symbol = replace ( factory::StringDataFactory::toString ( transition.first.second.getSymbol ( ) ), "\"", "\\\"" );
1761
1762 symbol += " |";
1763
1764 // Pop part
1765 symbol += " &epsilon;";
1766 symbol += " ->";
1767
1768 symbol += " " + replace ( factory::StringDataFactory::toString ( transition.second.second ), "\"", "\\\"" );
1769
1770 // Insert into map
1771 std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second.first )->second );
1772 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
1773
1774 if ( mapit == transitions.end ( ) ) {
1775 transitions.insert ( std::make_pair ( key, symbol ) );
1776 } else {
1777 mapit->second += ",";
1778
1779 size_t pos = mapit->second.find_last_of ( "\n" );
1780
1781 if ( pos == std::string::npos ) pos = 0;
1782
1783 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1784 mapit->second += "\n";
1785 else
1786 mapit->second += " ";
1787
1788 mapit->second += symbol;
1789 }
1790 }
1791
1792 for ( const auto & transition : pda.getReturnTransitions ( ) ) {
1793 std::string symbol;
1794
1795 // input symbol
1796 if ( std::get < 1 > ( transition.first ).is_epsilon ( ) )
1797 symbol = "&epsilon;";
1798 else
1799 symbol = replace ( factory::StringDataFactory::toString ( std::get < 1 > ( transition.first ).getSymbol ( ) ), "\"", "\\\"" );
1800
1801 symbol += " |";
1802
1803 // Pop part
1804 symbol += " " + replace ( factory::StringDataFactory::toString ( std::get < 2 > ( transition.first ) ), "\"", "\\\"" );
1805 symbol += " ->";
1806
1807 symbol += " &epsilon;";
1808
1809 // Insert into map
1810 std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( transition.second )->second );
1811 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
1812
1813 if ( mapit == transitions.end ( ) ) {
1814 transitions.insert ( std::make_pair ( key, symbol ) );
1815 } else {
1816 mapit->second += ",";
1817
1818 size_t pos = mapit->second.find_last_of ( "\n" );
1819
1820 if ( pos == std::string::npos ) pos = 0;
1821
1822 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1823 mapit->second += "\n";
1824 else
1825 mapit->second += " ";
1826
1827 mapit->second += symbol;
1828 }
1829 }
1830
1831 for ( const auto & transition : pda.getLocalTransitions ( ) ) {
1832 std::string symbol;
1833
1834 // input symbol
1835 if ( transition.first.second.is_epsilon ( ) )
1836 symbol = "&epsilon;";
1837 else
1838 symbol = replace ( factory::StringDataFactory::toString ( transition.first.second.getSymbol ( ) ), "\"", "\\\"" );
1839
1840 symbol += " |";
1841
1842 // Pop part
1843 symbol += " &epsilon;";
1844 symbol += " ->";
1845
1846 symbol += " &epsilon;";
1847
1848 // Insert into map
1849 std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second )->second );
1850 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
1851
1852 if ( mapit == transitions.end ( ) ) {
1853 transitions.insert ( std::make_pair ( key, symbol ) );
1854 } else {
1855 mapit->second += ",";
1856
1857 size_t pos = mapit->second.find_last_of ( "\n" );
1858
1859 if ( pos == std::string::npos ) pos = 0;
1860
1861 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1862 mapit->second += "\n";
1863 else
1864 mapit->second += " ";
1865
1866 mapit->second += symbol;
1867 }
1868 }
1869
1870 out << "\\path[->]";
1871
1872 // print the map
1873 for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) {
1874 replaceInplace ( transition.second, "\n", "\\n" );
1875
1876 out << "(" << transition.first.first << ") edge [left] node [align=center] ";
1877 out << "{$" << transition.second << "$}";
1878 out << "(" << transition.first.second << ")\n";
1879 }
1880}
1881
1882template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
1883void TikZConverter::transitions ( const automaton::NPDA < InputSymbolType, PushdownStoreSymbolType, StateType > & pda, const ext::map < StateType, int > & states, ext::ostream & out ) {
1884 ext::map < std::pair < int, int >, std::string > transitions;
1885
1886 for ( const auto & transition : pda.getTransitions ( ) ) {
1887 std::string symbol;
1888
1889 // input symbol
1890 if ( std::get < 1 > ( transition.first ).is_epsilon ( ) )
1891 symbol = "&epsilon;";
1892 else
1893 symbol = replace ( factory::StringDataFactory::toString ( std::get < 1 > ( transition.first ).getSymbol ( ) ), "\"", "\\\"" );
1894
1895 symbol += " |";
1896
1897 // Pop part
1898 if ( std::get < 2 > ( transition.first ).empty ( ) )
1899 symbol += " &epsilon;";
1900 else
1901 for ( const PushdownStoreSymbolType & symb : std::get < 2 > ( transition.first ) )
1902 symbol += " " + replace ( factory::StringDataFactory::toString ( symb ), "\"", "\\\"" );
1903
1904 symbol += " ->";
1905
1906 // Push part
1907 if ( transition.second.second.empty ( ) )
1908 symbol += " &epsilon;";
1909 else
1910 for ( const PushdownStoreSymbolType & symb : transition.second.second )
1911 symbol += " " + replace ( factory::StringDataFactory::toString ( symb ), "\"", "\\\"" );
1912
1913 // Insert into map
1914 std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( transition.second.first )->second );
1915 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
1916
1917 if ( mapit == transitions.end ( ) ) {
1918 transitions.insert ( std::make_pair ( key, symbol ) );
1919 } else {
1920 mapit->second += ",";
1921
1922 size_t pos = mapit->second.find_last_of ( "\n" );
1923
1924 if ( pos == std::string::npos ) pos = 0;
1925
1926 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1927 mapit->second += "\n";
1928 else
1929 mapit->second += " ";
1930
1931 mapit->second += symbol;
1932 }
1933 }
1934
1935 out << "\\path[->]";
1936
1937 // print the map
1938 for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) {
1939 replaceInplace ( transition.second, "\n", "\\n" );
1940
1941 out << "(" << transition.first.first << ") edge [left] node [align=center] ";
1942 out << "{$" << transition.second << "$}";
1943 out << "(" << transition.first.second << ")\n";
1944 }
1945}
1946
1947template<class InputSymbolType, class PushdownStoreSymbolType, class StateType>
1948void TikZConverter::transitions ( const automaton::SinglePopNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > & pda, const ext::map < StateType, int > & states, ext::ostream & out ) {
1949 ext::map < std::pair < int, int >, std::string > transitions;
1950
1951 for ( const auto & transition : pda.getTransitions ( ) ) {
1952 std::string symbol;
1953
1954 // input symbol
1955 if ( std::get < 1 > ( transition.first ).is_epsilon ( ) )
1956 symbol = "&epsilon;";
1957 else
1958 symbol = replace ( factory::StringDataFactory::toString ( std::get < 1 > ( transition.first ).getSymbol ( ) ), "\"", "\\\"" );
1959
1960 symbol += " |";
1961
1962 // Pop part
1963 symbol += " " + replace ( factory::StringDataFactory::toString ( std::get < 2 > ( transition.first ) ), "\"", "\\\"" );
1964
1965 symbol += " ->";
1966
1967 // Push part
1968 if ( transition.second.second.empty ( ) )
1969 symbol += " &epsilon;";
1970 else
1971 for ( const PushdownStoreSymbolType & symb : transition.second.second )
1972 symbol += " " + replace ( factory::StringDataFactory::toString ( symb ), "\"", "\\\"" );
1973
1974 // Insert into map
1975 std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( transition.second.first )->second );
1976 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
1977
1978 if ( mapit == transitions.end ( ) ) {
1979 transitions.insert ( std::make_pair ( key, symbol ) );
1980 } else {
1981 mapit->second += ",";
1982
1983 size_t pos = mapit->second.find_last_of ( "\n" );
1984
1985 if ( pos == std::string::npos ) pos = 0;
1986
1987 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
1988 mapit->second += "\n";
1989 else
1990 mapit->second += " ";
1991
1992 mapit->second += symbol;
1993 }
1994 }
1995
1996 out << "\\path[->]";
1997
1998 // print the map
1999 for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) {
2000 replaceInplace ( transition.second, "\n", "\\n" );
2001
2002 out << "(" << transition.first.first << ") edge [left] node [align=center] ";
2003 out << "{$" << transition.second << "$}";
2004 out << "(" << transition.first.second << ")\n";
2005 }
2006}
2007
2008template<class SymbolType, class StateType>
2009void TikZConverter::transitions ( const automaton::OneTapeDTM < SymbolType, StateType > & tm, const ext::map < StateType, int > & states, ext::ostream & out ) {
2010 ext::map < std::pair < int, int >, std::string > transitions;
2011
2012 for ( const auto & transition : tm.getTransitions ( ) ) {
2013 std::string symbol;
2014
2015 // input symbol
2016 symbol = "(";
2017 symbol += replace ( factory::StringDataFactory::toString ( transition.first.second ), "\"", "\\\"" );
2018 symbol += ", ";
2019 symbol += replace ( factory::StringDataFactory::toString ( std::get < 1 > ( transition.second ) ), "\"", "\\\"" );
2020 symbol += " ";
2021
2022 switch ( std::get < 2 > ( transition.second ) ) {
2024 symbol += "&larr;";
2025 break;
2026
2028 symbol += "&rarr;";
2029 break;
2030
2032 symbol += "&times;";
2033 break;
2034
2035 default:
2036 throw exception::CommonException ( "Unexpected shift direction" );
2037 }
2038
2039 // Insert into map
2040 std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( std::get < 0 > ( transition.second ) )->second );
2041 ext::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key );
2042
2043 if ( mapit == transitions.end ( ) ) {
2044 transitions.insert ( std::make_pair ( key, symbol ) );
2045 } else {
2046 mapit->second += ",";
2047
2048 size_t pos = mapit->second.find_last_of ( "\n" );
2049
2050 if ( pos == std::string::npos ) pos = 0;
2051
2052 if ( mapit->second.size ( ) - pos > CAPTION_LENGTH_LIMIT )
2053 mapit->second += "\n";
2054 else
2055 mapit->second += " ";
2056
2057 mapit->second += symbol;
2058 }
2059 }
2060
2061 out << "\\path[->]";
2062
2063 // print the map
2064 for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) {
2065 replaceInplace ( transition.second, "\n", "\\n" );
2066
2067 out << "(" << transition.first.first << ") edge [left] node [align=center] ";
2068 out << "{$" << transition.second << "$}";
2069 out << "(" << transition.first.second << ")\n";
2070 }
2071}
2072
2073template<typename TGrid>
2074void TikZConverter::grid(ext::ostream &out, const TGrid &a) {
2075 out << "\\begin{tikzpicture}[ultra thin/.style= {line width=0.1pt}]\n";
2076 long width = a.getWidth();
2077 long height = a.getHeight();
2078
2079 out << "\t\\draw[step=1cm, gray,very thin] (0,0) grid (" << width << "," << height << ");\n";
2080
2081 for (const auto &node : a.getObstacleList()) {
2082 out << "\t\\fill[draw=gray, fill=black, very thin] ("
2083 << node.second << "," << height - node.first - 1
2084 << ") rectangle ("
2085 << node.second + 1 << "," << height - node.first << ");\n";
2086 }
2087
2088 out << "\\end{tikzpicture}\n";
2089}
2090
2091template < class SymbolType >
2094 out << "\\begin{forest}\n";
2095
2096 rte.getRTE ( ).getStructure ( ).template accept < void, TikZConverter::FormalRTEVisitor < SymbolType > > ( oss );
2097 out << " " << oss.str ( ) << "\n";
2098
2099 out << "\\end{forest}" << std::endl;
2100}
2101
2102template < class SymbolType >
2104 out << "[$+$" ;
2105 node.getLeftElement ( ).template accept < void, TikZConverter::FormalRTEVisitor < SymbolType > > ( out );
2106 node.getRightElement ( ).template accept < void, TikZConverter::FormalRTEVisitor < SymbolType > > ( out );
2107 out << "]";
2108}
2109
2110template < class SymbolType >
2112 out << "[$\\cdot\\square_" << node.getSubstitutionSymbol ( ).getSymbol ( ).getSymbol ( ) << "$ ";
2113 node.getLeftElement ( ).template accept < void, TikZConverter::FormalRTEVisitor < SymbolType > > ( out );
2114 node.getRightElement ( ).template accept < void, TikZConverter::FormalRTEVisitor < SymbolType > > ( out );
2115 out << "]";
2116}
2117
2118template < class SymbolType >
2120 out << "[${}^{*,\\square_" << node.getSubstitutionSymbol ( ).getSymbol ( ).getSymbol ( ) << "}$ ";
2121 node.getElement ( ).template accept < void, TikZConverter::FormalRTEVisitor < SymbolType > > ( out );
2122 out << "]";
2123}
2124
2125template < class SymbolType >
2127 out << "[$" << node.getSymbol ( ).getSymbol ( ) << "$ ";
2128 for ( const auto & child : node.getChildren ( ) )
2129 child.template accept < void, TikZConverter::FormalRTEVisitor < SymbolType > > ( out );
2130 out << "]";
2131}
2132
2133template < class SymbolType >
2135 out << "[$\\square_" << node.getSymbol ( ).getSymbol ( ) << "$]";
2136}
2137
2138template < class SymbolType >
2140 out << "[$\\emptyset$]";
2141}
2142
2143} /* namespace convert */
2144
Compact nondeterministic finite automaton. Accepts regular languages. The automaton has a list of sym...
Definition: CompactNFA.h:78
const ext::set< StateType > & getFinalStates() const &
Definition: CompactNFA.h:232
const ext::multimap< ext::pair< StateType, ext::vector< SymbolType > >, StateType > & getTransitions() const &
Definition: CompactNFA.h:555
const ext::set< StateType > & getStates() const &
Definition: CompactNFA.h:183
const StateType & getInitialState() const &
Definition: CompactNFA.h:154
Deterministic finite automaton. Accepts regular languages.
Definition: DFA.h:71
const ext::set< StateType > & getFinalStates() const &
Definition: DFA.h:183
const ext::map< ext::pair< StateType, SymbolType >, StateType > & getTransitions() const &
Definition: DFA.h:473
const StateType & getInitialState() const &
Definition: DFA.h:105
const ext::set< StateType > & getStates() const &
Definition: DFA.h:134
Nondeterministic finite tree automaton without epsilon transitions. Accepts regular tree languages.
Definition: DFTA.h:74
const ext::map< ext::pair< common::ranked_symbol< SymbolType >, ext::vector< StateType > >, StateType > & getTransitions() const &
Definition: DFTA.h:289
const ext::set< StateType > & getFinalStates() const &
Definition: DFTA.h:154
const ext::set< StateType > & getStates() const &
Definition: DFTA.h:105
Deterministic pushdown automaton. Accepts subset of context free languages.
Definition: DPDA.h:78
const ext::set< StateType > & getStates() const &
Definition: DPDA.h:145
const ext::map< ext::tuple< StateType, common::symbol_or_epsilon< InputSymbolType >, ext::vector< PushdownStoreSymbolType > >, ext::pair< StateType, ext::vector< PushdownStoreSymbolType > > > & getTransitions() const &
Definition: DPDA.h:682
const ext::set< StateType > & getFinalStates() const &
Definition: DPDA.h:194
const StateType & getInitialState() const &
Definition: DPDA.h:116
Epsilon nondeterministic finite automaton. Accepts regular languages.
Definition: EpsilonNFA.h:74
const ext::set< StateType > & getStates() const &
Definition: EpsilonNFA.h:158
const ext::set< StateType > & getFinalStates() const &
Definition: EpsilonNFA.h:207
const ext::multimap< ext::pair< StateType, common::symbol_or_epsilon< SymbolType > >, StateType > & getTransitions() const &
Definition: EpsilonNFA.h:666
const StateType & getInitialState() const &
Definition: EpsilonNFA.h:129
Extended nondeterministic finite automaton. Accepts regular languages. The automaton has a regular ex...
Definition: ExtendedNFA.h:80
const StateType & getInitialState() const &
Definition: ExtendedNFA.h:156
const ext::multimap< ext::pair< StateType, regexp::UnboundedRegExpStructure< SymbolType > >, StateType > & getTransitions() const &
Definition: ExtendedNFA.h:581
const ext::set< StateType > & getStates() const &
Definition: ExtendedNFA.h:185
const ext::set< StateType > & getFinalStates() const &
Definition: ExtendedNFA.h:234
Deterministic input driven pushdown automaton. Accepts subset of context free languages.
Definition: InputDrivenDPDA.h:79
const ext::map< ext::pair< StateType, InputSymbolType >, StateType > & getTransitions() const &
Definition: InputDrivenDPDA.h:655
const ext::set< StateType > & getStates() const &
Definition: InputDrivenDPDA.h:160
const ext::set< StateType > & getFinalStates() const &
Definition: InputDrivenDPDA.h:209
const ext::map< InputSymbolType, ext::pair< ext::vector< PushdownStoreSymbolType >, ext::vector< PushdownStoreSymbolType > > > & getPushdownStoreOperations() const &
Definition: InputDrivenDPDA.h:604
const StateType & getInitialState() const &
Definition: InputDrivenDPDA.h:131
Nondeterministic input driven pushdown automaton. Accepts subset of context free languages.
Definition: InputDrivenNPDA.h:79
const ext::map< InputSymbolType, ext::pair< ext::vector< PushdownStoreSymbolType >, ext::vector< PushdownStoreSymbolType > > > & getPushdownStoreOperations() const &
Definition: InputDrivenNPDA.h:614
const ext::multimap< ext::pair< StateType, InputSymbolType >, StateType > & getTransitions() const &
Definition: InputDrivenNPDA.h:661
const ext::set< StateType > & getFinalStates() const &
Definition: InputDrivenNPDA.h:209
const StateType & getInitialState() const &
Definition: InputDrivenNPDA.h:131
const ext::set< StateType > & getStates() const &
Definition: InputDrivenNPDA.h:160
Nondeterministic finite automaton with multiple initial states. Accepts regular languages.
Definition: MultiInitialStateNFA.h:69
const ext::set< StateType > & getInitialStates() const &
Definition: MultiInitialStateNFA.h:117
const ext::set< StateType > & getStates() const &
Definition: MultiInitialStateNFA.h:166
const ext::multimap< ext::pair< StateType, SymbolType >, StateType > & getTransitions() const &
Definition: MultiInitialStateNFA.h:520
const ext::set< StateType > & getFinalStates() const &
Definition: MultiInitialStateNFA.h:215
Nondeterministic finite automaton. Accepts regular languages.
Definition: NFA.h:66
const ext::set< StateType > & getStates() const &
Definition: NFA.h:136
const StateType & getInitialState() const &
Definition: NFA.h:107
const ext::multimap< ext::pair< StateType, SymbolType >, StateType > & getTransitions() const &
Definition: NFA.h:484
const ext::set< StateType > & getFinalStates() const &
Definition: NFA.h:185
Nondeterministic finite tree automaton without epsilon transitions. Accepts regular tree languages.
Definition: NFTA.h:72
const ext::set< StateType > & getFinalStates() const &
Definition: NFTA.h:159
const ext::multimap< ext::pair< common::ranked_symbol< SymbolType >, ext::vector< StateType > >, StateType > & getTransitions() const &
Definition: NFTA.h:294
const ext::set< StateType > & getStates() const &
Definition: NFTA.h:110
Definition: NPDA.h:74
const ext::set< StateType > & getFinalStates() const &
Definition: NPDA.h:197
const StateType & getInitialState() const &
Definition: NPDA.h:119
const ext::set< StateType > & getStates() const &
Definition: NPDA.h:148
const ext::multimap< ext::tuple< StateType, common::symbol_or_epsilon< InputSymbolType >, ext::vector< PushdownStoreSymbolType > >, ext::pair< StateType, ext::vector< PushdownStoreSymbolType > > > & getTransitions() const &
Definition: NPDA.h:644
Deterministic single tape turing machine. Accepts recursive languages.
Definition: OneTapeDTM.h:71
const StateType & getInitialState() const &
Definition: OneTapeDTM.h:108
const ext::set< StateType > & getFinalStates() const &
Definition: OneTapeDTM.h:186
const ext::map< ext::pair< StateType, SymbolType >, ext::tuple< StateType, SymbolType, Shift > > & getTransitions() const &
Definition: OneTapeDTM.h:526
const ext::set< StateType > & getStates() const &
Definition: OneTapeDTM.h:137
Deterministic real time height deterministic pushdown automaton. Accepts subset of context free langu...
Definition: RealTimeHeightDeterministicDPDA.h:89
const StateType & getInitialState() const &
Definition: RealTimeHeightDeterministicDPDA.h:149
const ext::map< ext::pair< StateType, common::symbol_or_epsilon< InputSymbolType > >, ext::pair< StateType, PushdownStoreSymbolType > > & getCallTransitions() const &
Definition: RealTimeHeightDeterministicDPDA.h:1062
const ext::map< ext::pair< StateType, common::symbol_or_epsilon< InputSymbolType > >, StateType > & getLocalTransitions() const &
Definition: RealTimeHeightDeterministicDPDA.h:1082
const ext::map< ext::tuple< StateType, common::symbol_or_epsilon< InputSymbolType >, PushdownStoreSymbolType >, StateType > & getReturnTransitions() const &
Definition: RealTimeHeightDeterministicDPDA.h:1072
const ext::set< StateType > & getStates() const &
Definition: RealTimeHeightDeterministicDPDA.h:178
const ext::set< StateType > & getFinalStates() const &
Definition: RealTimeHeightDeterministicDPDA.h:227
Nondeterministic real time height deterministic pushdown automaton. Accepts subset of context free la...
Definition: RealTimeHeightDeterministicNPDA.h:76
const ext::set< StateType > & getInitialStates() const &
Definition: RealTimeHeightDeterministicNPDA.h:175
const ext::set< StateType > & getStates() const &
Definition: RealTimeHeightDeterministicNPDA.h:126
const ext::multimap< ext::pair< StateType, common::symbol_or_epsilon< InputSymbolType > >, StateType > & getLocalTransitions() const &
Definition: RealTimeHeightDeterministicNPDA.h:1004
const ext::multimap< ext::pair< StateType, common::symbol_or_epsilon< InputSymbolType > >, ext::pair< StateType, PushdownStoreSymbolType > > & getCallTransitions() const &
Definition: RealTimeHeightDeterministicNPDA.h:984
const ext::set< StateType > & getFinalStates() const &
Definition: RealTimeHeightDeterministicNPDA.h:224
const ext::multimap< ext::tuple< StateType, common::symbol_or_epsilon< InputSymbolType >, PushdownStoreSymbolType >, StateType > & getReturnTransitions() const &
Definition: RealTimeHeightDeterministicNPDA.h:994
Deterministic pushdown automaton requiring a symbol pop from pushdown store on each transition use....
Definition: SinglePopDPDA.h:78
const StateType & getInitialState() const &
Definition: SinglePopDPDA.h:116
const ext::set< StateType > & getFinalStates() const &
Definition: SinglePopDPDA.h:194
const ext::set< StateType > & getStates() const &
Definition: SinglePopDPDA.h:145
const ext::map< ext::tuple< StateType, common::symbol_or_epsilon< InputSymbolType >, PushdownStoreSymbolType >, ext::pair< StateType, ext::vector< PushdownStoreSymbolType > > > & getTransitions() const &
Definition: SinglePopDPDA.h:639
Definition: SinglePopNPDA.h:72
const StateType & getInitialState() const &
Definition: SinglePopNPDA.h:110
const ext::multimap< ext::tuple< StateType, common::symbol_or_epsilon< InputSymbolType >, PushdownStoreSymbolType >, ext::pair< StateType, ext::vector< PushdownStoreSymbolType > > > & getTransitions() const &
Definition: SinglePopNPDA.h:617
const ext::set< StateType > & getStates() const &
Definition: SinglePopNPDA.h:139
const ext::set< StateType > & getFinalStates() const &
Definition: SinglePopNPDA.h:188
Deterministic visibly pushdown automaton. Accepts subset of context free languages.
Definition: VisiblyPushdownDPDA.h:86
const ext::map< ext::tuple< StateType, InputSymbolType, PushdownStoreSymbolType >, StateType > & getReturnTransitions() const &
Definition: VisiblyPushdownDPDA.h:899
const ext::map< ext::pair< StateType, InputSymbolType >, StateType > & getLocalTransitions() const &
Definition: VisiblyPushdownDPDA.h:909
const ext::set< StateType > & getFinalStates() const &
Definition: VisiblyPushdownDPDA.h:224
const ext::map< ext::pair< StateType, InputSymbolType >, ext::pair< StateType, PushdownStoreSymbolType > > & getCallTransitions() const &
Definition: VisiblyPushdownDPDA.h:889
const ext::set< StateType > & getStates() const &
Definition: VisiblyPushdownDPDA.h:175
const StateType & getInitialState() const &
Definition: VisiblyPushdownDPDA.h:146
Nondeterministic visibly pushdown automaton. Accepts subset of context free languages.
Definition: VisiblyPushdownNPDA.h:81
const ext::set< StateType > & getInitialStates() const &
Definition: VisiblyPushdownNPDA.h:131
const ext::set< StateType > & getStates() const &
Definition: VisiblyPushdownNPDA.h:180
const ext::multimap< ext::pair< StateType, InputSymbolType >, StateType > & getLocalTransitions() const &
Definition: VisiblyPushdownNPDA.h:884
const ext::set< StateType > & getFinalStates() const &
Definition: VisiblyPushdownNPDA.h:229
const ext::multimap< ext::tuple< StateType, InputSymbolType, PushdownStoreSymbolType >, StateType > & getReturnTransitions() const &
Definition: VisiblyPushdownNPDA.h:874
const ext::multimap< ext::pair< StateType, InputSymbolType >, ext::pair< StateType, PushdownStoreSymbolType > > & getCallTransitions() const &
Definition: VisiblyPushdownNPDA.h:864
Definition: TikZConverter.h:202
static void visit(const rte::FormalRTEAlternation< SymbolType > &node, ext::ostream &out)
Definition: TikZConverter.h:2103
Definition: TikZConverter.h:53
static void convert(ext::ostream &out, const grid::SquareGrid8< TCoordinate, TEdge > &a)
Definition: TikZConverter.h:180
static void convert(ext::ostream &out, const automaton::DFA< SymbolType, StateType > &a)
Definition: TikZConverter.h:300
static void convert(ext::ostream &out, const grid::WeightedSquareGrid8< TCoordinate, TEdge > &a)
Definition: TikZConverter.h:190
static void convert(ext::ostream &out, const grid::WeightedSquareGrid4< TCoordinate, TEdge > &a)
Definition: TikZConverter.h:185
static std::string convert(const T &automaton)
Definition: TikZConverter.h:195
static void convert(ext::ostream &out, const grid::SquareGrid4< TCoordinate, TEdge > &a)
Definition: TikZConverter.h:175
Basic exception from which all other exceptions are derived.
Definition: CommonException.h:21
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
std::pair< iterator, bool > insert(const T &key, const R &value)
Insert variant with explicit key and value parameters.
Definition: map.hpp:118
auto end() &
Inherited behavior of end for non-const instance.
Definition: map.hpp:215
Definition: ostream.h:14
Definition: sstream.h:15
std::string str() const &
Definition: sstream.cpp:29
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
static std::string toString(const T &data)
Definition: StringDataFactory.hpp:89
Definition: SquareGrid4.hpp:18
Definition: SquareGrid8.hpp:18
Definition: WeightedSquareGrid4.hpp:18
Definition: WeightedSquareGrid8.hpp:18
Represents the alternation operator in the regular tree expression. The node must have exactly two ch...
Definition: FormalRTEAlternation.h:44
Represents the empty expression in the regular tree expression. The node can't have any children.
Definition: FormalRTEEmpty.h:40
Represents the iteration operator in the regular tree expression. The node has exactly one child.
Definition: FormalRTEIteration.h:45
Represents the concatenation operator in the regular tree expression. The node must have exactly two ...
Definition: FormalRTESubstitution.h:44
Represents the terminal symbol in the regular tree expression. The number of children must be the sam...
Definition: FormalRTESymbolAlphabet.h:44
Represents the substitution symbol in the regular tree expression. The node can't have any children.
Definition: FormalRTESymbolSubst.h:43
Formal regular tree expression represents regular tree expression. It describes regular tree language...
Definition: FormalRTE.h:71
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
int i
Definition: AllEpsilonClosure.h:118
Definition: ToGrammar.h:31
Definition: converterCommon.hpp:8
auto replaceInplace
Definition: converterCommon.hpp:10
auto replace
Definition: converterCommon.hpp:19
std::string to_string(const T &value)
To string method designated for objects that can be casted to string.
Definition: string.hpp:131
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: GridDirection.hpp:12
Definition: Node.cpp:11
Definition: ToFTAGlushkov.h:22
string::LinearString< char > stringFrom(const std::string &string)
Definition: String.cpp:10