InsertionSearch#

class causalbase.order.InsertionSearch(scorer)[source]#

First-improvement insertion local search over orders.

Parameters:
scorerOrderScorer

Order evaluator; its caches are shared by every move.

best_move(order, v)[source]#

Return the gain and new index of the best reinsertion of v.

The gain is 0 and the index its own if no reinsertion improves.

Only the positions where a jump changes u or v are visited: the gain is constant in between, so the best position, found by the same rule as a sweep over every position, is always one of them.

run(order, rng, max_passes=None, deadline=None)[source]#

Apply improving moves, visiting the variables in a random order each pass.

Stops after a pass without improvement, after max_passes passes or at deadline (a time.perf_counter value). Returns the order and its score.