File tree Expand file tree Collapse file tree 5 files changed +3718
-2
lines changed
Expand file tree Collapse file tree 5 files changed +3718
-2
lines changed Original file line number Diff line number Diff line change @@ -146,8 +146,8 @@ impl ExtendedDdnnf {
146146
147147#[ cfg( test) ]
148148mod test {
149- use crate :: ddnnf:: anomalies:: t_wise_sampling:: Sample ;
150149 use crate :: ddnnf:: anomalies:: t_wise_sampling:: t_iterator:: TInteractionIter ;
150+ use crate :: ddnnf:: anomalies:: t_wise_sampling:: { Sample , SamplingResult } ;
151151 use crate :: ddnnf:: extended_ddnnf:: optimal_configs:: test:: build_sandwich_ext_ddnnf_with_objective_function_values;
152152 use crate :: { Ddnnf , parser:: build_ddnnf} ;
153153 use itertools:: Itertools ;
@@ -231,4 +231,18 @@ mod test {
231231 check_validity_of_sample ( & ext_ddnnf. sample_t_wise_yasa ( t) , & ext_ddnnf. ddnnf , t) ;
232232 }
233233 }
234+
235+ #[ test]
236+ fn number_of_interactions ( ) {
237+ let ddnnf = build_ddnnf ( Path :: new ( "tests/data/busybox.nnf" ) , Some ( 42 ) ) ;
238+ let sample = ddnnf. sample_t_wise ( 2 ) ;
239+ match sample {
240+ SamplingResult :: Empty | SamplingResult :: Void => {
241+ panic ! ( "Expected valid, non-empty sampling result." )
242+ }
243+ SamplingResult :: ResultWithSample ( sample) => {
244+ assert_eq ! ( sample. interactions( 2 ) . len( ) , 1387048 )
245+ }
246+ }
247+ }
234248}
Original file line number Diff line number Diff line change 11use super :: SatWrapper ;
2+ use crate :: ddnnf:: anomalies:: t_wise_sampling:: t_iterator:: TInteractionIter ;
23use std:: fmt:: Display ;
34use std:: hash:: { Hash , Hasher } ;
5+ use streaming_iterator:: StreamingIterator ;
46
57/// Represents a (partial) configuration
68#[ derive( Debug , Clone , Eq ) ]
@@ -203,4 +205,13 @@ impl Config {
203205 pub fn is_complete ( & self ) -> bool {
204206 self . n_decided_literals == self . literals . len ( )
205207 }
208+
209+ /// Generates all `t`-wise interactions covered by this configuration.
210+ pub fn interactions ( & self , t : usize ) -> Vec < Vec < i32 > > {
211+ let mut out = Vec :: new ( ) ;
212+ TInteractionIter :: new ( & self . literals , t)
213+ . for_each ( |interaction| out. push ( interaction. to_vec ( ) ) ) ;
214+
215+ out
216+ }
206217}
Original file line number Diff line number Diff line change @@ -236,6 +236,22 @@ impl Sample {
236236 TInteractionIter :: new ( & literals, min ( t, literals. len ( ) ) )
237237 . all ( |interaction| self . covers ( interaction) )
238238 }
239+
240+ /// Generates all `t`-wise interactions covered by this sample.
241+ pub fn interactions ( & self , t : usize ) -> HashSet < Vec < i32 > > {
242+ let mut interactions = HashSet :: new ( ) ;
243+ self . iter ( ) . for_each ( |config| {
244+ config
245+ . interactions ( t)
246+ . into_iter ( )
247+ . for_each ( |mut interaction| {
248+ interaction. sort_unstable ( ) ;
249+ interactions. insert ( interaction) ;
250+ } ) ;
251+ } ) ;
252+
253+ interactions
254+ }
239255}
240256
241257#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments