From 73c64fd9344abae09e844323b861e247bf6cb7be Mon Sep 17 00:00:00 2001 From: yancy Date: Wed, 25 Sep 2024 19:31:54 -0500 Subject: [PATCH] wip --- src/branch_and_bound.rs | 46 ++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/src/branch_and_bound.rs b/src/branch_and_bound.rs index c78125e3..888fd285 100644 --- a/src/branch_and_bound.rs +++ b/src/branch_and_bound.rs @@ -826,10 +826,8 @@ mod tests { effective_value_sum += eff_value; } - let result = effective_value_sum.to_unsigned().unwrap(); - // There will be a match, but there could be - // more than one possible solution. + let result = effective_value_sum.to_unsigned().unwrap(); assert_eq!(result, target); Ok(()) @@ -843,26 +841,14 @@ mod tests { // generate all the possible utxos subsets let mut gen = exhaustigen::Gen::new(); - let mut subsets: Vec> = Vec::new(); + let mut subsets: Vec> = Vec::new(); while !gen.done() { let s = gen.gen_subset(&pool.utxos).collect::>(); - let w = s.into_iter().cloned().collect(); - subsets.push(w); + subsets.push(s); } - let non_empty_subsets: Vec<_> = subsets.clone().into_iter().filter(|x| !x.is_empty()).collect(); - - let selection: &Vec = u.choose(&non_empty_subsets).unwrap(); - - for s in subsets { - let sum: Amount = s.iter().map(|u| u.clone().value()).sum(); - let selection_sum: Amount = selection.iter().map(|u| u.value()).sum(); - - // in theory this could be possible; looking for the seed. - if sum == selection_sum && selection.len() > 1 && *selection != s { - panic!(); - } - } + // choose a set at random to be the target + let selection: &Vec<&Utxo> = u.choose(&subsets).unwrap(); // find the minmum fee_rate that will result in all utxos having a posiive // effective_value @@ -891,16 +877,20 @@ mod tests { &pool.utxos, ); - let result: SignedAmount = coins.unwrap().map(|u| { - effective_value( - fee_rate, - u.satisfaction_weight(), - u.value(), - ) - .unwrap() - }).sum(); + if selection.is_empty() { + assert!(coins.is_none()); + } else { + let result: SignedAmount = coins.unwrap().map(|u| { + effective_value( + fee_rate, + u.satisfaction_weight(), + u.value(), + ) + .unwrap() + }).sum(); - assert_eq!(result, target); + assert_eq!(result, target); + } Ok(()) });