-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
92 lines (69 loc) · 2.73 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
CSE355 optional project, main.cpp
Purpose: Takes an automaton from an input file and converts it to a DFA
if its an NFA then generates a compliment of that new DFA and finds the
shortest string in the new DFA.
@author Suhail Ghafoor
@version 0.2 04/04/18
*/
#include <iostream>
#include <fstream>
#include "Parser.h"
#include "Automaton.h"
#include "Intersector.h"
#include "helper.h"
using namespace std;
/*
* Config box begin, change settings here.
*/
// I/O
bool takeInputFromFile = true;
string inputFilePath = "/Users/Suhail/Documents/University/CSE355/Optional Project/project files/m3test.txt";
// Other settings
bool printEpsilonInsteadOfEmptyString = true;
bool nicefyNames = true;
string deadStateName = "Dead-State";
/*
* Config box end
*/
int main() {
ifstream in(inputFilePath);
if(takeInputFromFile) {
cin.rdbuf(in.rdbuf());
}
//make parser for both specifications so we can read it from input
auto * specificationAutomaton = new Parser();
auto * systemAutomaton = new Parser();
//fills up parser from given input file
readLines(specificationAutomaton, systemAutomaton);
//this class turns NFA to DFA if required and also a tuple which
// is used by the graph
auto * specification = new Automaton(specificationAutomaton, deadStateName, printEpsilonInsteadOfEmptyString);
auto * system = new Automaton(systemAutomaton, deadStateName, printEpsilonInsteadOfEmptyString);
//get tuple from specifications
auto * specTuple = specification->giveTuple();
auto * systemTuple = system->giveTuple();
//print the specs and system to a js file before it is altered by the intersector
jsonPrint(specTuple, "specNormal.js");
jsonPrint(systemTuple, "system.js");
//make the new intersected dfa and find the shortest string
auto * intersected = new Intersector(specTuple, systemTuple, nicefyNames);
auto * dfa = new DFA(intersected->giveIntersected());
string shortest = dfa->giveShortestString();
//print the new specs and the intersected tuple to a file
jsonPrint(specTuple, "specs.js");
jsonPrint(intersected->giveIntersected(), "intersected.js");
//output to console
if(shortest.empty() || shortest == "Not yet traversed"){
cout << "The system satisfies the specification!";
} else{
cout << "The system does not satisfy the specification!" << endl;
cout << "The counterexample that demonstrates that the specification does not hold is: " << shortest;
}
freopen("1210107207_Milestone2_str.txt","w",stdout);
cout << "Shortest string: ";
cout << shortest;
freopen("1210107207_Milestone2_M.txt","w",stdout);
printMachine(intersected->giveIntersected());
return 0;
}