Class BranchAndBound
java.lang.Object
topics.branchandbound.utils.BranchAndBound
- Direct Known Subclasses:
AgentsTasks, EightPuzzle, RectanglesPlacement, RectanglesPlacementTestTime, StringInterleavingGenerator
Branch and Bound Execution Engine
An abstract base class that provides the core algorithmic framework for solving combinatorial optimization problems using the Branch and Bound paradigm.
This engine manages the state space tree explicitly using a custom priority queue (Heap) to implement a Best-First Search strategy. It actively tracks the global upper bound to prune sub-optimal branches systematically.
- Author:
- vicegd
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected NodeThe node representing the optimal valid configuration discovered during execution.protected intThe global upper bound metric used to prune paths mathematically incapable of yielding a better outcome than the currently discovered optimal solution.protected HeapThe priority queue managing the active, unexplored nodes in the state space tree.protected NodeThe origin state of the problem. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInitializes the fundamental memory structures required for the execution engine. -
Method Summary
Modifier and TypeMethodDescriptionvoidbranchAndBound(Node initialNode) Executes the primary Branch and Bound systemic loop.Retrieves the node encapsulating the mathematically optimal path or configuration.Retrieves the foundational starting state of the problem.voidExtracts and logs the complete topological lineage of the optimal path, detailing every state transition from the root node to the final solution leaf.
-
Field Details
-
nodeHeap
The priority queue managing the active, unexplored nodes in the state space tree. -
bestNode
The node representing the optimal valid configuration discovered during execution. -
rootNode
The origin state of the problem. -
globalUpperBound
protected int globalUpperBoundThe global upper bound metric used to prune paths mathematically incapable of yielding a better outcome than the currently discovered optimal solution.
-
-
Constructor Details
-
BranchAndBound
protected BranchAndBound()Initializes the fundamental memory structures required for the execution engine.
-
-
Method Details
-
branchAndBound
Executes the primary Branch and Bound systemic loop.It continuously extracts the most promising state, expands its children, updates the optimal benchmark if a leaf solution is reached, and prunes branches that violate the bounding constraints.
- Parameters:
initialNode- The starting mathematical state of the problem environment.
-
getRootNode
Retrieves the foundational starting state of the problem.- Returns:
- The root node of the execution tree.
-
getBestNode
Retrieves the node encapsulating the mathematically optimal path or configuration.- Returns:
- The best discovered node, or
nullif no valid solution exists.
-
printSolutionTrace
public void printSolutionTrace()Extracts and logs the complete topological lineage of the optimal path, detailing every state transition from the root node to the final solution leaf.
-