-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.cpp
175 lines (147 loc) · 4.93 KB
/
Test.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <iostream>
#include "MarkovMonoid.hpp"
#include "ExplicitAutomaton.hpp"
#include "Output.hpp"
//#include "StabilisationMonoid.hpp"
#include "MultiMonoid.hpp"
#include "Parser.hpp"
#include "StarHeight.hpp"
#include <fstream>
#include <sstream>
#include <math.h>
#ifdef MSVC
#include <windows.h>
#include <time.h>
#else
#include <unistd.h>
#endif
using namespace std;
void pusage(char* s)
{
cerr << "Usage: " << s << " [-v] [-o dot_output_file] input_file" << endl;
exit(-1);
}
int main(int argc, char **argv)
{
int opt,verbose=0,toOut=0;
ifstream ifs;
string outputFilename;
#ifndef WIN32
while((opt = getopt(argc,argv, "vho:")) != -1)
{
switch(opt)
{
case 'h':
pusage(argv[0]);
case 'v':
verbose = 1;
break;
case 'o':
toOut=1;
outputFilename = optarg;
break;
default:
pusage(argv[0]);
}
}
if (optind >= argc)
{
cerr << "Expected file" << endl;
pusage(argv[0]);
}
ifs.open(argv[optind]);
if(ifs.fail())
{
cerr << "Could not open file " << argv[optind] << endl;
pusage(argv[0]);
}
#endif
ExplicitAutomaton* expa = Parser::parseFile(ifs);
ifs.close();
if(expa->type==PROB)
{
cout << endl << endl << "The input automaton is a probabilistic automaton. Stamina will construct the Markov Monoid to check whether it has value 1." << endl << endl ;
UnstableMarkovMonoid m(*expa);
m.setWitnessTest(&(m.value1Test));
auto expr = m.ComputeMonoid();
cout << "***************************************" << endl;
cout << "***********MAIN RESULTS****************" << endl;
cout << "***************************************" << endl << endl;
pair<int, const ExtendedExpression*> r = m.maxLeakNb();
if(r.first == 0){
cout << "No leak found: the automaton is leaktight." << endl;
if (expr) {
cout << "The automaton has value 1; a witness is ";
expr->print();
cout << endl << endl;
}
else cout << "No value 1 witness found: the automaton does not have value 1." << endl << endl;
}
else{
cout << "A leak was found: the automaton is not leaktight." << endl;
if (expr) {
cout << "The automaton has value 1; a witness is ";
expr->print();
cout << endl << endl;
}
else cout << "No value 1 witness found: the automaton may or may not have value 1." << endl << endl;
}
if(verbose){
cout << "***************************************" << endl;
cout << "***********VERBOSE MODE****************" << endl;
cout << "***************************************" << endl << endl;
m.print();
cout << endl;
}
if(toOut) {
ofstream ofs(outputFilename + ".dot");
ofs << Dot::toDot(expa,&m, -1);
}
}
else if (expa->type==CLASSICAL)
{
ClassicAut aut(*expa);
if(!aut.isdet()) {
cout << "Only deterministic automata are handled" << endl;
return 0;
}
//outputs
UnstableMultiMonoid * monoid = NULL;
const ExtendedExpression * witness = NULL;
int loopComplexity = 0;
auto h = computeStarHeight(aut, monoid, witness, loopComplexity, true, true);
cout << "RESULT: the star height is " << h << "." << endl;
if(toOut) {
ofstream ofs(outputFilename + ".dot");
ofs << Dot::toDot(expa,monoid, -1);
}
delete expa; expa = NULL;
delete monoid; monoid = NULL;
}
else if (expa->type > 0)
{
UnstableMultiMonoid m(* expa);
const ExtendedExpression * expr = m.ComputeMonoid();
if(expr == NULL)
{
cout << endl << endl << "RESULT: This automaton is LIMITED, its monoid contains No UNLIMITED WITNESS." << endl << endl;
}
else
{
cout << endl << endl << "RESULT: This automaton is NOT LIMITED, its monoid contains the following UNLIMITED WITNESS:" << endl;
cout << *expr << endl;
}
if(verbose){
cout << "***************************************" << endl;
cout << "***********VERBOSE MODE****************" << endl;
cout << "***************************************" << endl << endl;
m.print();
cout << endl;
}
if(toOut) {
ofstream ofs(outputFilename + ".dot");
ofs << Dot::toDot(expa,&m, -1);
}
}
return 0;
}