diff --git a/acat2/src/acat.cpp b/acat2/src/acat.cpp index 4eb63f914e801993a0d02387d7d1aba43d83f1e8..c58cd7d705fa3b502113ad8e84b58f3ac67c655e 100644 --- a/acat2/src/acat.cpp +++ b/acat2/src/acat.cpp @@ -50,11 +50,11 @@ int main(int argc, char** argv) { alib::Object object = alib::DataFactory::fromTokens<alib::Object>(tokens); alib::DataFactory::toStdout(object); + return 0; } catch(const exception::AlibException& exception) { alib::DataFactory::toStdout(exception); return 1; } catch(...) { return 127; } - return 0; } diff --git a/alib2data/src/factory/DataFactory.hpp b/alib2data/src/factory/DataFactory.hpp index 1db40a6fff1af07f634d9bbcf0b0915cf1fe0d93..cb3b22d02bc8d5023eb7e45312ae62fed5d7ede7 100644 --- a/alib2data/src/factory/DataFactory.hpp +++ b/alib2data/src/factory/DataFactory.hpp @@ -62,7 +62,7 @@ public: */ template<class T> static T fromStream(std::istream& in) { - std::string input(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>()); + std::string input{std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>()}; return fromString<T>(input); } diff --git a/aminimize/makefile b/aminimize/makefile deleted file mode 100644 index f31e3d5917c73e9172564ad177eea58242906e67..0000000000000000000000000000000000000000 --- a/aminimize/makefile +++ /dev/null @@ -1,20 +0,0 @@ -CC=g++ -EXECUTABLE=aminimize -CCFLAGS= -std=c++11 -O2 -c -Wall -I../alib/src -LDFLAGS= -L../alib/lib -lxml2 -lalib -Wl,-rpath,. - -SOURCES=$(shell find src/ -name *cpp) -OBJECTS=$(patsubst src/%.cpp, obj/%.o, $(SOURCES)) - -all: $(SOURCES) bin/$(EXECUTABLE) - -bin/$(EXECUTABLE): $(OBJECTS) - mkdir -p bin - $(CC) $(OBJECTS) -o $@ $(LDFLAGS) - -obj/%.o: src/%.cpp - mkdir -p $(dir $@) - $(CC) $(CCFLAGS) $< -o $@ - -clean: - $(RM) -r *.o *.d bin obj diff --git a/aminimize/src/aminimize.cpp b/aminimize/src/aminimize.cpp deleted file mode 100644 index 4562910785c458be57deca3d316ed7722a2713ce..0000000000000000000000000000000000000000 --- a/aminimize/src/aminimize.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//============================================================================ -// Name : aminimize.cpp -// Author : Jan Travnicek -//============================================================================ - -#include <iostream> -#include <string> -#include <set> - -#include "AutomatonFactory.h" -#include "AlibException.h" -#include "automaton/AutomatonParser.h" - -#include "Minimize.h" - -using namespace std; -using namespace automaton; -using namespace alib; - -int main(int argc, char** argv) { - - UnknownAutomaton automaton; - - try { - - if (argc == 2 && string("-h").compare(argv[1]) == 0) { - cout << "Automaton minimize.\nUsage: aminimize automaton.xml\n"; - return -1; - } else if (argc == 1 || (argc == 2 && string("--").compare(argv[1]) == 0)) { - automaton = AutomatonFactory::fromStdin(); - if(!AutomatonFactory::isFSM(automaton)) { - cout << "Automaton minimize require deterministic finite automaton\n"; - return 1; - } - } else if (argc == 2) { - automaton = AutomatonFactory::fromFile(argv[1]); - if(!AutomatonFactory::isFSM(automaton)) { - cout << "Automaton minimize require deterministic finite automaton\n"; - return 1; - } - } else { - cout << "Automaton minimize require finite automaton\n"; - return 1; - } - automaton::FSM fsm = AutomatonFactory::buildFSM(automaton); - if(!fsm.isDeterministic()) { - cout << "Automaton minimize require deterministic finite automaton\n"; - return 1; - } - - automaton::FSM res = Minimize::minimize(fsm); - res.toXML(cout); - - return 0; - - } catch (AlibException& e) { - cout << e.getCause() << endl; - return 0; - } - -} diff --git a/aminimize2/makefile b/aminimize2/makefile new file mode 100644 index 0000000000000000000000000000000000000000..076ce8784b2c4d54ad68735d4250273fbf87186d --- /dev/null +++ b/aminimize2/makefile @@ -0,0 +1,73 @@ +SHELL:=/bin/bash +EXECUTABLE:=aminimize2 + +LDFLAGS= -L../alib2data/lib -L../alib2algo/lib -rdynamic -lxml2 -lalib2data -lalib2algo -Wl,-rpath,. + +OBJECTS:=$(patsubst src/%.cpp, obj/%.o, $(shell find src/ -name *cpp)) + +.PHONY: all build clean + +all: build + + + +bin/$(EXECUTABLE): obj/ $(OBJECTS) + mkdir -p bin + $(CXX) $(OBJECTS) -o $@ $(LDFLAGS) + +obj/makefile: makefile + mkdir -p $(dir $@) + echo "SHELL:=/bin/bash" >> $@ + echo "SRCDIR:=" >> $@ + echo "DEPTH:=" >> $@ + echo "" >> $@ + echo "CXXFLAGS:= -std=c++11 -Og -g -c -Wall -pedantic -Wextra -I../../\$$(DEPTH)alib2data/src/ -I../../\$$(DEPTH)alib2algo/src -I/usr/include/libxml2/" >> $@ + echo "" >> $@ + echo "SOURCES:= \$$(shell find ../\$$(DEPTH)src/\$$(SRCDIR) -maxdepth 1 -type f -name \"*.cpp\")" >> $@ + echo "DEPENDENCIES:= \$$(patsubst ../\$$(DEPTH)src/\$$(SRCDIR)%.cpp, ../\$$(DEPTH)obj/\$$(SRCDIR)%.d, \$$(SOURCES))" >> $@ + echo "OBJECTS:= \$$(patsubst %.d, %.o, \$$(DEPENDENCIES))" >> $@ + echo "SOURCES_DIRS:= \$$(shell find ../\$$(DEPTH)src/\$$(SRCDIR) -maxdepth 1 -mindepth 1 -type d)" >> $@ + echo "OBJECTS_DIRS:= \$$(patsubst ../\$$(DEPTH)src/\$$(SRCDIR)%, %/, \$$(SOURCES_DIRS))" >> $@ + echo "OBJECTS_DIRS_MAKEFILES:= \$$(patsubst %, %makefile, \$$(OBJECTS_DIRS))" >> $@ + echo "" >> $@ + echo ".PHONY: all" >> $@ + echo ".PRECIOUS: \$$(DEPENDECIES) \$$(OBJECTS_DIRS_MAKEFILES)" >> $@ + echo "" >> $@ + echo "all: \$$(OBJECTS_DIRS) \$$(OBJECTS)" >> $@ + echo "" >> $@ + echo "%.d:" >> $@ + echo " @echo \"\$$(shell sha1sum <<< \"\$$@\" | sed \"s/ -//g\") = \\$$\$$(shell (\\$$\$$(CXX) -MM \\$$\$$(CXXFLAGS) \$$(patsubst ../\$$(DEPTH)obj/\$$(SRCDIR)%.d,../\$$(DEPTH)src/\$$(SRCDIR)%.cpp, \$$@) 2>/dev/null || echo \\\"\$$(patsubst ../\$$(DEPTH)obj/\$$(SRCDIR)%.d,../\$$(DEPTH)src/\$$(SRCDIR)%.cpp, \$$@) FORCE\\\") | sed \\\"s/.*://g;s/\\\\\\\\\\\\\\\\//g\\\")\" >> \$$@" >> $@ + echo " @echo \"\$$(patsubst %.d,%.o, \$$@): \\$$\$$(\$$(shell sha1sum <<< \"\$$@\" | sed \"s/ -//g\"))\" >> \$$@" >> $@ + echo " @echo \" \\$$\$$(CXX) \\$$\$$(CXXFLAGS) \\$$\$$< -o \$$(patsubst %.d,%.o, \$$@)\" >> \$$@" >> $@ + echo "" >> $@ + echo "%/makefile:" >> $@ + echo " mkdir -p \$$(dir \$$@)" >> $@ + echo " cp makefile \$$@" >> $@ + echo "" >> $@ + echo "%/: FORCE | %/makefile" >> $@ + echo " @accesstime=\`stat -c %Y \$$@\` && \\" >> $@ + echo " \$$(MAKE) -C \$$@ SRCDIR=\$$(SRCDIR)\$$(notdir \$$(patsubst %/, %, \$$@))/ DEPTH=\$$(DEPTH)../ && \\" >> $@ + echo " accesstime2=\`stat -c %Y \$$@\` && \\" >> $@ + echo " if [ "\$$\$$accesstime" -ne "\$$\$$accesstime2" ]; then \\" >> $@ + echo " touch .; \\" >> $@ + echo " fi" >> $@ + echo "" >> $@ + echo "FORCE:" >> $@ + echo "" >> $@ + echo "-include \$$(DEPENDENCIES)" >> $@ + +obj/: FORCE | obj/makefile + $(MAKE) -C $@ + +$(OBJECTS): obj/ + + +build: bin/$(EXECUTABLE) + + + +clean: + $(RM) -r *.o *.d bin lib obj test-bin test-obj + +FORCE: + diff --git a/aminimize2/src/aminimize.cpp b/aminimize2/src/aminimize.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5439c355b4a78864f85fddd7ddfc141e617b8c9a --- /dev/null +++ b/aminimize2/src/aminimize.cpp @@ -0,0 +1,45 @@ +//============================================================================ +// Name : aminimize.cpp +// Author : Jan Travnicek +//============================================================================ + +#include <iostream> +#include <string> +#include <set> + +#include "exception/AlibException.h" +#include "factory/DataFactory.hpp" +#include "minimize/dfa/MinimizeDFA.h" + +int main(int argc, char** argv) { + + try { + + automaton::DFA* automatonPointer = NULL; + + if (argc == 2 && std::string("-h").compare(argv[1]) == 0) { + std::cout << "Automaton minimize.\nUsage: aminimize automaton.xml" << std::endl; + return -1; + } else if (argc == 1 || (argc == 2 && std::string("--").compare(argv[1]) == 0)) { + automatonPointer = static_cast<automaton::DFA*>(std::move(alib::DataFactory::fromStdin<automaton::DFA>()).plunder()); + } else if (argc == 2) { + automatonPointer = static_cast<automaton::DFA*>(std::move(alib::DataFactory::fromFile<automaton::DFA>(argv[1])).plunder()); + } else { + std::cout << "Automaton minimize require deterministic finite automaton" << std::endl; + return 1; + } + + automaton::DFA res = minimize::MinimizeDFA::minimize(*automatonPointer); + alib::DataFactory::toStdout(res); + + delete automatonPointer; + + return 0; + + } catch (const exception::AlibException& exception) { + alib::DataFactory::toStdout(exception); + return 1; + } catch(...) { + return 127; + } +} diff --git a/examples2/automaton/NFSM1.DET.xml b/examples2/automaton/NFSM1.DET.xml new file mode 100644 index 0000000000000000000000000000000000000000..48199ee431862e9c7855eef3a0b11b0119bd44ef --- /dev/null +++ b/examples2/automaton/NFSM1.DET.xml @@ -0,0 +1,60 @@ +<DFA> + <states> + <StringLabel>['A', 'C', 'S']</StringLabel> + <StringLabel>['A', 'S']</StringLabel> + <StringLabel>['B', 'S']</StringLabel> + <StringLabel>['S']</StringLabel> + </states> + <inputAlphabet> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + </inputAlphabet> + <initialState> + <StringLabel>['S']</StringLabel> + </initialState> + <finalStates> + <StringLabel>['A', 'C', 'S']</StringLabel> + </finalStates> + <transitions> + <transition> + <from><StringLabel>['A', 'C', 'S']</StringLabel></from> + <input><LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol></input> + <to><StringLabel>['A', 'S']</StringLabel></to> + </transition> + <transition> + <from><StringLabel>['A', 'C', 'S']</StringLabel></from> + <input><LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol></input> + <to><StringLabel>['B', 'S']</StringLabel></to> + </transition> + <transition> + <from><StringLabel>['A', 'S']</StringLabel></from> + <input><LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol></input> + <to><StringLabel>['A', 'S']</StringLabel></to> + </transition> + <transition> + <from><StringLabel>['A', 'S']</StringLabel></from> + <input><LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol></input> + <to><StringLabel>['B', 'S']</StringLabel></to> + </transition> + <transition> + <from><StringLabel>['B', 'S']</StringLabel></from> + <input><LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol></input> + <to><StringLabel>['A', 'C', 'S']</StringLabel></to> + </transition> + <transition> + <from><StringLabel>['B', 'S']</StringLabel></from> + <input><LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol></input> + <to><StringLabel>['S']</StringLabel></to> + </transition> + <transition> + <from><StringLabel>['S']</StringLabel></from> + <input><LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol></input> + <to><StringLabel>['A', 'S']</StringLabel></to> + </transition> + <transition> + <from><StringLabel>['S']</StringLabel></from> + <input><LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol></input> + <to><StringLabel>['S']</StringLabel></to> + </transition> + </transitions> +</DFA>