Node Managers

Node managers implement the BaseNodeManager interface and control how nodes are stored and retrieved during Branch & Bound search. The manager is the strategy object injected into BranchAndBound via the manager parameter (or the build_manager() factory).

Simple managers (LifoManager, FifoManager) use a plain deque and impose pure stack / queue traversal with no priority ordering. For bound-based traversal strategies see Priority Managers.

BaseNodeManager

class bnbpy.cython.manager.BaseNodeManager

Bases: object

Base class for managing active nodes in a Branch & Bound search.

This class implements the Template Method pattern. Subclasses must implement the four abstract hooks:

  • _enqueue — add a node to the underlying data structure.

  • _dequeue — remove and return the next node.

  • _filter_by_lb — physically discard nodes with lb >= max_lb.

  • _clear — empty the underlying data structure.

All other public methods (enqueue, dequeue, size, not_empty, filter_by_lb, clear, get_lower_bound, memorize, forget, filter_memory_lb, clear_memory, enqueue_all) implement the template logic and should not be overridden.

clear()

Makes the manager empty.

dequeue()

Removes and returns the next node, updating bound_memory.

Returns:

The next node, or None if empty.

Return type:

Node

enqueue(node)

Adds a node to the manager and records it in bound_memory.

Parameters:

node (Node) – The node to add.

enqueue_all(nodes)

Adds a list of nodes to the manager.

Parameters:

nodes (list[Node]) – The list of nodes to add.

filter_by_lb(max_lb)

Remove nodes with lb >= max_lb and update bound_memory.

Parameters:

max_lb (float) – The maximum lower bound value (exclusive upper bound).

get_lower_bound()

Gets a node with the global minimum lower bound without removing it.

Returns:

A node with the lowest lower bound, or None if empty.

Return type:

Node

not_empty()

Checks if the manager is not empty.

Returns:

True if the manager is not empty, False otherwise.

Return type:

bool

size()

Returns the number of nodes in the manager.

Returns:

The number of nodes in the manager.

Return type:

int

LifoManager

class bnbpy.cython.manager.LifoManager

Bases: BaseNodeManager

Last-In First-Out (stack) node manager.

dequeue() returns the most recently enqueued node. get_lower_bound() returns a node with the minimum lb in O(1) via the inherited bound_memory mechanism.

FifoManager

class bnbpy.cython.manager.FifoManager

Bases: LifoManager

First-In First-Out (queue) node manager.

Identical to LifoManager except that dequeue() returns the oldest enqueued node (pop(0)).