///|
/// Work bounds for FM passes, vertex moves, pair trials and candidate scans.
#derive(Debug)
pub(all) struct RefinementBudget {
max_passes : Int32
max_moves : Int32
max_swap_trials : Int32
max_candidates : Int32
}
///|
pub extend RefinementBudget with @debug.Debug::{to_repr}
///|
/// Default bounds for the single-level implementation.
pub fn RefinementBudget::default() -> RefinementBudget {
{
max_passes: 8,
max_moves: 10000,
max_swap_trials: 10000,
max_candidates: 200000,
}
}
///|
/// Counts include exploratory moves subsequently rolled back.
#derive(Debug)
pub struct RefineResult {
assignment : Array[Int32]
metrics : @metrics.Metrics
initial_cut : Int64
moves : Int32
swaps : Int32
passes : Int32
rolled_back : Int32
budget_limited : Bool
}
///|
pub extend RefineResult with @debug.Debug::{to_repr}
///|
priv struct State {
assignment : Array[Int32]
zero_pins : Array[Int32]
loads : Array[Int64]
sizes : Array[Int32]
mut cut : Int64
}
///|
fn State::new(
g : @model.Hypergraph,
assignment : Array[Int32],
metrics : @metrics.Metrics,
) -> State {
let zero_pins = Array::make(g.edge_count(), 0)
for e in 0.. Int64 {
let from = self.assignment[v]
let mut gain = 0L
for i in 0.. Unit {
let from = self.assignment[v]
let to = 1 - from
let gain = self.gain(g, v)
let delta = if from == 0 { -1 } else { 1 }
for i in 0.. Int64 {
let touched = []
let change_a = if self.assignment[a] == 0 { -1 } else { 1 }
for i in 0.. 0 && before < g.edge_size(e)
let is_cut = after > 0 && after < g.edge_size(e)
if was_cut && !is_cut {
gain += g.edge_weight(e)
}
if !was_cut && is_cut {
gain -= g.edge_weight(e)
}
delta[e] = 0
}
gain
}