Class HeapThreads
java.lang.Object
topics.branchandbound.utils.threads.HeapThreads
Concurrent State Space Queue (Heap)
Manages the frontier of unexplored nodes during a multithreaded Branch and Bound execution. This data structure ensures thread-safe prioritization, extraction, and duplicate-state detection across parallel workers.
*Architecture invalid input: '&' Complexity
- Priority Queue: Utilizes a
PriorityBlockingQueueto maintain the Best-First Search ordering concurrently. Extraction isO(log N). - Lineage Tracking: Employs a
ConcurrentMapto link extracted states back to their parents for final path reconstruction. Lookup isO(1). - Duplicate Pruning: Integrates a concurrent
Setto track topologically equivalent states, preventing redundant exploration loops inO(1)time.
- Author:
- vicegd
-
Constructor Summary
ConstructorsConstructorDescriptionInitializes the concurrent collections required to manage the state space. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Flushes all active nodes from the priority queue.intPeeks at the most promising active node to estimate the current best theoretical outcome without removing it from the queue.Thread-safe retrieval and removal of the highest-priority node from the frontier.extractUsedNodesFrom(Node targetNode) Traces the ancestral lineage of a specific node back to the root of the execution tree.voidSafely inserts a new node into the priority queue if it has not been explored previously.booleanisEmpty()Evaluates whether the active frontier contains any pending nodes.
-
Constructor Details
-
HeapThreads
public HeapThreads()Initializes the concurrent collections required to manage the state space.
-
-
Method Details
-
clear
public void clear()Flushes all active nodes from the priority queue.Note: This does not clear the lineage or explored states registries, preserving the historical context of the execution.
-
insert
Safely inserts a new node into the priority queue if it has not been explored previously.- Parameters:
node- The mathematical state node to be evaluated for insertion.
-
isEmpty
public boolean isEmpty()Evaluates whether the active frontier contains any pending nodes.- Returns:
trueif the priority queue is empty;falseotherwise.
-
estimateBest
public int estimateBest()Peeks at the most promising active node to estimate the current best theoretical outcome without removing it from the queue.- Returns:
- The heuristic value of the highest-priority node, or
Integer.MAX_VALUEif the queue is temporarily empty.
-
extractBestNode
Thread-safe retrieval and removal of the highest-priority node from the frontier. Registers the extracted node in the lineage and explored-state trackers.- Returns:
- The optimal pending node, or
nullif the queue is empty.
-
extractUsedNodesFrom
Traces the ancestral lineage of a specific node back to the root of the execution tree.- Parameters:
targetNode- The terminal node (typically the optimal solution leaf).- Returns:
- A chronologically ordered list representing the path from the target node up to the root node.
-