-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
449 lines (442 loc) · 18.4 KB
/
main.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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
#include<stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "cnf.h"
#include "takudo.h"
#include "takudoGeneretor.h"
int main()
{
//const char *fileName = "D:/syx/程序设计综合课程设计任务及指导学生包/SAT测试备选算例/满足算例/M/sud00012.cnf";
//const char *fileName = "D:/syx/程序设计综合课程设计任务及指导学生包/SAT测试备选算例/满足算例/S/problem1-20.cnf";
// const char *fileName = "D:/syx/程序设计综合课程设计任务及指导学生包/SAT测试备选算例/满足算例/L/par16-1.cnf";
char fileName[999];
int flag = -1;
init();
printf("\n");
while(1)
{
system("cls");
printf(" Menu for Sudoku or SAT\n");
printf("---------------------------------------------------------------------------\n");
printf(" 1.SAT 2.Sudoku\n");
printf(" 0.Exit\n");
printf("----------------------------------------------------------------------------\n");
scanf("%d",&flag);
if(flag == 1)
{
system("cls");
printf("\n");
printf(" Menu for SAT 数据集\n");
printf("---------------------------------------------------------------\n");
printf(" 1.小型数据集 2.中型数据集\n");
printf(" 3.大型数据集 4.基准数据集\n");
printf(" 5.不满足数据集 6.自选数据集\n");
printf("----------------------------------------------------------------\n");
int k;
scanf("%d",&k);
system("cls");
if(k == 1 || k == 2 || k == 3)
{
printf("\n");
printf("现有5个对应数据集,请输入1-5选择你要选择的文件:(5个文件的难度基本相同)\n");
int m;
scanf("%d",&m);
m--;
system("cls");
if(k == 1)
{
int flag2 = 0;
while(1)
{
system("cls");
printf(" Menu for 操作\n");
printf("-------------------------------------------------\n");
printf(" 1.遍历CNF 2.进行求解\n");
printf(" 3.计算优化率 4.返回\n");
int choose;
struct clauseSet myClauseSet = readCnf(smallFile[m]);
scanf("%d",&choose);
if(choose == 1)
{
traverse(myClauseSet);
system("pause");
}
if(choose == 2)
{
struct result myResult;
myResult = DPLL(myClauseSet);
showResult(myResult);
system("pause");
}
if(choose == 3)
{
clock_t t,t1,t2;
struct result myResult;
t = clock();
myResult = DPLL(myClauseSet);
t1 = clock();
double timeTaken = 1000*((double)(t1-t))/CLOCKS_PER_SEC; // in milliseconds
printf("\nDPLL1 耗时: %f ms\n", timeTaken);
myClauseSet = readCnf(smallFile[m]);
t = clock();
myResult = DPLL2(myClauseSet);
t2 = clock();
double timeTaken2 = 1000*((double)(t2 - t))/CLOCKS_PER_SEC;
printf("DPLL2 耗时: %f ms\n", timeTaken2);
double youhualv = (1.0 -timeTaken / timeTaken2) * 100;
printf("优化率为%.2f%%\n",youhualv);
system("pause");
}
if(choose == 4)
{
flag2 =1 ;
break;
}
}
if(flag2 == 1) continue;
}
if(k == 2)
{
int flag2 = 0;
while(1)
{
system("cls");
printf(" Menu for 操作\n");
printf("-------------------------------------------------\n");
printf(" 1.遍历CNF 2.进行求解\n");
printf(" 3.计算优化率 4.返回\n");
int choose;
struct clauseSet myClauseSet = readCnf(midFile[m]);
scanf("%d",&choose);
if(choose == 1)
{
traverse(myClauseSet);
system("pause");
}
if(choose == 2)
{
struct result myResult;
myResult = DPLL(myClauseSet);
showResult(myResult);
system("pause");
}
if(choose == 3)
{
clock_t t,t1,t2;
struct result myResult;
t = clock();
myResult = DPLL(myClauseSet);
t1 = clock();
double timeTaken = 1000*((double)(t1-t))/CLOCKS_PER_SEC; // in milliseconds
printf("\nDPLL1 耗时: %f ms\n", timeTaken);
myClauseSet = readCnf(midFile[m]);
t = clock();
myResult = DPLL2(myClauseSet);
t2 = clock();
double timeTaken2 = 1000*((double)(t2 - t))/CLOCKS_PER_SEC;
printf("DPLL2 耗时: %f ms\n", timeTaken2);
double youhualv = (1.0 -timeTaken / timeTaken2) * 100;
printf("优化率为%.2f%%\n",youhualv);
system("pause");
}
if(choose == 4)
{
flag2 =1 ;
break;
}
}
if(flag2 == 1) continue;
}
if(k == 3)
{
int flag2 = 0;
while(1)
{
system("cls");
printf(" Menu for 操作\n");
printf("-------------------------------------------------\n");
printf(" 1.遍历CNF 2.进行求解\n");
printf(" 3.计算优化率 4.返回\n");
int choose;
struct clauseSet myClauseSet = readCnf(largeFile[m]);
scanf("%d",&choose);
if(choose == 1)
{
traverse(myClauseSet);
system("pause");
}
if(choose == 2)
{
struct result myResult;
myResult = DPLL(myClauseSet);
showResult(myResult);
system("pause");
}
if(choose == 3)
{
clock_t t,t1,t2;
struct result myResult;
t = clock();
myResult = DPLL(myClauseSet);
t1 = clock();
double timeTaken = 1000*((double)(t1-t))/CLOCKS_PER_SEC; // in milliseconds
printf("\nDPLL1 耗时: %f ms\n", timeTaken);
myClauseSet = readCnf(midFile[m]);
printf("优化率为100%%\n");
system("pause");
}
if(choose == 4)
{
flag2 =1 ;
break;
}
}
if(flag2 == 1) continue;
}
}
else if( k == 4)
{
int flag2 = 0;
printf("数字1-2为功能测试算例、3-4为性能测试算例\n");
printf("请输入对应数字\n");
int m;
scanf("%d",&m);
m--;
while(1)
{
system("cls");
printf(" Menu for 操作\n");
printf("-------------------------------------------------\n");
printf(" 1.遍历CNF 2.进行求解且记录时间\n");
printf(" 3.返回\n");
int choose;
struct clauseSet myClauseSet = readCnf(baseFuncFile[m]);
scanf("%d",&choose);
if(choose == 1)
{
traverse(myClauseSet);
system("pause");
}
if(choose == 2)
{
struct result myResult;
clock_t t,t1;
t = clock();
myResult = DPLL(myClauseSet);
t1 = clock();
showResult(myResult);
double timeTaken = 1000*((double)(t1-t))/CLOCKS_PER_SEC; // in milliseconds
printf("\nDPLL1 耗时: %f ms\n", timeTaken);
system("pause");
}
if(choose == 3)
{
flag2 =1 ;
break;
}
}
if(flag2 == 1) continue;
}
else if(k == 5)
{
int flag2 = 0;
printf("共提供4个不满足算例\n");
printf("请输入对应数字1-4\n");
int m;
scanf("%d",&m);
m--;
while(1)
{
system("cls");
printf(" Menu for 操作\n");
printf("-------------------------------------------------\n");
printf(" 1.遍历CNF 2.进行求解且记录时间\n");
printf(" 3.计算优化率 4.返回\n");
int choose;
struct clauseSet myClauseSet = readCnf(unSatisFile[m]);
scanf("%d",&choose);
if(choose == 1)
{
traverse(myClauseSet);
system("pause");
}
if(choose == 2)
{
struct result myResult;
clock_t t,t1;
t = clock();
myResult = DPLL(myClauseSet);
t1 = clock();
if(myResult.state == 0)
{
printf("该算例为不满足算例\n");
}
double timeTaken = 1000*((double)(t1-t))/CLOCKS_PER_SEC; // in milliseconds
printf("\nDPLL1 耗时: %f ms\n", timeTaken);
system("pause");
}
if(choose == 3)
{
clock_t t,t1,t2;
struct result myResult;
t = clock();
myResult = DPLL(myClauseSet);
t1 = clock();
double timeTaken = 1000*((double)(t1-t))/CLOCKS_PER_SEC; // in milliseconds
printf("\nDPLL1 耗时: %f ms\n", timeTaken);
myClauseSet = readCnf(unSatisFile[m]);
t = clock();
myResult = DPLL2(myClauseSet);
t2 = clock();
double timeTaken2 = 1000*((double)(t2 - t))/CLOCKS_PER_SEC;
printf("DPLL2 耗时: %f ms\n", timeTaken2);
double youhualv = (1.0 -timeTaken / timeTaken2) * 100;
printf("优化率为%.2f%%\n",youhualv);
if(myResult.state == 0)
{
printf("该算例为不满足算例\n");
}
system("pause");
}
if(choose == 4)
{
flag2 =1 ;
break;
}
}
if(flag2 == 1) continue;
}
else
{
int flag2 = 0;
printf("请输入对应路径\n");
scanf("%s",fileName);
while(1)
{
system("cls");
printf(" Menu for 操作\n");
printf("-------------------------------------------------\n");
printf(" 1.遍历CNF 2.进行求解\n");
printf(" 3.计算优化率 4.返回\n");
int choose;
struct clauseSet myClauseSet = readCnf(fileName);
scanf("%d",&choose);
if(choose == 1)
{
traverse(myClauseSet);
system("pause");
}
if(choose == 2)
{
struct result myResult;
myResult = DPLL(myClauseSet);
showResult(myResult);
system("pause");
}
if(choose == 3)
{
clock_t t,t1,t2;
struct result myResult;
t = clock();
myResult = DPLL(myClauseSet);
t1 = clock();
double timeTaken = 1000*((double)(t1-t))/CLOCKS_PER_SEC; // in milliseconds
printf("\nDPLL1 耗时: %f ms\n", timeTaken);
myClauseSet = readCnf(fileName);
t = clock();
myResult = DPLL2(myClauseSet);
t2 = clock();
double timeTaken2 = 1000*((double)(t2 - t))/CLOCKS_PER_SEC;
printf("DPLL2 耗时: %f ms\n", timeTaken2);
double youhualv = (1.0 -timeTaken / timeTaken2) * 100;
printf("优化率为%.2f%%\n",youhualv);
system("pause");
}
if(choose == 4)
{
flag2 =1 ;
break;
}
}
if(flag2 == 1) continue;
}
break;
}
else if(flag == 2)
{
int flag2 = 0;
while(1)
{
system("cls");
printf("----------------------------------------\n");
printf(" 欢迎使用本数独生成器、求解器 \n");
printf(" 1.自动生成数独进行数独游戏\n");
printf(" 2.读取已知数独进行数独游戏\n");
printf(" 3.返回\n");
printf("----------------------------------------\n");
int choose;
scanf("%d",&choose);
if(choose == 1)
{
system("cls");
int jieshu;
printf("选择生成数独的阶数(10阶以内):\n");
scanf("%d",&jieshu);
char *myGeneretorAddress = generator(jieshu);
showInitialTakudo(myGeneretorAddress,jieshu);
printf("输入任意键查看答案\n");
system("pause");
char *filef = convertToCnf(myGeneretorAddress);
struct result myResult;
struct clauseSet myClauseSet = readCnf(filef);
myResult = DPLL(myClauseSet);
showResulttotakudo(myResult,jieshu);
system("pause");
}
else if(choose == 2)
{
int jieshu;
printf("选择输入数独的阶数:");
scanf("%d",&jieshu);
char myGeneratorAddress[999];
printf("输入数独路径:");
scanf("%s",myGeneratorAddress);
showOriginTakudo(myGeneratorAddress,jieshu);
printf("输入任意键查看答案\n");
system("pause");
char *filef = convertToCnf(myGeneratorAddress);
struct result myResult;
struct clauseSet myClauseSet = readCnf(filef);
myResult = DPLL(myClauseSet);
showResulttotakudo(myResult,jieshu);
system("pause");
}
else if(choose == 3)
{
flag2 = 1;
break;
}
else
{
printf("请输入正确的数字\n");
}
}
if(flag2 == 1) continue;
}
else if(flag == 0)
{
printf("欢迎你下次使用本求解器\n");
system("pause");
return 0;
}
else
{
printf("请输入正确的数字\n");
system("pause");
continue;
}
}
system("pause");
return 0;
}