Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
FormalRTE.h
Go to the documentation of this file.
1
6/*
7 * This file is part of Algorithms library toolkit.
8 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
9
10 * Algorithms library toolkit is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14
15 * Algorithms library toolkit is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19
20 * You should have received a copy of the GNU General Public License
21 * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
26#include <ext/iostream>
27#include <ext/algorithm>
28
29#include <alib/string>
30#include <alib/set>
31
32#include <core/components.hpp>
34
36
37#include "FormalRTEStructure.h"
38
39#include <core/normalize.hpp>
41
42namespace rte {
43
44class GeneralAlphabet;
45class ConstantAlphabet;
46
70template < class SymbolType = DefaultSymbolType >
71class FormalRTE final : public core::Components < FormalRTE < SymbolType >, ext::set < common::ranked_symbol < SymbolType > >, component::Set, std::tuple < GeneralAlphabet, ConstantAlphabet > > {
76
77public:
81 explicit FormalRTE ( );
82
91
99
106
113 return this->template accessComponent < GeneralAlphabet > ( ).get ( );
114 }
115
122 return std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) );
123 }
124
133 this->template accessComponent < GeneralAlphabet > ( ).add ( std::move ( symbol ) );
134 }
135
142 this->template accessComponent < GeneralAlphabet > ( ).add ( std::move ( symbols ) );
143 }
144
151 this->template accessComponent < GeneralAlphabet > ( ).set ( std::move ( symbols ) );
152 }
153
162 this->template accessComponent < GeneralAlphabet > ( ).remove ( symbol );
163 }
164
171 return this->template accessComponent < ConstantAlphabet > ( ).get ( );
172 }
173
180 return std::move ( this->template accessComponent < ConstantAlphabet > ( ).get ( ) );
181 }
182
191 this->template accessComponent < ConstantAlphabet > ( ).add ( std::move ( symbol ) );
192 }
193
200 this->template accessComponent < ConstantAlphabet > ( ).add ( std::move ( symbols ) );
201 }
202
209 this->template accessComponent < ConstantAlphabet > ( ).set ( std::move ( symbols ) );
210 }
211
220 this->template accessComponent < ConstantAlphabet > ( ).remove ( symbol );
221 }
222
228 const FormalRTEStructure < SymbolType > & getRTE ( ) const &;
229
236
242 void setRTE ( FormalRTEStructure < SymbolType > param );
243
251 auto operator <=> ( const FormalRTE & other ) const {
252 return std::tie ( m_rte, getAlphabet ( ), getSubstitutionAlphabet ( ) ) <=> std::tie ( m_rte, other.getAlphabet ( ), getSubstitutionAlphabet ( ) );
253 }
254
262 bool operator == ( const FormalRTE & other ) const {
263 return std::tie ( m_rte, getAlphabet ( ), getSubstitutionAlphabet ( ) ) == std::tie ( m_rte, other.getAlphabet ( ), getSubstitutionAlphabet ( ) );
264 }
265
274 friend ext::ostream & operator << ( ext::ostream & out, const FormalRTE & instance ) {
275 return out << "(FormalRTE " << instance.getRTE ( ) << ")";
276 }
277};
278
279template < class SymbolType >
280FormalRTE < SymbolType >::FormalRTE ( ext::set < common::ranked_symbol < SymbolType > > alphabetF, ext::set < common::ranked_symbol < SymbolType > > alphabetK, FormalRTEStructure < SymbolType > rte ) : core::Components < FormalRTE, ext::set < common::ranked_symbol < SymbolType > >, component::Set, std::tuple < GeneralAlphabet, ConstantAlphabet > > ( std::move ( alphabetF ), std::move ( alphabetK ) ), m_rte ( std::move ( rte ) ) {
281 if ( !this->m_rte.getStructure ( ).checkAlphabet ( getAlphabet ( ), getSubstitutionAlphabet ( ) ) )
282 throw exception::CommonException ( "Input symbols not in the alphabet." );
283}
284
285template < class SymbolType >
286FormalRTE < SymbolType >::FormalRTE ( std::pair < ext::set < common::ranked_symbol < SymbolType > >, ext::set < common::ranked_symbol < SymbolType > > > alphabets, FormalRTEStructure < SymbolType > rte ) : FormalRTE ( std::move ( alphabets.first ), std::move ( alphabets.second ), std::move ( rte ) ) {
287}
288
289template < class SymbolType >
291}
292
293template < class SymbolType >
294FormalRTE < SymbolType >::FormalRTE ( FormalRTEStructure < SymbolType > rte ) : FormalRTE ( rte.getStructure ( ).computeMinimalAlphabets ( ), rte ) {
295}
296
297template < class SymbolType >
299 return m_rte;
300}
301
302template < class SymbolType >
304 return std::move ( m_rte );
305}
306
307template < class SymbolType >
309 if ( !param.getStructure ( ).checkAlphabet ( getAlphabet ( ), getSubstitutionAlphabet ( ) ) )
310 throw exception::CommonException ( "Symbols not matching alphabets." );
311
312 this->m_rte = std::move ( param );
313}
314
315} /* namespace rte */
316
317namespace core {
318
324template < class SymbolType >
325class SetConstraint< rte::FormalRTE < SymbolType >, common::ranked_symbol < SymbolType >, rte::GeneralAlphabet > {
326public:
336 return rte.getRTE ( ).getStructure ( ).testSymbol ( symbol );
337 }
338
348 return true;
349 }
350
358 if ( rte.template accessComponent < rte::ConstantAlphabet > ( ).get ( ).count ( symbol ) )
359 throw ::exception::CommonException ( "Symbol " + ext::to_string ( symbol ) + " cannot be in general alphabet since it is already in constant alphabet" );
360 }
361};
362
368template < class SymbolType >
369class SetConstraint< rte::FormalRTE < SymbolType >, common::ranked_symbol < SymbolType >, rte::ConstantAlphabet > {
370public:
380 return rte.getRTE ( ).getStructure ( ).testSymbol ( symbol );
381 }
382
392 return true;
393 }
394
402 if ( rte.template accessComponent < rte::GeneralAlphabet > ( ).get ( ).count ( symbol ) )
403 throw ::exception::CommonException ( "Symbol " + ext::to_string ( symbol ) + " cannot be in constant alphabet since it is already in general alphabet" );
404 }
405};
406
412template < class SymbolType >
413struct normalize < rte::FormalRTE < SymbolType > > {
416 ext::set < common::ranked_symbol < DefaultSymbolType > > constants = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getSubstitutionAlphabet ( ) );
417
418 return rte::FormalRTE < > ( alphabet, constants, std::move ( value ).getRTE ( ).normalize ( ) );
419 }
420};
421
422} /* namespace core */
423
424extern template class rte::FormalRTE < >;
425
static ext::set< common::ranked_symbol< DefaultSymbolType > > normalizeRankedAlphabet(ext::set< common::ranked_symbol< SymbolType > > &&symbols)
Definition: SymbolNormalize.h:59
Definition: ranked_symbol.hpp:20
Definition: components.hpp:181
static void valid(const rte::FormalRTE< SymbolType > &rte, const common::ranked_symbol< SymbolType > &symbol)
Definition: FormalRTE.h:357
static bool used(const rte::FormalRTE< SymbolType > &rte, const common::ranked_symbol< SymbolType > &symbol)
Definition: FormalRTE.h:335
static bool available(const rte::FormalRTE< SymbolType > &, const common::ranked_symbol< SymbolType > &)
Definition: FormalRTE.h:347
static void valid(const rte::FormalRTE< SymbolType > &rte, const common::ranked_symbol< SymbolType > &symbol)
Definition: FormalRTE.h:401
static bool available(const rte::FormalRTE< SymbolType > &, const common::ranked_symbol< SymbolType > &)
Definition: FormalRTE.h:391
static bool used(const rte::FormalRTE< SymbolType > &rte, const common::ranked_symbol< SymbolType > &symbol)
Definition: FormalRTE.h:379
Definition: setComponents.hpp:26
Basic exception from which all other exceptions are derived.
Definition: CommonException.h:21
Definition: ostream.h:14
Definition: set.hpp:44
Represents unbounded regular expression structure. Regular expression is stored as a tree of Unbounde...
Definition: FormalRTEStructure.h:41
Formal regular tree expression represents regular tree expression. It describes regular tree language...
Definition: FormalRTE.h:71
ext::set< common::ranked_symbol< SymbolType > > && getAlphabet() &&
Definition: FormalRTE.h:121
bool operator==(const FormalRTE &other) const
Definition: FormalRTE.h:262
void addConstantSymbols(ext::set< common::ranked_symbol< SymbolType > > symbols)
Definition: FormalRTE.h:199
void setRTE(FormalRTEStructure< SymbolType > param)
Definition: FormalRTE.h:308
void setAlphabetSymbols(ext::set< common::ranked_symbol< SymbolType > > symbols)
Definition: FormalRTE.h:150
void removeConstantSymbol(const common::ranked_symbol< SymbolType > &symbol)
Definition: FormalRTE.h:219
void addConstantSymbol(common::ranked_symbol< SymbolType > symbol)
Definition: FormalRTE.h:190
void setConstantSymbols(ext::set< common::ranked_symbol< SymbolType > > symbols)
Definition: FormalRTE.h:208
FormalRTE()
Creates a new instance of the expression. The default constructor creates expression describing empty...
Definition: FormalRTE.h:290
const ext::set< common::ranked_symbol< SymbolType > > & getSubstitutionAlphabet() const &
Definition: FormalRTE.h:170
void removeAlphabetSymbol(const common::ranked_symbol< SymbolType > &symbol)
Definition: FormalRTE.h:161
const ext::set< common::ranked_symbol< SymbolType > > & getAlphabet() const &
Definition: FormalRTE.h:112
void addAlphabetSymbols(common::ranked_symbol< SymbolType > symbol)
Definition: FormalRTE.h:132
friend ext::ostream & operator<<(ext::ostream &out, const FormalRTE &instance)
Definition: FormalRTE.h:274
void addAlphabetSymbols(ext::set< common::ranked_symbol< SymbolType > > symbols)
Definition: FormalRTE.h:141
ext::set< common::ranked_symbol< SymbolType > > && getSubstitutionAlphabet() &&
Definition: FormalRTE.h:179
const FormalRTEStructure< SymbolType > & getRTE() const &
Definition: FormalRTE.h:298
Definition: BarSymbol.cpp:12
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
Definition: normalize.hpp:10
constexpr tuple< Elements &... > tie(Elements &... args) noexcept
Helper of extended tuple of references construction. The tuple is constructed to reffer to values in ...
Definition: tuple.hpp:218
std::string to_string(const T &value)
To string method designated for objects that can be casted to string.
Definition: string.hpp:131
Definition: ToFTAGlushkov.h:22
auto & get(ext::ptr_array< Type, N > &tpl)
Specialisation of get function for pointer arrays.
Definition: ptr_array.hpp:693
static rte::FormalRTE< > eval(rte::FormalRTE< SymbolType > &&value)
Definition: FormalRTE.h:414
Definition: normalize.hpp:13