-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmcMc.c
1541 lines (1210 loc) · 44.9 KB
/
mcMc.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
/* ---------------------------------------------------------------------------
This file is part of the ``mc'' package of NuSMV version 2.
Copyright (C) 1998-2001 by CMU and FBK-irst.
NuSMV version 2 is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
NuSMV version 2 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
For more information on NuSMV see <http://nusmv.fbk.eu>
or email to <nusmv-users@fbk.eu>.
Please report bugs to <nusmv-users@fbk.eu>.
To contact the NuSMV development board, email to <nusmv@fbk.eu>.
-----------------------------------------------------------------------------*/
/*!
\author Marco Roveri
\brief Fair CTL model checking routines.
Fair CTL model checking routines.
*/
#include "nusmv/core/mc/mcInt.h"
#include "nusmv/core/mc/mc.h"
#include "../enc/bdd/BddEnc.h"
#include "nusmv/core/utils/OStream.h"
#include "nusmv/core/utils/StreamMgr.h"
#include "nusmv/core/utils/Logger.h"
#include "nusmv/core/utils/ErrorMgr.h"
#include "nusmv/core/utils/error.h"
#include "nusmv/core/utils/utils_io.h"
#include "nusmv/core/trace/Trace.h"
#include "nusmv/core/trace/TraceMgr.h"
#include "nusmv/core/bmc/bmc.h"
#include "nusmv/core/bmc/sbmc/sbmcGen.h"
#include "nusmv/core/fsm/bdd/FairnessList.h"
#include "nusmv/core/parser/symbols.h"
#include "nusmv/core/enc/enc.h"
#include "nusmv/core/prop/propPkg.h"
#include "nusmv/core/fsm/bdd/BddFsm.h"
/* ADDED Header file for printing accepting states */
#include "nusmv/core/mc/mcAc.h"
#include "nusmv/core/mc/printinfo.h"
#include "nusmv/core/mc/multipath.h"
/*---------------------------------------------------------------------------*/
/* Variable declarations */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Static function prototypes */
/*---------------------------------------------------------------------------*/
//extern MasterPrinter_ptr global_wffprint;
//extern StreamMgr_ptr global_streams;
StreamMgr_ptr global_streams;
static BddStatesInputs
Mc_get_fair_si_subset(BddFsm_ptr fsm,
BddStatesInputs si);
static BddStatesInputs
Mc_fair_si_iteration(BddFsm_ptr fsm,
bdd_ptr states,
bdd_ptr subspace);
/*---------------------------------------------------------------------------*/
/* Definition of exported functions */
/*---------------------------------------------------------------------------*/
void Mc_CheckCTLSpec(NuSMVEnv_ptr env, Prop_ptr prop)
{
//try to dump sth
FILE *fp;
int dres=0;
int bdd_tmp_size=0;
char* str_p=NULL;
node_ptr tmp_explain;
struct multipath *x;
int flag;
SexpFsm_ptr sexp_fsm; /* needed for trace lanugage */
const StreamMgr_ptr streams =
STREAM_MGR(NuSMVEnv_get_value(env, ENV_STREAM_MANAGER));
const ErrorMgr_ptr errmgr =
ERROR_MGR(NuSMVEnv_get_value(env, ENV_ERROR_MANAGER));
node_ptr exp;
Trace_ptr trace;
/* ADDED bdd_ptr for accepting and initial states */
bdd_ptr s0, tmp_1, tmp_2, accepted, init;
BddFsm_ptr fsm;
BddEnc_ptr enc;
DDMgr_ptr dd;
Expr_ptr spec = Prop_get_expr_core(prop);
const OptsHandler_ptr opts =
OPTS_HANDLER(NuSMVEnv_get_value(env, ENV_OPTS_HANDLER));
const NodeMgr_ptr nodemgr =
NODE_MGR(NuSMVEnv_get_value(env, ENV_NODE_MGR));
if (opt_verbose_level_gt(opts, 0)) {
Logger_ptr logger = LOGGER(NuSMVEnv_get_value(env, ENV_LOGGER));
Logger_log(logger, "evaluating ");
print_spec(Logger_get_ostream(logger), prop, get_prop_print_method(opts));
Logger_log(logger, "\n");
}
fsm = Prop_compute_ground_bdd_fsm(env, prop);
enc = BddFsm_get_bdd_encoding(fsm);
dd = BddEnc_get_dd_manager(enc);
// fp = fopen("/home/william/spec.dot", "w");
//
// if(fp == NULL)
// printf("fail to open the file! \n");
// else
// {
// printf("The file is open! \n");
//// fprintf (fp, "Name\n");
//// bdd_tmp_size=bdd_size(dd,spec);
//// dres=dd_dump_dot(dd,bdd_tmp_size,&spec,NULL,NULL,fp);
// bst_print_dot(spec,fp);
// if(dres==1)
// {
// printf("success!\n");
// }
// else
// {
// printf("failed!");
// }
// fclose(fp);
// }
//added:multipath
multipath_head=(struct multipath*)malloc(sizeof(struct multipath));
multipath_head->size=0;
multipath_head->index=0;
multipath_head->next=NULL;
multipath_head->current=NULL;
/* Evaluates the spec */
s0 = eval_ctl_spec(fsm, enc, spec, Nil);
//
// fp = fopen("/home/william/test.dot", "w");
//
// if(fp == NULL)
// printf("fail to open the file! \n");
// else
// {
// printf("The file is open! \n");
//// fprintf (fp, "Name\n");
// bdd_tmp_size=bdd_size(dd,s0);
// dres=dd_dump_dot(dd,bdd_tmp_size,&s0,NULL,NULL,fp);
// if(dres==1)
// {
// printf("success!\n");
// }
// else
// {
// printf("failed!");
// }
// fclose(fp);
// }
/* ADDED: save accepting states */
if(get_print_accepting(opts) != NULL)
accepted = bdd_dup(s0);
tmp_1 = bdd_not(dd, s0);
tmp_2 = BddFsm_get_state_constraints(fsm);
bdd_and_accumulate(dd, &tmp_2 , tmp_1);
bdd_free(dd, tmp_1);
tmp_1 = BddFsm_get_fair_states(fsm);
if (bdd_is_false(dd, tmp_1)) {
ErrorMgr_warning_fsm_fairness_empty(errmgr);
}
bdd_and_accumulate(dd, &tmp_2 , tmp_1);
bdd_free(dd, tmp_1);
bdd_free(dd, s0);
s0 = BddFsm_get_init(fsm);
bdd_and_accumulate(dd, &s0, tmp_2);
bdd_free(dd, tmp_2);
/* Prints out the result, if not true explain. */
StreamMgr_print_output(streams, "-- ");
print_spec(StreamMgr_get_output_ostream(streams),
prop, get_prop_print_method(opts));
if (bdd_is_false(dd, s0)) {
StreamMgr_print_output(streams, "is true\n");
Prop_set_status(prop, Prop_True);
}
else {
StreamMgr_print_output(streams, "is false\n");
Prop_set_status(prop, Prop_False);
if (opt_counter_examples(opts)) {
char* trace_title = NULL;
char* trace_title_postfix = " Counterexample";
// printf("AAAXXXX NUM:%lf\n",BddEnc_get_minterms_of_bdd(enc, s0));
tmp_1 = BddEnc_pick_one_state(enc, s0);
// tmp_1 = BddEnc_pick_one_state_rand(enc, s0);
bdd_free(dd, s0);
s0 = bdd_dup(tmp_1);
bdd_free(dd, tmp_1);
tmp_explain=explain(fsm, enc, cons(nodemgr, (node_ptr) bdd_dup(s0), Nil),
spec, Nil);
if(multipath_head->size>0) {
x = multipath_head->next;
global_streams = streams;
/* The trace title depends on the property type. For example it
is in the form "LTL Counterexample" */
trace_title = ALLOC(char,
strlen(Prop_get_type_as_string(prop)) +
strlen(trace_title_postfix) + 1);
nusmv_assert(trace_title != (char *) NULL);
strcpy(trace_title, Prop_get_type_as_string(prop));
strcat(trace_title, trace_title_postfix);
// {
sexp_fsm = Prop_get_scalar_sexp_fsm(prop);
if (SEXP_FSM(NULL) == sexp_fsm) {
sexp_fsm = \
SEXP_FSM(NuSMVEnv_get_value(env, ENV_SEXP_FSM));
SEXP_FSM_CHECK_INSTANCE(sexp_fsm);
}
// }
flag=0;
while (x != NULL) {
tmp_explain=x->path;
exp = reverse_cpy(tmp_explain);
if (exp == Nil) {
/* The counterexample consists of one initial state */
exp = cons(nodemgr, (node_ptr) bdd_dup(s0), Nil);
}
// fp = fopen("/home/william/path.dot", "w");
//
// if (fp == NULL)
// printf("fail to open the file! \n");
// else {
// printf("The file is open! \n");
// bst_print_dot(exp, fp);
//
// fclose(fp);
// }
{
//这里这里,有问题的地方在这里
trace = \
Mc_create_trace_from_bdd_state_input_list(enc,
SexpFsm_get_symbols_list(sexp_fsm), trace_title,
TRACE_TYPE_CNTEXAMPLE, exp);
}
// FREE(trace_title);
StreamMgr_print_output(streams,
"-- as demonstrated by the following execution sequence\n");
TraceMgr_register_trace(TRACE_MGR(NuSMVEnv_get_value(env, ENV_TRACE_MGR)), trace);
TraceMgr_execute_plugin(TRACE_MGR(NuSMVEnv_get_value(env, ENV_TRACE_MGR)), TRACE_OPT(NULL),
TRACE_MGR_DEFAULT_PLUGIN,
TRACE_MGR_LAST_TRACE);
Prop_set_trace(prop, Trace_get_id(trace));
// walk_dd(dd, bdd_free, exp);
// free_list(nodemgr, exp);
x=x->next;
}
}
}
}
/* ADDED: prints out accepting states, initial states
* and initial accepting states as additional information
* if commandline parameter "-a interesting_states" is set */
if(get_print_accepting(opts) != NULL) {
init = BddFsm_get_init(fsm);
print_accepting_states(env, prop, dd, enc, opts, streams, init, accepted);
bdd_free(dd,init);
bdd_free(dd,accepted);
}
free_list(nodemgr, exp);
bdd_free(dd, s0);
}
void Mc_CheckCompute(NuSMVEnv_ptr env, Prop_ptr prop)
{
const StreamMgr_ptr streams =
STREAM_MGR(NuSMVEnv_get_value(env, ENV_STREAM_MANAGER));
const OptsHandler_ptr opts =
OPTS_HANDLER(NuSMVEnv_get_value(env, ENV_OPTS_HANDLER));
FILE* errstream = StreamMgr_get_error_stream(streams);
FILE* outstream = StreamMgr_get_output_stream(streams);
int s0;
Expr_ptr spec = Prop_get_expr_core(prop);
BddFsm_ptr fsm = BDD_FSM(NULL);
BddEnc_ptr enc;
DDMgr_ptr dd;
if (opt_verbose_level_gt(opts, 0)) {
Logger_ptr logger = LOGGER(NuSMVEnv_get_value(env, ENV_LOGGER));
Logger_log(logger, "evaluating ");
print_spec(Logger_get_ostream(logger), prop, get_prop_print_method(opts));
Logger_log(logger, "\n");
}
fsm = Prop_compute_ground_bdd_fsm(env, prop);
BDD_FSM_CHECK_INSTANCE(fsm);
enc = BddFsm_get_bdd_encoding(fsm);
dd = BddEnc_get_dd_manager(enc);
{
/*
We force computation of reachable states, as the following
calls will be performed more efficiently since they are cached.
*/
bdd_ptr r = BddFsm_get_reachable_states(fsm);
bdd_free(dd, r);
}
s0 = eval_compute(fsm, enc, spec, Nil);
StreamMgr_print_output(streams, "-- ");
print_compute(StreamMgr_get_output_ostream(streams),
prop, get_prop_print_method(opts));
if (s0 == -1) {
StreamMgr_print_output(streams, "is infinity\n");
Prop_set_number_infinite(prop);
Prop_set_status(prop, Prop_Number);
}
else if (s0 == -2) {
StreamMgr_print_output(streams, "is undefined\n");
Prop_set_number_undefined(prop);
Prop_set_status(prop, Prop_Number);
}
else {
StreamMgr_print_output(streams, "is %d\n", s0);
Prop_set_number(prop, s0);
Prop_set_status(prop, Prop_Number);
}
fflush(outstream);
fflush(errstream);
}
BddStates ex(BddFsm_ptr fsm, BddStates g)
{
DDMgr_ptr dd = BddEnc_get_dd_manager(BddFsm_get_bdd_encoding(fsm));
NuSMVEnv_ptr env = EnvObject_get_environment(ENV_OBJECT(dd));
const OptsHandler_ptr opts =
OPTS_HANDLER(NuSMVEnv_get_value(env, ENV_OPTS_HANDLER));
bdd_ptr result;
bdd_ptr tmp = bdd_dup(g);
{
/*
The explicit restriction to fair states is required (it affects
the result from a logical point of view.)
*/
bdd_ptr fair_states_bdd = BddFsm_get_fair_states(fsm);
bdd_and_accumulate(dd, &tmp, fair_states_bdd);
bdd_free(dd, fair_states_bdd);
}
if (opt_use_reachable_states(opts)) {
bdd_ptr reachable_states_bdd = BddFsm_get_reachable_states(fsm);
bdd_and_accumulate(dd, &tmp, reachable_states_bdd);
bdd_free(dd, reachable_states_bdd);
}
result = BddFsm_get_backward_image(fsm, tmp);//后继?其实应该是前驱,就是preimage
bdd_free(dd, tmp);
if (opt_use_reachable_states(opts)) {
bdd_ptr reachable_states_bdd = BddFsm_get_reachable_states(fsm);
bdd_and_accumulate(dd, &result, reachable_states_bdd);
bdd_free(dd, reachable_states_bdd);
}
return(result);
}
//f=true,g=tmp_1
//Check(E[f U g]) = CheckEU(Check(f); Check(g));
BddStates eu(BddFsm_ptr fsm, BddStates f, BddStates g)
{
BddEnc_ptr enc = BddFsm_get_bdd_encoding(fsm);
DDMgr_ptr dd = BddEnc_get_dd_manager(enc);
MasterPrinter_ptr global_wffprint;
NuSMVEnv_ptr env = EnvObject_get_environment(ENV_OBJECT(dd));
const OptsHandler_ptr opts =
OPTS_HANDLER(NuSMVEnv_get_value(env, ENV_OPTS_HANDLER));
const MasterPrinter_ptr wffprint = MASTER_PRINTER(NuSMVEnv_get_value(env, ENV_WFF_PRINTER));
const ErrorMgr_ptr errmgr =
ERROR_MGR(NuSMVEnv_get_value(env, ENV_ERROR_MANAGER));
bdd_ptr new, oldY;
bdd_ptr Y = bdd_dup(g);//bdd_ref
int n = 1;
/* The following simplification may be useful for efficiency since g
may be unreachable (but they are not fundamental for correctness
similar simplifications are applied in ex). */
//优化,是不是这里才是计算fixedpoint啊?好像是获得Fairness规则的部分
{
bdd_ptr fair_states_bdd = BddFsm_get_fair_states(fsm);
bdd_and_accumulate(dd, &Y, fair_states_bdd);
bdd_free(dd, fair_states_bdd);
}
if (opt_use_reachable_states(opts)) {
bdd_ptr reachable_states_bdd = BddFsm_get_reachable_states(fsm);
bdd_and_accumulate(dd, &Y, reachable_states_bdd);
bdd_free(dd, reachable_states_bdd);
}
global_wffprint=wffprint;
if (opt_verbose_level_gt(opts, 1)) {
// if (true) {
// Logger_ptr logger = LOGGER(NuSMVEnv_get_value(env, ENV_LOGGER));
// Logger_nlog(logger, wffprint,
// "eu: computing fixed point approximations for %N ...\n",
// ErrorMgr_get_the_node(errmgr));
}
//计算fixedpoint了
oldY = bdd_dup(Y);
new = bdd_dup(Y);//这里都是Y
//应该是没跑了,这里在计算fixed point,而且应该是least fixed poin这个循环很重要呢,需要好好研究
//model checking中的不同算法
while(bdd_isnot_false(dd, new)) {
bdd_ptr tmp_1, tmp_2;
// if (true) {
if (opt_verbose_level_gt(opts, 1)) {
Logger_ptr logger = LOGGER(NuSMVEnv_get_value(env, ENV_LOGGER));
double states = BddEnc_count_states_of_bdd(enc, Y);
int size = bdd_size(dd, Y);
Logger_log(logger, "size of Y%d = %g states, %d BDD nodes\n",
n++, states, size);
}
bdd_free(dd, oldY);
oldY = bdd_dup(Y);
tmp_1 = ex(fsm, new);
tmp_2 = bdd_and(dd, f, tmp_1);
bdd_free(dd, tmp_1);
bdd_or_accumulate(dd, &Y, tmp_2);
bdd_free(dd, tmp_2);
tmp_1 = bdd_not(dd, oldY);
bdd_free(dd, new);
new = bdd_and(dd, Y, tmp_1);
bdd_free(dd, tmp_1);
}
bdd_free(dd, new);//这里看看Logic False是个什么样的吧,new到这里除了循环说明已经是Logic False了
bdd_free(dd, oldY);
return(Y);
}
BddStates eg(BddFsm_ptr fsm, BddStates g)
{
DDMgr_ptr dd = BddEnc_get_dd_manager(BddFsm_get_bdd_encoding(fsm));
bdd_ptr fair_transitions;
bdd_ptr fair_transitions_g;
bdd_ptr res_si;
bdd_ptr res;
/* Lazy evaluation for the case 'EG True' */
if (bdd_is_true(dd, g)) return BddFsm_get_fair_states(fsm);
fair_transitions = BddFsm_get_fair_states_inputs(fsm);
fair_transitions_g = bdd_and(dd, fair_transitions, g);
res_si = eg_si(fsm, fair_transitions_g);
res = BddFsm_states_inputs_to_states(fsm, res_si);
bdd_free(dd, res_si);
bdd_free(dd, fair_transitions_g);
bdd_free(dd, fair_transitions);
return(res);
}
BddStates ef(BddFsm_ptr fsm, BddStates g)
{
DDMgr_ptr dd = BddEnc_get_dd_manager(BddFsm_get_bdd_encoding(fsm));
bdd_ptr result, one;
one = bdd_true(dd);//获得一个TRUE?是的,ef=eu(true,sub_formula)
result = eu(fsm, one, g);
bdd_free(dd, one);
return(result);
}
BddStates au(BddFsm_ptr fsm, BddStates f, BddStates g)
{
DDMgr_ptr dd = BddEnc_get_dd_manager(BddFsm_get_bdd_encoding(fsm));
bdd_ptr result, tmp_1, tmp_2, tmp_3, tmp_4;
tmp_1 = bdd_not(dd, f);
tmp_2 = bdd_not(dd, g);
tmp_3 = eg(fsm, tmp_2);
tmp_4 = bdd_and(dd, tmp_1, tmp_2);
bdd_free(dd, tmp_1);
tmp_1 = eu(fsm, tmp_2, tmp_4);
bdd_free(dd, tmp_2);
tmp_2 = bdd_or(dd, tmp_1, tmp_3);
result = bdd_not(dd, tmp_2);
bdd_free(dd, tmp_2);
bdd_free(dd, tmp_1);
bdd_free(dd, tmp_4);
bdd_free(dd, tmp_3);
return(result);
}
BddStatesInputs ex_si(BddFsm_ptr fsm, BddStatesInputs si)
{
DDMgr_ptr dd = BddEnc_get_dd_manager(BddFsm_get_bdd_encoding(fsm));
NuSMVEnv_ptr env = EnvObject_get_environment(ENV_OBJECT(dd));
const OptsHandler_ptr opts =
OPTS_HANDLER(NuSMVEnv_get_value(env, ENV_OPTS_HANDLER));
BddStates states;
BddStatesInputs si_preimage;
/* Eliminate input variables */
states = BddFsm_states_inputs_to_states(fsm, si);
/* Perform weak preimage */
si_preimage = BddFsm_get_weak_backward_image(fsm, states);
if (opt_use_reachable_states(opts)) {
bdd_ptr reachable_states_bdd = BddFsm_get_reachable_states(fsm);
bdd_and_accumulate(dd, &si_preimage, reachable_states_bdd);
bdd_free(dd, reachable_states_bdd);
}
bdd_free(dd, states);
return si_preimage;
}
BddStatesInputs eu_si(BddFsm_ptr fsm, bdd_ptr f, bdd_ptr g)
{
int i = 0;
BddEnc_ptr enc = BddFsm_get_bdd_encoding(fsm);
DDMgr_ptr dd = BddEnc_get_dd_manager(enc);
NuSMVEnv_ptr env = EnvObject_get_environment(ENV_OBJECT(dd));
const OptsHandler_ptr opts =
OPTS_HANDLER(NuSMVEnv_get_value(env, ENV_OPTS_HANDLER));
bdd_ptr oldY;
bdd_ptr resY;
bdd_ptr newY;
bdd_ptr rg = bdd_dup(g);
if (opt_use_reachable_states(opts)) {
bdd_ptr reachable_states_bdd = BddFsm_get_reachable_states(fsm);
bdd_and_accumulate(dd, &rg, reachable_states_bdd);
bdd_free(dd, reachable_states_bdd);
}
oldY = bdd_dup(rg);
resY = bdd_dup(rg);
newY = bdd_dup(rg);
bdd_free(dd, rg);
while (bdd_isnot_false(dd, newY)) {
bdd_ptr tmp_1, tmp_2;
if (opt_verbose_level_gt(opts, 5)) {
Logger_ptr logger = LOGGER(NuSMVEnv_get_value(env, ENV_LOGGER));
Logger_log(logger,
" size of Y%d = %g <states>x<inputs>, %d BDD nodes\n",
i++, BddEnc_count_states_inputs_of_bdd(enc, resY),
bdd_size(dd, resY) );
}
bdd_free(dd, oldY);
oldY = bdd_dup(resY);
tmp_1 = ex_si(fsm, newY);
tmp_2 = bdd_and(dd, tmp_1, f);
bdd_free(dd, tmp_1);
bdd_or_accumulate(dd, &resY, tmp_2);
bdd_free(dd, tmp_2);
tmp_1 = bdd_not(dd, oldY);
bdd_free(dd, newY);
newY = bdd_and(dd, resY, tmp_1);
bdd_free(dd, tmp_1);
}
bdd_free(dd, newY);
bdd_free(dd, oldY);
return BDD_STATES_INPUTS( resY );
}
bdd_ptr eg_si(BddFsm_ptr fsm, bdd_ptr g_si)
{
DDMgr_ptr dd = BddEnc_get_dd_manager(BddFsm_get_bdd_encoding(fsm));
NuSMVEnv_ptr env = EnvObject_get_environment(ENV_OBJECT(dd));
const OptsHandler_ptr opts =
OPTS_HANDLER(NuSMVEnv_get_value(env, ENV_OPTS_HANDLER));
bdd_ptr applicable_states_inputs;
bdd_ptr fair_states_inputs;
applicable_states_inputs =
BddFsm_get_states_inputs_constraints(fsm, BDD_FSM_DIR_BWD);
bdd_and_accumulate(dd, &applicable_states_inputs, g_si);
if (opt_use_reachable_states(opts)) {
bdd_ptr reachable_states_bdd = BddFsm_get_reachable_states(fsm);
bdd_and_accumulate(dd, &applicable_states_inputs, reachable_states_bdd);
bdd_free(dd, reachable_states_bdd);
}
fair_states_inputs = Mc_get_fair_si_subset(fsm, applicable_states_inputs);
bdd_free(dd, applicable_states_inputs);
return fair_states_inputs;
}
BddStates ebu(BddFsm_ptr fsm, BddStates f, BddStates g, int inf, int sup)
{
BddEnc_ptr enc = BddFsm_get_bdd_encoding(fsm);
DDMgr_ptr dd = BddEnc_get_dd_manager(enc);
NuSMVEnv_ptr env = EnvObject_get_environment(ENV_OBJECT(dd));
const OptsHandler_ptr opts =
OPTS_HANDLER(NuSMVEnv_get_value(env, ENV_OPTS_HANDLER));
const MasterPrinter_ptr wffprint = MASTER_PRINTER(NuSMVEnv_get_value(env, ENV_WFF_PRINTER));
const ErrorMgr_ptr errmgr =
ERROR_MGR(NuSMVEnv_get_value(env, ENV_ERROR_MANAGER));
int i;
bdd_ptr Y, oldY, tmp_1, tmp_2;
int n = 1;
if (inf > sup || inf < 0) return(bdd_false(dd));
Y = bdd_dup(g);
{
bdd_ptr fair_states_bdd = BddFsm_get_fair_states(fsm);
bdd_and_accumulate(dd, &Y, fair_states_bdd);
bdd_free(dd, fair_states_bdd);
}
if (opt_use_reachable_states(opts)) {
bdd_ptr reachable_states_bdd = BddFsm_get_reachable_states(fsm);
bdd_and_accumulate(dd, &Y, reachable_states_bdd);
bdd_free(dd, reachable_states_bdd);
}
if (opt_verbose_level_gt(opts, 1)) {
Logger_ptr logger = LOGGER(NuSMVEnv_get_value(env, ENV_LOGGER));
Logger_nlog(logger, wffprint,
"ebu: computing fixed point approximations for %N ...\n",
ErrorMgr_get_the_node(errmgr));
}
/* compute Y = g | (f & ex(Y)) for states within the bound */
for (i = sup; i > inf; i--) {
/* There are more states within the bounds */
if (opt_verbose_level_gt(opts, 1)) {
Logger_ptr logger = LOGGER(NuSMVEnv_get_value(env, ENV_LOGGER));
Logger_log(logger, "size of Y%d = %g states, %d BDD nodes\n",
n++, BddEnc_count_states_of_bdd(enc, Y),
bdd_size(dd, Y));
}
oldY = Y;
tmp_1 = ex(fsm, Y);
tmp_2 = bdd_and(dd, f, tmp_1);
bdd_or_accumulate(dd, &Y, tmp_2);
bdd_free(dd, tmp_1);
bdd_free(dd, tmp_2);
if (Y == oldY) {
/* fixpoint found. collect garbage, and goto next phase */
break;
}
}
/* compute Y = f & ex(Y) for states before the bound */
for (i = inf; i > 0; i--) {
if (opt_verbose_level_gt(opts, 1)) {
Logger_ptr logger = LOGGER(NuSMVEnv_get_value(env, ENV_LOGGER));
Logger_log(logger, "size of Y%d = %g states, %d BDD nodes\n",
n++, BddEnc_count_states_of_bdd(enc, Y),
bdd_size(dd, Y));
}
oldY = bdd_dup(Y);
tmp_1 = ex(fsm, Y);
bdd_free(dd, Y);
Y = bdd_and(dd, f, tmp_1);
bdd_free(dd, tmp_1);
bdd_free(dd, oldY);
if (Y == oldY) {
/* fixpoint found. collect garbage, and finish */
break;
}
}
return(Y);
}
BddStates ebf(BddFsm_ptr fsm, BddStates g, int inf, int sup)
{
DDMgr_ptr dd = BddEnc_get_dd_manager(BddFsm_get_bdd_encoding(fsm));
bdd_ptr one, result;
one = bdd_true(dd);
result = ebu(fsm, one, g, inf, sup);
bdd_free(dd, one);
return(result);
}
BddStates ebg(BddFsm_ptr fsm, BddStates g, int inf, int sup)
{
BddEnc_ptr enc = BddFsm_get_bdd_encoding(fsm);
DDMgr_ptr dd = BddEnc_get_dd_manager(enc);
NuSMVEnv_ptr env = EnvObject_get_environment(ENV_OBJECT(dd));
const OptsHandler_ptr opts =
OPTS_HANDLER(NuSMVEnv_get_value(env, ENV_OPTS_HANDLER));
const MasterPrinter_ptr wffprint =
MASTER_PRINTER(NuSMVEnv_get_value(env, ENV_WFF_PRINTER));
const ErrorMgr_ptr errmgr =
ERROR_MGR(NuSMVEnv_get_value(env, ENV_ERROR_MANAGER));
int i;
bdd_ptr Y, oldY, tmp_1;
int n = 1;
if (inf > sup || inf < 0) return bdd_true(dd);
Y = bdd_dup(g);
/* Limitation to fair states should be imposed. */
{
bdd_ptr fair_states_bdd = BddFsm_get_fair_states(fsm);
bdd_and_accumulate(dd, &Y, fair_states_bdd);
bdd_free(dd, fair_states_bdd);
}
if (opt_use_reachable_states(opts)) {
bdd_ptr reachable_states_bdd = BddFsm_get_reachable_states(fsm);
bdd_and_accumulate(dd, &Y, reachable_states_bdd);
bdd_free(dd, reachable_states_bdd);
}
if (opt_verbose_level_gt(opts, 1)) {
Logger_ptr logger = LOGGER(NuSMVEnv_get_value(env, ENV_LOGGER));
Logger_nlog(logger, wffprint,
"ebg: computing fixed point approximations for %N ...\n",
ErrorMgr_get_the_node(errmgr));
}
/* compute Y = g & ex(Y) for states within the bound */
for (i = sup; i > inf; i--) {
if (opt_verbose_level_gt(opts, 1)) {
Logger_ptr logger = LOGGER(NuSMVEnv_get_value(env, ENV_LOGGER));
Logger_log(logger, "size of Y%d = %g states, %d BDD nodes\n",
n++, BddEnc_count_states_of_bdd(enc, Y),
bdd_size(dd, Y));
}
oldY = bdd_dup(Y);
tmp_1 = ex(fsm, Y);
bdd_and_accumulate(dd, &Y, tmp_1);
bdd_free(dd, tmp_1);
if (Y == oldY) {
bdd_free(dd, oldY);
/* fixpoint found. goto next phase */
break;
}
bdd_free(dd, oldY);
}
/* compute Y = ex(Y) for states before the bound */
for (i = inf; i > 0; i--) {
if (opt_verbose_level_gt(opts, 1)) {
Logger_ptr logger = LOGGER(NuSMVEnv_get_value(env, ENV_LOGGER));
Logger_log(logger, "size of Y%d = %g states, %d BDD nodes\n",
n++, BddEnc_count_states_of_bdd(enc, Y),
bdd_size(dd, Y));
}
oldY = Y;
tmp_1 = ex(fsm, Y);
bdd_free(dd, Y);
Y = tmp_1;
if (Y == oldY) {
break; /* fixpoint found. */
}
}
return Y;
}
BddStates abu(BddFsm_ptr fsm, BddStates f, BddStates g, int inf, int sup)
{
BddEnc_ptr enc = BddFsm_get_bdd_encoding(fsm);
DDMgr_ptr dd = BddEnc_get_dd_manager(enc);
NuSMVEnv_ptr env = EnvObject_get_environment(ENV_OBJECT(dd));
const OptsHandler_ptr opts =
OPTS_HANDLER(NuSMVEnv_get_value(env, ENV_OPTS_HANDLER));
const MasterPrinter_ptr wffprint =
MASTER_PRINTER(NuSMVEnv_get_value(env, ENV_WFF_PRINTER));
const ErrorMgr_ptr errmgr =
ERROR_MGR(NuSMVEnv_get_value(env, ENV_ERROR_MANAGER));
int i;
bdd_ptr Y, oldY, tmp_1, tmp_2;
int n = 1;
if (inf > sup || inf < 0) return(bdd_false(dd));
Y = bdd_dup(g);
{
bdd_ptr fair_states_bdd = BddFsm_get_fair_states(fsm);
bdd_and_accumulate(dd, &Y, fair_states_bdd);
bdd_free(dd, fair_states_bdd);
}
if (opt_use_reachable_states(opts)) {
bdd_ptr reachable_states_bdd = BddFsm_get_reachable_states(fsm);
bdd_and_accumulate(dd, &Y, reachable_states_bdd);
bdd_free(dd, reachable_states_bdd);
}
if (opt_verbose_level_gt(opts, 1)) {
Logger_ptr logger = LOGGER(NuSMVEnv_get_value(env, ENV_LOGGER));
Logger_nlog(logger, wffprint,
"abu: computing fixed point approximations for %N ...\n",
ErrorMgr_get_the_node(errmgr));
}
/* compute Y = g | (f & ax(Y)) for states within the bound */
for (i = sup; i > inf; i--) {
if (opt_verbose_level_gt(opts, 1)){
Logger_ptr logger = LOGGER(NuSMVEnv_get_value(env, ENV_LOGGER));
Logger_log(logger, "size of Y%d = %g states, %d BDD nodes\n",
n++, BddEnc_count_states_of_bdd(enc, Y),
bdd_size(dd, Y));
}
oldY = Y;
tmp_1 = bdd_not(dd, Y);
tmp_2 = ex(fsm, tmp_1);
bdd_free(dd, tmp_1);
tmp_1 = bdd_not(dd, tmp_2);
bdd_free(dd, tmp_2);
tmp_2 = bdd_and(dd, f, tmp_1);
bdd_or_accumulate(dd, &Y, tmp_2);
bdd_free(dd, tmp_1);
bdd_free(dd, tmp_2);
if (Y == oldY) {
break; /* fixpoint found. goto next phase */
}
}
/* compute Y = f & ax(Y) for states before the bound */
for (i = inf; i > 0; i--) {
if (opt_verbose_level_gt(opts, 1)) {
Logger_ptr logger = LOGGER(NuSMVEnv_get_value(env, ENV_LOGGER));
Logger_log(logger, "size of Y%d = %g states, %d BDD nodes\n",
n++, BddEnc_count_states_of_bdd(enc, Y),
bdd_size(dd, Y));
}
oldY = bdd_dup(Y);
tmp_1 = bdd_not(dd, Y);
tmp_2 = ex(fsm, tmp_1);
bdd_free(dd, tmp_1);
tmp_1 = bdd_not(dd, tmp_2);
bdd_free(dd, tmp_2);
bdd_free(dd, Y);
Y = bdd_and(dd, f, tmp_1);
bdd_free(dd, oldY);
bdd_free(dd,tmp_1);
if (Y == oldY) {
break; /* fixpoint found. finish */
}
}
return(Y);
}
int minu(BddFsm_ptr fsm, bdd_ptr arg_f, bdd_ptr arg_g)
{
BddEnc_ptr enc = BddFsm_get_bdd_encoding(fsm);
DDMgr_ptr dd = BddEnc_get_dd_manager(enc);
NuSMVEnv_ptr env = EnvObject_get_environment(ENV_OBJECT(dd));
const ErrorMgr_ptr errmgr =
ERROR_MGR(NuSMVEnv_get_value(env, ENV_ERROR_MANAGER));
const OptsHandler_ptr opts =
OPTS_HANDLER(NuSMVEnv_get_value(env, ENV_OPTS_HANDLER));
const MasterPrinter_ptr wffprint =
MASTER_PRINTER(NuSMVEnv_get_value(env, ENV_WFF_PRINTER));
int i;
int n = 1;
bdd_ptr R, Rp, tmp_1;