diff --git a/alib2algo/src/stringology/simulations/HammingDynamicProgramming.cpp b/alib2algo/src/stringology/simulations/HammingDynamicProgramming.cpp new file mode 100644 index 0000000000000000000000000000000000000000..192d73e2a416e1022ee277112402e20698829e7e --- /dev/null +++ b/alib2algo/src/stringology/simulations/HammingDynamicProgramming.cpp @@ -0,0 +1,19 @@ +/* + * HammingDynamicProgramming.cpp + * + * Created on: 12. 3. 2018 + * Author: Tomas Capek + */ + +#include "HammingDynamicProgramming.h" +#include <registration/AlgoRegistration.hpp> + +namespace stringology { + +namespace simulations { + +auto HammingDynamicProgrammingLinearString = registration::AbstractRegister < HammingDynamicProgramming, ext::set < unsigned >, const string::LinearString < > &, const string::LinearString < > &, unsigned > ( HammingDynamicProgramming::search ); + +} /* namespace simulations */ + +} /* namespace stringology */ diff --git a/alib2algo/src/stringology/simulations/HammingDynamicProgramming.h b/alib2algo/src/stringology/simulations/HammingDynamicProgramming.h index c4de7edb15246c8a3ae4b7ce4995ab14b30d48e8..43f05e8d7533197bfe605f613f8cacd0799c51d1 100644 --- a/alib2algo/src/stringology/simulations/HammingDynamicProgramming.h +++ b/alib2algo/src/stringology/simulations/HammingDynamicProgramming.h @@ -20,7 +20,7 @@ public: static ext::vector<ext::vector<unsigned int>> compute_table(const string::LinearString<SymbolType> & text, const string::LinearString<SymbolType> & pattern, unsigned int errors); template <class SymbolType> - static ext::vector<unsigned int> search(const string::LinearString<SymbolType> & text, const string::LinearString<SymbolType> & pattern, unsigned int errors); + static ext::set<unsigned int> search(const string::LinearString<SymbolType> & text, const string::LinearString<SymbolType> & pattern, unsigned int errors); }; @@ -47,14 +47,14 @@ ext::vector<ext::vector<unsigned int>> HammingDynamicProgramming::compute_table( } template <class SymbolType> -ext::vector<unsigned int> HammingDynamicProgramming::search(const string::LinearString<SymbolType> & text, const string::LinearString<SymbolType> & pattern, unsigned int errors) { +ext::set<unsigned int> HammingDynamicProgramming::search(const string::LinearString<SymbolType> & text, const string::LinearString<SymbolType> & pattern, unsigned int errors) { auto table = HammingDynamicProgramming::compute_table(text, pattern, errors); - ext::vector<unsigned int> result = ext::vector<unsigned int>(); + ext::set<unsigned int> result; for(unsigned int i=1; i<=text.getContent().size(); i++) { if (table[i][pattern.getContent().size()] <= errors) { - result.push_back(i - pattern.getContent().size()); + result.insert(i - pattern.getContent().size()); } } diff --git a/astringology2/src/astringology.cpp b/astringology2/src/astringology.cpp index 5b93d30954ae297044577eff19f279f8684318a1..c69944ec8014f9783349ad0e635c7fdf96232a30 100644 --- a/astringology2/src/astringology.cpp +++ b/astringology2/src/astringology.cpp @@ -52,6 +52,9 @@ int main ( int argc, char * argv[] ) { allowed.push_back ( "badCharacterShiftTable" ); allowed.push_back ( "quickSearchBadCharacterShiftTable"); allowed.push_back ( "goodSuffixShiftTable" ); + + allowed.push_back ( "hammingMatchDynamicProgramming" ); + TCLAP::ValuesConstraint < std::string > allowedVals ( allowed ); TCLAP::ValueArg < std::string > algorithm ( "a", "algorithm", "Execute algorithm", false, "exactFactorMatch", & allowedVals ); @@ -63,6 +66,9 @@ int main ( int argc, char * argv[] ) { TCLAP::MultiArg < std::string > patternInput ( "p", "pattern", "Pattern string from file", false, "file" ); cmd.add ( patternInput ); + TCLAP::ValueArg < unsigned > distanceInput ( "d", "distance", "Number of errors for aproximate algorithms", false, 1, "unsigned" ); + cmd.add ( distanceInput ); + TCLAP::SwitchArg measure ( "m", "measure", "Measure times", false ); cmd.add ( measure ); @@ -100,7 +106,8 @@ int main ( int argc, char * argv[] ) { || algorithm.getValue ( ) == "bitParallelIndex" || algorithm.getValue ( ) == "compressedBitParallelIndex" || algorithm.getValue ( ) == "suffixArray" - || algorithm.getValue ( ) == "suffixAutomaton" ) { + || algorithm.getValue ( ) == "suffixAutomaton" + || algorithm.getValue ( ) == "hammingMatchDynamicProgramming" ) { std::string input; if ( subjectInput.getValue ( ).size ( ) == 0 ) input = "-"; @@ -129,7 +136,8 @@ int main ( int argc, char * argv[] ) { || algorithm.getValue ( ) == "bndmMatcher" || algorithm.getValue ( ) == "badCharacterShiftTable" || algorithm.getValue ( ) == "quickSearchBadCharacterShiftTable" - || algorithm.getValue ( ) == "goodSuffixShiftTable" ) { + || algorithm.getValue ( ) == "goodSuffixShiftTable" + || algorithm.getValue ( ) == "hammingMatchDynamicProgramming" ) { std::string input; if ( patternInput.getValue ( ).size ( ) == 0 ) input = "-"; @@ -156,6 +164,12 @@ int main ( int argc, char * argv[] ) { parser.parse ( )->run ( environment ); } + if ( algorithm.getValue ( ) == "hammingMatchDynamicProgramming" ) { + unsigned input = distanceInput.getValue ( ); + + environment.setVariable ( "distance", input ); + } + measurements::end ( ); measurements::start ( "Algorithm", measurements::Type::MAIN ); @@ -218,6 +232,8 @@ int main ( int argc, char * argv[] ) { cliCommand = "execute string::properties::QuickSearchBadCharacterShiftTable $pattern > $output"; } else if ( algorithm.getValue ( ) == "goodSuffixShiftTable" ) { cliCommand = "execute string::properties::GoodSuffixShiftTable $pattern > $output"; + } else if ( algorithm.getValue ( ) == "hammingMatchDynamicProgramming" ) { + cliCommand = "execute stringology::simulations::HammingDynamicProgramming $subject $pattern $distance > $output"; } else { throw exception::CommonException ( "Invalid algorithm" ); }