|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Reference example: comparing Depth-First and Best-First strategies in Branch-and-Bound on a 0/1 knapsack problem. More...
#include <cstddef>#include <iostream>#include <string>#include <Branch_And_Bound.H>#include <tpl_array.H>Go to the source code of this file.
Classes | |
| struct | Item |
| struct | KnapsackState |
| class | KnapsackDomain |
| struct | KnapsackDomain::Move |
Functions | |
| static void | run_strategy (const Array< Item > &items, double capacity, ExplorationPolicy::Strategy strategy, const std::string &label) |
| int | main () |
Reference example: comparing Depth-First and Best-First strategies in Branch-and-Bound on a 0/1 knapsack problem.
The 0/1 knapsack problem assigns a binary decision (include / exclude) to each item. Branch-and-Bound prunes subtrees whose optimistic upper bound cannot beat the current incumbent.
Depth-First (the default) quickly finds a first feasible solution and tightens the bound early, but may explore many nodes before proving optimality.
Best-First expands nodes in decreasing order of their optimistic bound, so it tends to reach the optimum with fewer expansions — at the cost of maintaining a priority queue.
This example runs both strategies on the same instance and prints the results side-by-side.
Build and run:
cmake --build build --target branch_and_bound_df_vs_bf_example./build/Examples/branch_and_bound_df_vs_bf_example Definition in file branch_and_bound_df_vs_bf_example.cc.
| int main | ( | ) |
Definition at line 232 of file branch_and_bound_df_vs_bf_example.cc.
References run_strategy().
|
static |
Definition at line 203 of file branch_and_bound_df_vs_bf_example.cc.
References engine, and Aleph::ExplorationPolicy::strategy.
Referenced by main().