-
Notifications
You must be signed in to change notification settings - Fork 1
/
TLMain.cpp
252 lines (215 loc) · 7.13 KB
/
TLMain.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/*
* File: Main.cc
* Project: QUEST
* Author: Axel Hirche, Marc Diefenbruch
* Date: (C) 1997, 1998 University of Essen, Germany
*/
//#include <string.h>
#include "SCL/SCStream.h"
#include "TL.h"
#include "TLFormula.h"
#include "TLFormulaNOT.h"
#include "TLFormulaSet.h"
#include "TLParser.h"
#include "TLState.h"
#include "TLStateList.h"
#include "TLNode.h"
#include "TLBuechi.h"
#include "TLHelp.h"
#include "SCL/SCListIter.h"
#if _SC_DMALLOC
#include <dmalloc.h>
#endif
SCBoolean a (void)
{
return true;
}
SCBoolean b (void)
{
return false;
}
SCBoolean c (void)
{
return false;
}
SCBoolean d (void)
{
return true;
}
SCBoolean e (void)
{
return false;
}
SCBoolean f (void)
{
return true;
}
SCBoolean g (void)
{
return false;
}
SCBoolean h (void)
{
return true;
}
void PrintHelp (char* myName)
{
cerr << "usage: " << myName << " [-a|-d|-g|-e|-n|-s|-x]* \"<formula>\"" << endl;
cerr << " -a when comparing states, use only the atomic propositions" << endl;
cerr << " in NOW for comparison." << endl;
cerr << " -d When displaying states, display only the atomic propositions" << endl;
cerr << " in NOW." << endl;
cerr << " -e Do not insert T (true) into formula sets, i.e. treat {T} as {}." << endl;
cerr << " -f Same as \"-a -d -g -e -s -x\"" << endl;
cerr << " -g Construct the links between the states in such a way that the" << endl;
cerr << " automaton will reach an acepting state as quickly as possible." << endl;
cerr << " -h Display this message." << endl;
cerr << " -n Automatically prepend a not (~) to the formula." << endl;
cerr << " -s Use some simple equivalences to simplify the formula, e.g." << endl;
cerr << " <><>a <-> <>a, or a && ~a <-> F." << endl;
cerr << " -x Construct automaton that can handle <>, [], W and Z without" << endl;
cerr << " rewriting the formula." << endl << endl;
cerr << "Valid values for atomic propositions are the letters \"a\" through \"h\"" << endl;
cerr << "and the values \"F\" for false and \"T\" for true." << endl;
cerr << "Valid operators are ~, X, <>, [], ->, <->, U, V, W, Z, ||, &&." << endl;
cerr << "example: " << myName << " -a -x \"a U b\"" << endl;
}
int main (int argc, char** argv)
{
char* phiStr;
SCBoolean trueEquivEmpty = false;
SCBoolean nowIsPureAtomic = false;
SCBoolean nowDisplaysOnlyAtomics = false;
SCBoolean extendedAutomaton = false;
SCBoolean simplifyFormulae = false;
SCBoolean greedyAutomaton = false;
SCBoolean autoNegate = false;
SCName2PropFuncPtr *name2Func = new SCName2PropFuncPtr[8];
TLBuechi* myBuechi = NULL;
if (argc > 1) // At least program name and formula.
{
for (int i = 1; i < argc ; i++) // Ignore argv[0], which is program name.
{
assert (argv[i]);
if (*argv[i] == '-') // It is an option.
{
if (strlen (argv[i]) != 2) // Option syntax is -<letter>
{
cerr << "unrecognized option: " << argv[i] << endl;
exit (-1);
}
if (*(argv[i] + 1) == 'h') // User wants help...
{
PrintHelp(argv[0]);
exit (0);
}
switch (*(argv[i] + 1)) // Use the 2nd character.
{
case 'e': // trueEquivEmpty
trueEquivEmpty = true;
break;
case 'd': // nowDisplaysOnlyAtomics
nowDisplaysOnlyAtomics = true;
break;
case 'a': // nowIsPureAtomic
nowIsPureAtomic = true;
break;
case 'x': // extendedAutomaton
extendedAutomaton = true;
break;
case 's': // simplifyFormulae
simplifyFormulae = true;
break;
case 'g': // greedyAutomaton
greedyAutomaton = true;
break;
case 'n': // autoNegate
autoNegate = true;
break;
case 'f':
trueEquivEmpty = true;
nowDisplaysOnlyAtomics = true;
nowIsPureAtomic = true;
extendedAutomaton = true;
simplifyFormulae = true;
greedyAutomaton = true;
break;
case 'h': // Can't do that babe ;-)
cerr << "can't mix -h with other options!" << endl;
exit (-1);
break;
default:
cerr << "unrecognized option: " << argv[i] << endl;
exit (-1);
break;
}
}
else // The formula.
{
phiStr = StrDup (argv[i]);
}
}
}
else
{
cerr << "usage: " << argv[0] << " [-a|-d|-g|-e|-n|-s|-x]* \"<formula>\"" << endl;
cerr << "for help type " << argv[0] << " -h" << endl;
exit (-1);
}
name2Func[0].name = "a"; // Translation table
name2Func[0].Evaluate = a; // for translation from
name2Func[1].name = "b"; // names to proposition
name2Func[1].Evaluate = b; // functions.
name2Func[2].name = "c";
name2Func[2].Evaluate = c;
name2Func[3].name = "d";
name2Func[3].Evaluate = d;
name2Func[4].name = "e";
name2Func[4].Evaluate = e;
name2Func[5].name = "f";
name2Func[5].Evaluate = f;
name2Func[6].name = "g";
name2Func[6].Evaluate = g;
name2Func[7].name = "h";
name2Func[7].Evaluate = h;
myBuechi = new TLBuechi (phiStr,
name2Func,
8,
trueEquivEmpty,
nowIsPureAtomic,
nowDisplaysOnlyAtomics,
extendedAutomaton,
simplifyFormulae,
greedyAutomaton,
autoNegate);
{
SCNatural numOfTrans = 0;
SCNatural numOfBogusAccept = 0;
SCNatural numOfReallyAccept = 0;
SCListIter<TLState> myIter (*myBuechi->GetStateList());
TLState* tmpState;
for (tmpState = myIter++; tmpState; tmpState = myIter++)
{
numOfTrans += tmpState->GetOutEdges()->NumOfElems();
if (tmpState->IsAcceptingState())
{
if (tmpState->isReallyAccepting)
numOfReallyAccept++;
else
numOfBogusAccept++;
}
}
cout << myBuechi->GetNumOfStates();
cout << '\t' << numOfTrans;
cout << '\t' << myBuechi->GetNumOfAcceptanceSets();
cout << '\t' << numOfReallyAccept;
cout << '\t' << numOfBogusAccept << endl;
}
// cout << "myBuechi->GetReferenceAcceptanceSet() == ";
// ShowBits (cout, myBuechi->GetReferenceAcceptanceSet());
// cout << endl;
delete myBuechi;
delete[] name2Func;
delete[] phiStr;
return 0;
}