Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
yancyribbens committed Dec 14, 2024
1 parent ad05f14 commit 04a1baf
Showing 1 changed file with 0 additions and 18 deletions.
18 changes: 0 additions & 18 deletions src/coin_grinder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,11 @@ pub fn select_coins<Utxo: WeightedUtxo>(
let mut iteration = 0;

loop {
println!("---");
println!("begin loop");
println!("amount_sum {:?} weight_sum {} selection {:?}", amount_sum, weight_sum, selection);
let mut cut = false;
let mut shift = false;

// EXPLORE
let (eff_value, u) = w_utxos[next_utxo_index];
println!("effective_value: {:?} weight: {}", eff_value, u.weight());

amount_sum += eff_value;
weight_sum += u.weight();
Expand All @@ -175,12 +171,10 @@ pub fn select_coins<Utxo: WeightedUtxo>(
iteration += 1;

let tail: usize = *selection.last().unwrap();
println!("amount sum {:?} weight sum {} selection {:?} next_utxo_index {} iteration {}", amount_sum, weight_sum, selection, next_utxo_index, iteration);

// no possibility of hitting the total along this branch.
// CUT
if amount_sum + lookahead[tail] < total_target {
println!("* cut because branch no longer feasible");
cut = true;
} else if weight_sum > best_weight_sum {
// check if a better solution could exist. IE there exists a utxo with a better
Expand All @@ -199,27 +193,20 @@ pub fn select_coins<Utxo: WeightedUtxo>(
shift = true;
}
} else if amount_sum >= total_target {
println!("* shift since we have met the goal target");
shift = true;
if weight_sum < best_weight_sum || weight_sum == best_weight_sum && amount_sum < best_amount_sum {
println!("* recording new better solution");
best_selection = selection.clone();
best_weight_sum = weight_sum;
best_amount_sum = amount_sum;
println!("best_selection {:?} best_weight_sum {:?} best_amount_sum {:?}", best_selection, best_weight_sum, best_amount_sum);
}
}

println!("cut {} shift {}", cut, shift);

// check if evaluating a leaf node.
if next_utxo_index == w_utxos.len() {
cut = true;
}

if cut {
println!("* cutting");

// deselect
let (eff_value, u) = w_utxos[*selection.last().unwrap()];
amount_sum -= eff_value;
Expand All @@ -230,12 +217,7 @@ pub fn select_coins<Utxo: WeightedUtxo>(
}

if shift {
println!("* shifting");
println!("selection: {:?}", selection);

if selection.is_empty() {
println!("** done **");
println!("best_selection {:?}", best_selection);
return index_to_utxo_list(best_selection, w_utxos)
}

Expand Down

0 comments on commit 04a1baf

Please sign in to comment.