@@ -585,15 +585,26 @@ impl SddManager {
585
585
586
586
/// Enumerate models of the SDD.
587
587
pub fn model_enumeration ( & self , sdd : & SddRef ) -> Models {
588
+ let all_variables: BTreeSet < _ > = self . literal_manager . borrow ( ) . all_variables ( ) ;
588
589
let mut models: Vec < BitVec > = Vec :: new ( ) ;
589
- self . _model_enumeration ( sdd, & mut models) ;
590
590
591
- let all_variables: BTreeSet < _ > = self . literal_manager . borrow ( ) . all_variables ( ) ;
592
- let unbound_variables: Vec < _ > = all_variables
593
- . difference ( & self . get_variables ( sdd) )
594
- . cloned ( )
595
- . collect ( ) ;
596
- SddManager :: expand_models ( & mut models, & unbound_variables) ;
591
+ if sdd. is_true ( ) {
592
+ let all_variables: Vec < _ > = all_variables. iter ( ) . cloned ( ) . collect ( ) ;
593
+ SddManager :: expand_models ( & mut models, & all_variables) ;
594
+ return Models :: new ( & models, all_variables. clone ( ) ) ;
595
+ } else if !sdd. is_false ( ) {
596
+ // In the case of False, we do not add any models.
597
+ self . model_enumeration_rec ( sdd, & mut models) ;
598
+
599
+ let all_variables: BTreeSet < _ > = self . literal_manager . borrow ( ) . all_variables ( ) ;
600
+ let unbound_variables: Vec < _ > = all_variables
601
+ . difference ( & self . get_variables ( sdd) )
602
+ . cloned ( )
603
+ . collect ( ) ;
604
+
605
+ SddManager :: expand_models ( & mut models, & unbound_variables) ;
606
+ }
607
+
597
608
Models :: new ( & models, all_variables. iter ( ) . cloned ( ) . collect ( ) )
598
609
}
599
610
@@ -612,7 +623,7 @@ impl SddManager {
612
623
return 0 ;
613
624
}
614
625
615
- let models = self . _model_count ( sdd) ;
626
+ let models = self . model_count_rec ( sdd) ;
616
627
617
628
if self . root ( ) . index ( ) == sdd. vtree ( ) . unwrap ( ) . index ( ) {
618
629
return models;
@@ -870,7 +881,7 @@ impl SddManager {
870
881
}
871
882
872
883
#[ instrument( skip_all, level = tracing:: Level :: DEBUG ) ]
873
- fn _model_enumeration ( & self , sdd : & SddRef , bitvecs : & mut Vec < BitVec > ) {
884
+ fn model_enumeration_rec ( & self , sdd : & SddRef , bitvecs : & mut Vec < BitVec > ) {
874
885
tracing:: debug!( sdd_id = sdd. id( ) . 0 ) ;
875
886
// Return the cached value if it already exists.
876
887
if let Some ( ref mut models) = sdd. models ( ) {
@@ -912,16 +923,16 @@ impl SddManager {
912
923
913
924
if prime. is_true ( ) || sub. is_true ( ) {
914
925
if prime. is_true ( ) {
915
- self . _model_enumeration ( sub, & mut models) ;
926
+ self . model_enumeration_rec ( sub, & mut models) ;
916
927
} else {
917
- self . _model_enumeration ( prime, & mut models) ;
928
+ self . model_enumeration_rec ( prime, & mut models) ;
918
929
}
919
930
} else {
920
931
let mut fst = Vec :: new ( ) ;
921
932
let mut snd = Vec :: new ( ) ;
922
933
923
- self . _model_enumeration ( prime, & mut fst) ;
924
- self . _model_enumeration ( sub, & mut snd) ;
934
+ self . model_enumeration_rec ( prime, & mut fst) ;
935
+ self . model_enumeration_rec ( sub, & mut snd) ;
925
936
926
937
for fst_bv in & fst {
927
938
for snd_bv in & snd {
@@ -950,7 +961,7 @@ impl SddManager {
950
961
}
951
962
952
963
/// Count number of models for this SDD.
953
- fn _model_count ( & self , sdd : & SddRef ) -> u64 {
964
+ fn model_count_rec ( & self , sdd : & SddRef ) -> u64 {
954
965
// Return the cached value if it already exists.
955
966
if let Some ( model_count) = sdd. model_count ( ) {
956
967
return model_count;
@@ -969,7 +980,7 @@ impl SddManager {
969
980
} else if sdd. is_false ( ) {
970
981
0
971
982
} else {
972
- self . _model_count ( sdd)
983
+ self . model_count_rec ( sdd)
973
984
}
974
985
} ;
975
986
0 commit comments