///|
/// Repairs large deliveries first, reducing late capacity failures.
pub fn demand_first_repair(
  instance : @core.VrpInstance,
  partial : @core.Solution,
  config : @core.SolveConfig,
) -> @core.Solution {
  let mut current = partial
  let customers = partial.unassigned_customers()
  customers.sort_by(fn(left, right) {
    let order = Double::compare(
      instance.customer(right).demand(),
      instance.customer(left).demand(),
    )
    if order == 0 {
      left - right
    } else {
      order
    }
  })
  for customer_index in customers {
    current = @constructive.insert_customer(
      instance, current, customer_index, config,
    )
  }
  current
}

///|
fn time_window_priority(
  instance : @core.VrpInstance,
  customer_index : Int,
) -> Double {
  let customer = instance.customer(customer_index)
  customer.due_time() - customer.ready_time()
}

///|
/// Repairs tight time windows before relaxed deliveries.
pub fn time_window_repair(
  instance : @core.VrpInstance,
  partial : @core.Solution,
  config : @core.SolveConfig,
) -> @core.Solution {
  let customers = partial.unassigned_customers()
  customers.sort_by(fn(left, right) {
    let order = Double::compare(
      time_window_priority(instance, left),
      time_window_priority(instance, right),
    )
    if order == 0 {
      left - right
    } else {
      order
    }
  })
  let mut current = partial
  for customer_index in customers {
    current = @constructive.insert_customer(
      instance, current, customer_index, config,
    )
  }
  current
}

///|
/// Repeatedly applies greedy repair until no unassigned count changes.
pub fn repair_until_stable(
  instance : @core.VrpInstance,
  partial : @core.Solution,
  config : @core.SolveConfig,
  max_rounds : Int,
) -> @core.Solution {
  let mut current = partial
  for _ in 0..= before {
      break
    }
  }
  current
}

///|
/// Selects a repair order according to the structure of the instance.
pub fn repair_with_priority(
  instance : @core.VrpInstance,
  partial : @core.Solution,
  operator : @core.RepairOperator,
  config : @core.SolveConfig,
) -> @core.Solution {
  repair_solution(instance, partial, operator, config)
}