-
Notifications
You must be signed in to change notification settings - Fork 0
/
testfa.c
300 lines (287 loc) · 11.6 KB
/
testfa.c
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include "graph.h"
#include "fa.h"
int main(){
printf("TP4\n");
struct fa tomate;
struct fa tomate2;
struct fa tomateprod;
size_t states,alphas;
int loop=1,loop2,example,choice;
bool fa_created1=false;
bool fa_created2=false;
bool fa_createdprod=false;
printf("################################################################\n");
printf("# #\n");
printf("# TL fa-manager(0.6.2) #\n");
printf("# #\n");
printf("# !!! Warning there is no input check, follow instructions !!! #\n");
printf("# !!! Do not put any letter when not prompt to !!! #\n");
printf("# #\n");
printf("################################################################\n");
while(loop == 1){
printf("################################################################\n");
printf("# #\n");
printf("# 1 : Create Automate #\n");
printf("# 2 : Create Second Automate (For Product) #\n");
printf("# 3 : Display Automate #\n");
printf("# 4 : Display Production Automate #\n");
printf("# 5 : Modify Automate #\n");
printf("# 6 : Delete Automate #\n");
printf("# 7 : Quit (and delete Automate) #\n");
printf("# #\n");
printf("################################################################\n");
printf("Your Choice :");
scanf("%d", &choice);
switch(choice){
case 1:
if(fa_created1==true){
printf("Automate already created, destroy it before creating a other one\n");
} else {
printf("Do you want a example automate (from the TP subject) ?(1/0)");
scanf("%d", &example);
if (example==1) {
fa_create(&tomate,2,5);
fa_set_state_initial(&tomate, 0);
fa_set_state_initial(&tomate, 1);
fa_set_state_final(&tomate, 4);
fa_add_transition(&tomate, 0, 'a', 1);
fa_add_transition(&tomate, 0, 'a', 2);
fa_add_transition(&tomate, 0, 'a', 3);
fa_add_transition(&tomate, 1, 'b', 3);
fa_add_transition(&tomate, 2, 'a', 3);
fa_add_transition(&tomate, 2, 'b', 4);
fa_add_transition(&tomate, 3, 'a', 3);
fa_add_transition(&tomate, 3, 'b', 4);
fa_add_transition(&tomate, 4, 'a', 4);
} else {
printf("How many states do you want ?");
scanf("%zu", &states);
printf("How many alpha's do you want ?");
scanf("%zu", &alphas);
fa_create(&tomate, alphas, states);
}
fa_created1 = true;
}
break;
case 2:
if(fa_created2==true){
printf("Automate already created, destroy it before creating a other one\n");
} else {
printf("Do you want a example automate (from the TP subject) ?(1/0)");
scanf("%d", &example);
if (example==1) {
fa_create(&tomate2,2,5);
fa_set_state_initial(&tomate2, 0);
fa_set_state_initial(&tomate2, 1);
fa_set_state_final(&tomate2, 4);
fa_add_transition(&tomate2, 0, 'a', 1);
fa_add_transition(&tomate2, 0, 'a', 2);
fa_add_transition(&tomate2, 0, 'a', 3);
fa_add_transition(&tomate2, 1, 'b', 3);
fa_add_transition(&tomate2, 2, 'a', 3);
fa_add_transition(&tomate2, 2, 'b', 4);
fa_add_transition(&tomate2, 3, 'a', 3);
fa_add_transition(&tomate2, 3, 'b', 4);
fa_add_transition(&tomate2, 4, 'a', 4);
} else {
printf("How many states do you want ?");
scanf("%zu", &states);
printf("How many alpha's do you want ?");
scanf("%zu", &alphas);
fa_create(&tomate2, alphas, states);
}
fa_created2 = true;
}
break;
case 3:
if(fa_created1==false){
printf("No Production has been done, do one before displaying it\n");
} else {
printf("The Automate has %zu transition(s)\n",fa_count_transitions(&tomate));
if(fa_is_deterministic(&tomate)) {
printf("The Automate is deterministic\n");
}else{
printf("The Automate isn't deterministic\n");
}
if(fa_is_complete(&tomate)) {
printf("The Automate is complete\n");
}else{
printf("The Automate isn't complete\n");
}
if(fa_is_language_empty(&tomate)) {
printf("The Automate has an empty language\n");
}else{
printf("The Automate doesn't have an empty language\n");
}
fa_pretty_print(&tomate,stdout);
}
break;
case 4:
if(fa_createdprod==false){
printf("No Automate has been created, create it before displaying it\n");
} else {
printf("The Automate has %zu transition(s)\n",fa_count_transitions(&tomateprod));
if(fa_is_deterministic(&tomateprod)) {
printf("The Automate is deterministic\n");
}else{
printf("The Automate isn't deterministic\n");
}
if(fa_is_complete(&tomateprod)) {
printf("The Automate is complete\n");
}else{
printf("The Automate isn't complete\n");
}
if(fa_is_language_empty(&tomateprod)) {
printf("The Automate has an empty language\n");
}else{
printf("The Automate doesn't have an empty language\n");
}
if(fa_has_empty_intersection(&tomate,&tomate2)) {
printf("The Automates have an empty intersection\n");
}else{
printf("The Automates doesn't have an empty intersection\n");
}
fa_pretty_print(&tomateprod,stdout);
}
break;
case 5:
loop2=1;
int choice2;
size_t s1,s2;
char alpha;
if(fa_created1==false){
printf("No Automate has been created, create it before modifying it\n");
} else {
while(loop2==1) {
printf("#################################################################\n");
printf("# #\n");
printf("# 0 : Add Transition #\n");
printf("# 1 : Remove Transition #\n");
printf("# 2 : Add Initial State #\n");
printf("# 3 : Add Final State #\n");
printf("# 4 : Make Complete #\n");
printf("# 5 : Merge States #\n");
printf("# 6 : Remove State #\n");
printf("# 7 : Remove non accessible states #\n");
printf("# 8 : Remove non co-accessible states(not working) #\n");
printf("# 9 : Product of two automates #\n");
printf("# 10 : Go Back #\n");
printf("# #\n");
printf("#################################################################\n");
choice2 = 0;
printf("Your Choice :");
scanf("%d", &choice2);
switch (choice2) {
case 0:
printf("State from ?(0,1,...)");
scanf("%zu", &s1);
printf("With which letter ?(a,b,...)");
scanf("%s", &alpha);
printf("State to ?(0,1,...)");
scanf("%zu", &s2);
fa_add_transition(&tomate,s1,alpha,s2);
break;
case 1:
printf("State from ?(0,1,...)");
scanf("%zu", &s1);
printf("With which letter ?(a,b,...)");
scanf("%s", &alpha);
printf("State to ?(0,1,...)");
scanf("%zu", &s2);
fa_remove_transition(&tomate,s1,alpha,s2);
break;
case 2:
printf("Initial state ?(0,1,...)");
scanf("%zu", &s1);
fa_set_state_initial(&tomate,s1);
break;
case 3:
printf("Final state ?(0,1,...)");
scanf("%zu", &s1);
fa_set_state_final(&tomate,s1);
break;
case 4:
printf("Completing ...\n");
fa_make_complete(&tomate);
break;
case 5:
printf("First State to merge ?(0,1,...)");
scanf("%zu", &s1);
printf("Second State to merge ?(0,1,...)");
scanf("%zu", &s2);
fa_merge_states(&tomate,s1,s2);
break;
case 6:
printf("State to remove ?(0,1,...)");
scanf("%zu", &s1);
fa_remove_state(&tomate,s1);
break;
case 7:
fa_remove_non_accessible_states(&tomate);
break;
case 8:
fa_remove_non_co_accessible_states(&tomate);
loop2 = 0;
break;
case 9:
fa_create_product(&tomateprod,&tomate,&tomate2);
fa_createdprod=true;
loop2 = 0;
break;
case 10:
loop2 = 0;
break;
default:
printf("Restart menu and choose a number between 1 and 8\n");
loop2=0;
break;
}
}
}
break;
case 6:
if(fa_created1==false){
printf("No Automate has been created, create it before deleting it\n");
} else {
printf("Deleting ...\n");
fa_created1 = false;
fa_destroy(&tomate);
}
break;
case 7:
printf("Exiting ...\n");
if(fa_created1==true){
fa_destroy(&tomate);
}
loop=0;
break;
default:
printf("Restart menu and choose a number between 1 and 5\n");
loop=0;
break;
}
}
return 0;
/*struct fa tomateleft;
fa_create(&tomateleft,2,2);
fa_set_state_initial(&tomateleft, 0);
fa_set_state_final(&tomateleft, 1);
fa_add_transition(&tomateleft, 0, 'a', 1);
fa_add_transition(&tomateleft, 1, 'a', 1);
fa_add_transition(&tomateleft, 1, 'b', 1);
struct fa tomateright;
fa_create(&tomateright,2,2);
fa_set_state_initial(&tomateright, 0);
fa_set_state_final(&tomateright, 1);
fa_add_transition(&tomateright, 0, 'a', 0);
fa_add_transition(&tomateright, 0, 'b', 1);
fa_add_transition(&tomateright, 1, 'b', 1);
fa_add_transition(&tomateright, 1, 'a', 0);
struct fa tomatefinal;
fa_create_product(&tomatefinal, &tomateleft, &tomateright);
//fa_has_empty_intersection(&tomateleft, &tomateright);
fa_pretty_print(&tomatefinal, stdout);*/
}