-
Notifications
You must be signed in to change notification settings - Fork 0
/
sat13.c
3595 lines (3179 loc) · 66.9 KB
/
sat13.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
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define o mems++
#define oo mems+= 2
#define ooo mems+= 3
#define O "%"
#define mod % \
#define show_basics 1
#define show_choices 2
#define show_details 4
#define show_gory_details 8
#define show_warmlearn 16 \
#define show_recycling 32
#define show_recycling_details 64 \
#define show_restarts 128
#define show_initial_clauses 256 \
#define show_watches 512
#define show_experiments 4096 \
#define vars_per_vchunk 341 \
#define cells_per_chunk 511 \
#define hack_in(q,t) (tmp_var*) (t|(ullng) q) \
#define size(c) mem[(c) -1].lit
#define link0(c) mem[(c) -2].lit
#define link1(c) mem[(c) -3].lit
#define clause_extra 3
#define sign_bit 0x80000000
#define range(c) mem[(c) -4].lit
#define activ(c) mem[(c) -5].flt
#define activ_as_lit(c) ((ullng) mem[(c) -5].lit<<32)
#define learned_supplement 2 \
#define learned_extra (clause_extra+learned_supplement) \
#define bar(l) ((l) ^1)
#define thevar(l) ((l) >>1)
#define litname(l) (l) &1?"~":"",vmem[thevar(l) ].name.ch8
#define poslit(v) ((v) <<1)
#define neglit(v) (((v) <<1) +1)
#define unset 0xffffffff
#define isknown(l) (vmem[thevar(l) ].value!=unset)
#define iscontrary(l) ((vmem[thevar(l) ].value^(l) ) &1) \
#define sanity_checking 0 \
#define two_to_the_32 4294967296.0 \
#define memk_max_default 26 \
#define hack_out(q) (((ullng) q) &0x3)
#define hack_clean(q) ((tmp_var*) ((ullng) q&-4) ) \
#define two_to_the_31 ((unsigned long) 0x80000000) \
#define tiny 2.225073858507201383e-308 \
\
#define single_tiny 1.1754943508222875080e-38 \
\
#define buckets 256
#define badlevel 16.0 \
/*2:*/
#line 93 "sat13.w"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gb_flip.h"
typedef unsigned int uint;
typedef unsigned long long ullng;
/*9:*/
#line 384 "sat13.w"
typedef union{
char ch8[8];
uint u2[2];
ullng lng;
}octa;
typedef struct tmp_var_struct{
octa name;
uint serial;
int stamp;
struct tmp_var_struct*next;
}tmp_var;
typedef struct vchunk_struct{
struct vchunk_struct*prev;
tmp_var var[vars_per_vchunk];
}vchunk;
/*:9*//*10:*/
#line 411 "sat13.w"
typedef struct chunk_struct{
struct chunk_struct*prev;
tmp_var*cell[cells_per_chunk];
}chunk;
/*:10*//*28:*/
#line 848 "sat13.w"
typedef union{
uint lit;
float flt;
}cel;
/*:28*//*29:*/
#line 876 "sat13.w"
typedef struct{
octa name;
double activity;
uint value;
int tloc;
int hloc;
uint oldval;
uint stamp;
uint filler;
}variable;
/*:29*//*30:*/
#line 892 "sat13.w"
typedef struct{
int reason;
uint watch;
uint bimp_start;
uint bimp_end;
}literal;
/*:30*/
#line 100 "sat13.w"
;
/*4:*/
#line 218 "sat13.w"
int random_seed= 0;
int verbose= show_basics;
uint show_choices_max= 1000000;
int hbits= 8;
int print_state_cutoff= 0;
int buf_size= 1024;
FILE*out_file;
char*out_name;
FILE*restart_file;
char*restart_name;
FILE*learned_file;
char*learned_name;
int learn_save= 10000;
ullng learned_out;
FILE*polarity_infile;
char*polarity_in_name;
FILE*polarity_outfile;
char*polarity_out_name;
ullng imems,mems;
ullng bytes;
ullng nodes;
ullng thresh= 0;
ullng delta= 0;
ullng timeout= 0x1fffffffffffffff;
uint memk_max= memk_max_default;
uint max_cells_used;
int trivial_limit= 10;
float var_rho= 0.9;
float clause_rho= 0.9995;
float rand_prob= 0.02;
float true_prob= 0.50;
uint rand_prob_thresh;
uint true_prob_thresh;
float alpha= 0.4;
int warmups= 0;
ullng total_learned;
double cells_learned;
double cells_prelearned;
ullng discards;
ullng trivials;
ullng subsumptions;
ullng doomsday= 0x8000000000000000;
ullng next_recycle;
ullng recycle_bump= 1000;
ullng recycle_inc= 500;
ullng next_restart;
ullng restart_psi;
float restart_psi_fraction= .05;
ullng actual_restarts;
/*:4*//*11:*/
#line 417 "sat13.w"
char*buf;
tmp_var**hash;
uint hash_bits[93][8];
vchunk*cur_vchunk;
tmp_var*cur_tmp_var;
tmp_var*bad_tmp_var;
chunk*cur_chunk;
tmp_var**cur_cell;
tmp_var**bad_cell;
ullng vars;
ullng clauses;
ullng nullclauses;
int unaries;
int binaries;
ullng cells;
/*:11*//*27:*/
#line 770 "sat13.w"
cel*mem;
uint memsize;
uint min_learned;
uint first_learned;
uint max_learned;
int max_lit;
uint*bmem;
literal*lmem;
variable*vmem;
uint*heap;
int hn;
uint*trail;
int eptr;
int ebptr;
int lptr;
int lbptr;
char*history;
int llevel;
int*leveldat;
/*:27*//*41:*/
#line 1162 "sat13.w"
ullng depth_per_decision;
ullng trail_per_decision;
ullng mems_per_confl,lits_per_confl,lits_per_nontriv;
ullng res_per_confl,glucose_per_confl;
ullng props_per_confl= two_to_the_32;
uint short_per_confl;
uint agility;
ullng mems_at_prev_confl;
uint props;
/*:41*//*59:*/
#line 1544 "sat13.w"
uint lt;
uint lat;
uint wa,next_wa;
/*:59*//*80:*/
#line 1951 "sat13.w"
double var_bump= 1.0;
float clause_bump= 1.0;
double var_bump_factor;
float clause_bump_factor;
/*:80*//*90:*/
#line 2117 "sat13.w"
uint curstamp;
uint*learn;
int oldptr;
int jumplev;
int tl;
int xnew;
int clevels;
uint resols;
uint learned_size;
int prelearned_size;
int trivial_learning;
/*:90*//*97:*/
#line 2228 "sat13.w"
int*stack;
int stackptr;
int*conflictdat;
int conflict_level;
uint*levstamp;
/*:97*//*111:*/
#line 2662 "sat13.w"
int*rangedist;
int asserts;
int minrange;
int maxrange;
int recycle_point;
int budget;
ullng*clause_heap;
int clause_heap_size;
/*:111*//*140:*/
#line 3229 "sat13.w"
int full_run;
int conflict_seen;
int decisionvar;
int prev_learned;
int warmup_cycles;
int next_learned;
int restart_u,restart_v;
ullng restart_thresh;
int trail_marker;
int minjumplev;
/*:140*/
#line 101 "sat13.w"
;
/*139:*/
#line 3219 "sat13.w"
void confusion(char*id){
fprintf(stderr,"This can't happen ("O"s)!\n",id);
exit(-666);
}
void debugstop(int foo){
fprintf(stderr,"You rang("O"d)?\n",foo);
}
/*:139*/
#line 102 "sat13.w"
;
/*31:*/
#line 903 "sat13.w"
void print_bimp(int l){
register uint la;
printf(""O"s"O".8s("O"d) ->",litname(l),l);
if(lmem[l].bimp_end){
for(la= lmem[l].bimp_start;la<lmem[l].bimp_end;la++)
printf(" "O"s"O".8s("O"d)",litname(bmem[la]),bmem[la]);
}
printf("\n");
}
/*:31*//*32:*/
#line 917 "sat13.w"
void print_watches_for(int l){
register uint c;
printf(""O"s"O".8s("O"d) watched in",litname(l),l);
for(c= lmem[l].watch;c;){
printf(" "O"u",c);
if(mem[c].lit==l)c= link0(c);
else c= link1(c);
}
printf("\n");
}
/*:32*//*33:*/
#line 931 "sat13.w"
void print_clause(uint c){
register int k,l;
printf(""O"u:",c);
if(c<clause_extra||c>=max_learned){
printf(" clause "O"d doesn't exist!\n",c);
return;
}
for(k= 0;k<size(c);k++){
l= mem[c+k].lit;
if(l<2||l> max_lit){
printf(" BAD!\n");
return;
}
printf(" "O"s"O".8s("O"u)",litname(l),l);
}
while(mem[c+k].lit&sign_bit){
l= mem[c+k].lit^sign_bit;
if(l<2||l> max_lit){
printf(" !BAD!\n");
return;
}
printf(" !"O"s"O".8s("O"u)",litname(l),l);
k++;
}
printf("\n");
}
/*:33*//*34:*/
#line 964 "sat13.w"
void sanity(int eptr){
register uint k,l,c,endc,u,v,clauses,watches,vals,llevel;
/*35:*/
#line 974 "sat13.w"
for(clauses= k= 0,c= clause_extra;c<min_learned;k= c,c= endc+clause_extra){
endc= c+size(c);
clauses++;
if(link0(c)>=max_learned){
fprintf(stderr,"bad link0("O"u)!\n",c);
return;
}
if(link1(c)>=max_learned){
fprintf(stderr,"bad link1("O"u)!\n",c);
return;
}
if(size(c)<2)
fprintf(stderr,"size("O"u)="O"d!\n",c,size(c));
for(k= 0;k<size(c);k++)
if(mem[c+k].lit<2||mem[c+k].lit> max_lit)
fprintf(stderr,"bad lit "O"d of "O"d!\n",k,c);
while(mem[c+k].lit&sign_bit){
if(mem[c+k].lit<2+sign_bit||mem[c+k].lit> max_lit+sign_bit)
fprintf(stderr,"bad deleted lit "O"d of "O"d!\n",k,c);
k++,endc++;
}
}
if(c!=min_learned)
fprintf(stderr,"bad last unlearned clause ("O"d)!\n",k);
else{
for(k= 0,c= first_learned;c<max_learned;k= c,c= endc+learned_extra){
endc= c+size(c);
clauses++;
if(link0(c)>=max_learned){
fprintf(stderr,"bad link0("O"u)!\n",c);
return;
}
if(link1(c)>=max_learned){
fprintf(stderr,"bad link1("O"u)!\n",c);
return;
}
if(size(c)<2)
fprintf(stderr,"size("O"u)="O"d!\n",c,size(c));
for(k= 0;k<size(c);k++)
if(mem[c+k].lit<2||mem[c+k].lit> max_lit)
fprintf(stderr,"bad lit "O"d of "O"d!\n",k,c);
while(mem[c+k].lit&sign_bit){
if(mem[c+k].lit<2+sign_bit||mem[c+k].lit> max_lit+sign_bit)
fprintf(stderr,"bad deleted lit "O"d of "O"d!\n",k,c);
k++,endc++;
}
}
if(c!=max_learned)
fprintf(stderr,"bad last learned clause ("O"d)!\n",k);
if(mem[c-learned_extra].lit)
fprintf(stderr,"missing zero at end of mem!\n");
}
/*:35*/
#line 967 "sat13.w"
;
/*36:*/
#line 1031 "sat13.w"
for(watches= 0,l= 2;l<=max_lit;l++){
for(c= lmem[l].watch;c;){
watches++;
if(c<clause_extra||c>=max_learned){
fprintf(stderr,"clause "O"u in watch list "O"u out of range!\n",c,l);
return;
}
if(mem[c].lit==l)c= link0(c);
else if(mem[c+1].lit==l)c= link1(c);
else{
fprintf(stderr,"clause "O"u improperly on watch list "O"u!\n",c,l);
return;
}
}
}
if(watches!=clauses+clauses)
fprintf(stderr,""O"u clauses but "O"u watches!\n",clauses,watches);
/*:36*/
#line 968 "sat13.w"
;
/*72:*/
#line 1775 "sat13.w"
for(k= 1;k<=vars;k++){
if(vmem[k].hloc>=hn)
fprintf(stderr,"hloc of "O".8s exceeds "O"d!\n",vmem[k].name.ch8,hn-1);
else if(vmem[k].hloc>=0&&heap[vmem[k].hloc]!=k)
fprintf(stderr,"hloc of "O".8s errs!\n",vmem[k].name.ch8);
}
for(k= 0;k<hn;k++){
v= heap[k];
if(v<=0||v> vars)
fprintf(stderr,"heap["O"d]="O"d!\n",k,v);
else if(k){
u= heap[(k-1)>>1];
if(u> 0&&u<=vars&&vmem[u].activity<vmem[v].activity)
fprintf(stderr,"heap["O"d]act<heap["O"d]act!\n",(k-1)>>1,k);
}
}
/*:72*/
#line 969 "sat13.w"
;
/*37:*/
#line 1050 "sat13.w"
for(k= llevel= 0;k<eptr;k++){
l= trail[k];
if(l<2||l> max_lit){
fprintf(stderr,"bad lit "O"u in trail["O"u]!\n",l,k);
return;
}
if(vmem[thevar(l)].tloc!=k)
fprintf(stderr,""O"s"O".8s has bad tloc ("O"d not "O"d)!\n",
litname(l),vmem[thevar(l)].tloc,k);
if(k==leveldat[llevel+2]){
llevel+= 2;
if(lmem[l].reason)
fprintf(stderr,""O"s"O".8s("O"u), level "O"u, shouldn't have reason!\n",
litname(l),l,llevel>>1);
}else{
if(llevel&&!lmem[l].reason)
fprintf(stderr,""O"s"O".8s("O"u), level "O"u, should have reason!\n",
litname(l),l,llevel>>1);
}
if(lmem[bar(l)].reason)
fprintf(stderr,""O"s"O".8s("O"u), level "O"u, comp has reason!\n",
litname(l),l,llevel>>1);
if(vmem[thevar(l)].value!=llevel+(l&1))
fprintf(stderr,""O"s"O".8s("O"u), level "O"u, has bad value!\n",
litname(l),l,llevel>>1);
if(llevel){
if(lmem[l].reason<=0){
if(lmem[l].reason==-1||lmem[l].reason<-max_lit)
fprintf(stderr,
""O"s"O".8s("O"u), level "O"u, has wrong binary reason ("O"u)!\n",
litname(l),l,llevel>>1,c);
}else{
c= lmem[l].reason;
if(mem[c].lit!=l)
fprintf(stderr,""O"s"O".8s("O"u), level "O"u, has wrong reason ("O"u)!\n",
litname(l),l,llevel>>1,c);
u= bar(mem[c+1].lit);
if(vmem[thevar(u)].value!=llevel+(u&1))
fprintf(stderr,""O"s"O".8s("O"u), level "O"u, has bad reason ("O"u)!\n",
litname(l),l,llevel>>1,c);
}
}
}
/*:37*/
#line 970 "sat13.w"
;
/*38:*/
#line 1095 "sat13.w"
for(vals= 0,v= 1;v<=vars;v++){
if(vmem[v].value> llevel+1){
if(vmem[v].value!=unset)
fprintf(stderr,"strange val "O".8s (level "O"u)!\n",
vmem[v].name.ch8,vmem[v].value>>1);
else if(vmem[v].hloc<0)
fprintf(stderr,""O".8s should be in the heap!\n",vmem[v].name.ch8);
}else vals++;
}
if(vals!=eptr)
fprintf(stderr,"I found "O"u values, but eptr="O"u!\n",vals,eptr);
/*:38*/
#line 971 "sat13.w"
;
}
/*:34*//*39:*/
#line 1123 "sat13.w"
void print_stats(void){
register double mpc= mems_per_confl,ppc= props_per_confl;
fprintf(stderr,"z="O"d d="O".1f t="O".1f m="O".1f p="O".1f m/p="O".1f",
leveldat[2],
(double)depth_per_decision/two_to_the_32,
(double)trail_per_decision/two_to_the_32,
mpc/two_to_the_32,ppc/two_to_the_32,mpc/ppc);
fprintf(stderr," r="O".1f L="O".1f l="O".1f g="O".1f s="O".2f a="O".2f\n",
(double)res_per_confl/two_to_the_32,
(double)lits_per_confl/two_to_the_32,
(double)lits_per_nontriv/two_to_the_32,
(double)glucose_per_confl/two_to_the_32,
(double)short_per_confl/two_to_the_32,
(double)agility/two_to_the_32);
}
/*:39*//*42:*/
#line 1202 "sat13.w"
void print_state(int eptr){
register uint j,k;
fprintf(stderr," after "O"lld mems:",mems);
if(print_state_cutoff){
for(k= 0;k<eptr;k++){
if(k==trail_marker)fprintf(stderr,"|");
fprintf(stderr,""O"d",history[k]+(trail[k]&1));
if(k>=print_state_cutoff){
fprintf(stderr,"...");break;
}
}
fprintf(stderr,"\n");
}
fprintf(stderr," ");
print_stats();
fflush(stderr);
}
/*:42*//*43:*/
#line 1223 "sat13.w"
void print_trail(int eptr){
register int k,l;
for(k= 0;k<eptr;k++){
l= trail[k];
if(k>=vars||l<2||l> max_lit)return;
fprintf(stderr,""O"d: "O"d "O"d "O"s"O".8s("O"d)",
k,history[k]+(l&1),vmem[thevar(l)].value>>1,litname(l),l);
if(lmem[l].reason> 0){
if((vmem[thevar(l)].value>>1)||lmem[l].reason<min_learned)
fprintf(stderr," #"O"u\n",lmem[l].reason);
else fprintf(stderr," learned\n");
}else if(lmem[l].reason<0)
fprintf(stderr," <- "O"s"O".8s\n",litname(-lmem[l].reason));
else fprintf(stderr,"\n");
}
}
/*:43*//*44:*/
#line 1245 "sat13.w"
void print_unsat(void){
register int c,endc,k,l;
for(c= clause_extra;c<min_learned;c= endc+clause_extra){
endc= c+size(c);
for(k= endc-1;k>=c;k--){
l= mem[k].lit;
if(isknown(l)&&!iscontrary(l))break;
}
if(k<c){
fprintf(stderr,""O"d:",c);
for(k= 0;k<size(c);k++){
l= mem[c+k].lit;
if(!isknown(l))fprintf(stderr," "O"s"O".8s",litname(l));
}
fprintf(stderr," |");
for(k= 0;k<size(c);k++){
l= mem[c+k].lit;
if(isknown(l))fprintf(stderr," "O"s"O".8s",litname(l));
}
fprintf(stderr,"\n");
}
while(mem[endc].lit&sign_bit)endc++;
}
}
/*:44*//*71:*/
#line 1766 "sat13.w"
void print_heap(void){
register int k;
for(k= 0;k<hn;k++){
fprintf(stderr,""O"d: "O".8s "O"e\n",
k,vmem[heap[k]].name.ch8,vmem[heap[k]].activity);
}
}
/*:71*/
#line 103 "sat13.w"
;
main(int argc,char*argv[]){
register int h,hp,i,j,jj,k,kk,l,ll,lll,p,q,r,s;
register int c,cc,endc,la,t,u,v,w,x,y;
register double au,av;
/*3:*/
#line 211 "sat13.w"
for(j= argc-1,k= 0;j;j--)switch(argv[j][0]){
/*5:*/
#line 270 "sat13.w"
case'v':k|= (sscanf(argv[j]+1,""O"d",&verbose)-1);break;
case'c':k|= (sscanf(argv[j]+1,""O"d",&show_choices_max)-1);break;
case'H':k|= (sscanf(argv[j]+1,""O"d",&print_state_cutoff)-1);break;
case'h':k|= (sscanf(argv[j]+1,""O"d",&hbits)-1);break;
case'b':k|= (sscanf(argv[j]+1,""O"d",&buf_size)-1);break;
case's':k|= (sscanf(argv[j]+1,""O"d",&random_seed)-1);break;
case'd':k|= (sscanf(argv[j]+1,""O"lld",&delta)-1);thresh= delta;break;
case'D':k|= (sscanf(argv[j]+1,""O"lld",&doomsday)-1);break;
case'm':k|= (sscanf(argv[j]+1,""O"d",&memk_max)-1);break;
case't':k|= (sscanf(argv[j]+1,""O"d",&trivial_limit)-1);break;
case'w':k|= (sscanf(argv[j]+1,""O"d",&warmups)-1);break;
case'j':k|= (sscanf(argv[j]+1,""O"lld",&recycle_bump)-1);break;
case'J':k|= (sscanf(argv[j]+1,""O"lld",&recycle_inc)-1);break;
case'K':k|= (sscanf(argv[j]+1,""O"d",&learn_save)-1);break;
case'f':k|= (sscanf(argv[j]+1,""O"f",&restart_psi_fraction)-1);break;
case'a':k|= (sscanf(argv[j]+1,""O"f",&alpha)-1);break;
case'r':k|= (sscanf(argv[j]+1,""O"f",&var_rho)-1);break;
case'R':k|= (sscanf(argv[j]+1,""O"f",&clause_rho)-1);break;
case'p':k|= (sscanf(argv[j]+1,""O"f",&rand_prob)-1);break;
case'P':k|= (sscanf(argv[j]+1,""O"f",&true_prob)-1);break;
case'x':out_name= argv[j]+1,out_file= fopen(out_name,"w");
if(!out_file)
fprintf(stderr,"Sorry, I can't open file `"O"s' for writing!\n",out_name);
break;
case'l':learned_name= argv[j]+1,learned_file= fopen(learned_name,"w");
if(!learned_file)
fprintf(stderr,"Sorry, I can't open file `"O"s' for writing!\n",
learned_name);
break;
case'L':restart_name= argv[j]+1,restart_file= fopen(restart_name,"w");
if(!restart_file)
fprintf(stderr,"Sorry, I can't open file `"O"s' for writing!\n",
restart_name);
break;
case'z':polarity_in_name= argv[j]+1,
polarity_infile= fopen(polarity_in_name,"r");
if(!polarity_infile)
fprintf(stderr,"Sorry, I can't open file `"O"s' for reading!\n",
polarity_in_name);
break;
case'Z':polarity_out_name= argv[j]+1,
polarity_outfile= fopen(polarity_out_name,"w");
if(!polarity_outfile)
fprintf(stderr,"Sorry, I can't open file `"O"s' for writing!\n",
polarity_out_name);
break;
case'T':k|= (sscanf(argv[j]+1,""O"lld",&timeout)-1);break;
/*:5*/
#line 213 "sat13.w"
;
default:k= 1;
}
/*6:*/
#line 319 "sat13.w"
if(k||hbits<0||hbits> 30||buf_size<=0||memk_max<2||memk_max> 31||
trivial_limit<=0||(int)recycle_inc<0||alpha<0.0||alpha> 1.0||
rand_prob<0.0||true_prob<0.0||var_rho<=0.0||clause_rho<=0.0){
fprintf(stderr,
"Usage: "O"s [v<n>] [c<n>] [H<n>] [h<n>] [b<n>] [s<n>] [d<n>]",argv[0]);
fprintf(stderr," [D<n>] [m<n>] [t<n>] [w<n>] [j<n>] [J<n>] [K<n>]");
fprintf(stderr," [f<f>] [a<f>] [r<f>] [R<f>] [p<f>] [P<f>]");
fprintf(stderr," [x<foo>] [l<bar>] [L<baz>] [z<poi>] [Z<poo>] [T<n>] < foo.sat\n");
exit(-1);
}
/*:6*/
#line 216 "sat13.w"
;
/*:3*/
#line 108 "sat13.w"
;
/*12:*/
#line 434 "sat13.w"
gb_init_rand(random_seed);
buf= (char*)malloc(buf_size*sizeof(char));
if(!buf){
fprintf(stderr,"Couldn't allocate the input buffer (buf_size="O"d)!\n",
buf_size);
exit(-2);
}
hash= (tmp_var**)malloc(sizeof(tmp_var)<<hbits);
if(!hash){
fprintf(stderr,"Couldn't allocate "O"d hash list heads (hbits="O"d)!\n",
1<<hbits,hbits);
exit(-3);
}
for(h= 0;h<1<<hbits;h++)hash[h]= NULL;
/*:12*//*18:*/
#line 574 "sat13.w"
for(j= 92;j;j--)for(k= 0;k<8;k++)
hash_bits[j][k]= gb_next_rand();
/*:18*/
#line 109 "sat13.w"
;
/*13:*/
#line 463 "sat13.w"
while(1){
if(!fgets(buf,buf_size,stdin))break;
clauses++;
if(buf[strlen(buf)-1]!='\n'){
fprintf(stderr,
"The clause on line "O"lld ("O".20s...) is too long for me;\n",clauses,buf);
fprintf(stderr," my buf_size is only "O"d!\n",buf_size);
fprintf(stderr,"Please use the command-line option b<newsize>.\n");
exit(-4);
}
/*14:*/
#line 500 "sat13.w"
for(j= k= 0;;){
while(buf[j]==' ')j++;
if(buf[j]=='\n')break;
if(buf[j]<' '||buf[j]> '~'){
fprintf(stderr,"Illegal character (code #"O"x) in the clause on line "O"lld!\n",
buf[j],clauses);
exit(-5);
}
if(buf[j]=='~')i= 1,j++;
else i= 0;
/*15:*/
#line 527 "sat13.w"
{
register tmp_var*p;
if(cur_tmp_var==bad_tmp_var)/*16:*/
#line 545 "sat13.w"
{
register vchunk*new_vchunk;
new_vchunk= (vchunk*)malloc(sizeof(vchunk));
if(!new_vchunk){
fprintf(stderr,"Can't allocate a new vchunk!\n");
exit(-6);
}
new_vchunk->prev= cur_vchunk,cur_vchunk= new_vchunk;
cur_tmp_var= &new_vchunk->var[0];
bad_tmp_var= &new_vchunk->var[vars_per_vchunk];
}
/*:16*/
#line 530 "sat13.w"
;
/*19:*/
#line 578 "sat13.w"
cur_tmp_var->name.lng= 0;
for(h= l= 0;buf[j+l]> ' '&&buf[j+l]<='~';l++){
if(l> 7){
fprintf(stderr,
"Variable name "O".9s... in the clause on line "O"lld is too long!\n",
buf+j,clauses);
exit(-8);
}
h^= hash_bits[buf[j+l]-'!'][l];
cur_tmp_var->name.ch8[l]= buf[j+l];
}
if(l==0)goto empty_clause;
j+= l;
h&= (1<<hbits)-1;
/*:19*/
#line 532 "sat13.w"
;
/*20:*/
#line 594 "sat13.w"
for(p= hash[h];p;p= p->next)
if(p->name.lng==cur_tmp_var->name.lng)break;
if(!p){
p= cur_tmp_var++;
p->next= hash[h],hash[h]= p;
p->serial= vars++;
p->stamp= 0;
}
/*:20*/
#line 533 "sat13.w"
;
if(p->stamp==clauses||p->stamp==-clauses)/*21:*/
#line 608 "sat13.w"
{
if((p->stamp> 0)==(i> 0))goto empty_clause;
}
/*:21*/
#line 534 "sat13.w"
else{
p->stamp= (i?-clauses:clauses);
if(cur_cell==bad_cell)/*17:*/
#line 558 "sat13.w"
{
register chunk*new_chunk;
new_chunk= (chunk*)malloc(sizeof(chunk));
if(!new_chunk){
fprintf(stderr,"Can't allocate a new chunk!\n");
exit(-7);
}
new_chunk->prev= cur_chunk,cur_chunk= new_chunk;
cur_cell= &new_chunk->cell[0];
bad_cell= &new_chunk->cell[cells_per_chunk];
}
/*:17*/
#line 537 "sat13.w"
;
*cur_cell= p;
if(i==1)*cur_cell= hack_in(*cur_cell,1);
if(k==0)*cur_cell= hack_in(*cur_cell,2);
cur_cell++,k++;
}
}
/*:15*/
#line 511 "sat13.w"
;
}
if(k==0){
fprintf(stderr,"(Empty line "O"lld is being ignored)\n",clauses);
nullclauses++;
}
goto clause_done;
empty_clause:/*22:*/
#line 618 "sat13.w"
while(k){
/*23:*/
#line 627 "sat13.w"
if(cur_cell> &cur_chunk->cell[0])cur_cell--;
else{
register chunk*old_chunk= cur_chunk;
cur_chunk= old_chunk->prev;free(old_chunk);
bad_cell= &cur_chunk->cell[cells_per_chunk];
cur_cell= bad_cell-1;
}
/*:23*/
#line 620 "sat13.w"
;
k--;
}
if((buf[0]!='~')||(buf[1]!=' '))
fprintf(stderr,"(The clause on line "O"lld is always satisfied)\n",clauses);
nullclauses++;
/*:22*/
#line 518 "sat13.w"
;
clause_done:cells+= k;
if(k==1)unaries++;
else if(k==2)binaries++;
/*:14*/
#line 474 "sat13.w"
;
}
if((vars>>hbits)>=10){
fprintf(stderr,"There are "O"lld variables but only "O"d hash tables;\n",
vars,1<<hbits);
for(h= hbits+1;(vars>>h)>=10;h++);
fprintf(stderr," maybe you should use command-line option h"O"d?\n",h);
}
clauses-= nullclauses;
if(clauses==0){
fprintf(stderr,"No clauses were input!\n");
exit(-77);
}
if(vars>=0x80000000){
fprintf(stderr,"Whoa, the input had "O"llu variables!\n",vars);
exit(-664);
}
if(clauses>=0x80000000){
fprintf(stderr,"Whoa, the input had "O"llu clauses!\n",clauses);
exit(-665);
}
if(cells>=0x100000000){
fprintf(stderr,"Whoa, the input had "O"llu occurrences of literals!\n",cells);
exit(-666);
}
/*:13*/
#line 110 "sat13.w"
;
if(verbose&show_basics)
/*25:*/
#line 645 "sat13.w"
fprintf(stderr,
"("O"lld variables, "O"lld clauses, "O"llu literals successfully read)\n",
vars,clauses,cells);
/*:25*/
#line 112 "sat13.w"
;
/*45:*/
#line 1276 "sat13.w"
/*46:*/
#line 1287 "sat13.w"
vmem= (variable*)malloc((vars+1)*sizeof(variable));
if(!vmem){
fprintf(stderr,"Oops, I can't allocate the vmem array!\n");
exit(-12);
}
bytes+= (vars+1)*sizeof(variable);