58 explicit AssignmentState(
const size_t n = 0)
59 : row(0), total_cost(0), used_columns(n, 0), assigned_column(n, -1)
65class AssignmentBBDomain
73 using State = AssignmentState;
74 using Objective =
int;
82 bool is_complete(
const State &state)
const
84 return state.row == costs_.size();
87 Objective objective_value(
const State &state)
const
89 return state.total_cost;
92 Objective bound(
const State &state)
const
96 for (
size_t row = state.row; row < costs_.size(); ++row)
99 for (
size_t col = 0; col < costs_[row].size(); ++col)
101 best = costs_[row][col];
109 void apply(State &state,
const Move &move)
const
111 state.total_cost += costs_[state.row][move.col];
112 state.used_columns[move.col] = 1;
113 state.assigned_column[state.row] =
static_cast<int>(move.col);
117 void undo(State &state,
const Move &move)
const
120 state.total_cost -= costs_[state.row][move.col];
121 state.used_columns[move.col] = 0;
122 state.assigned_column[state.row] = -1;
125 template <
typename Visitor>
126 bool for_each_successor(
const State &state,
Visitor visit)
const
128 if (state.row >= costs_.size())
131 for (
size_t col = 0; col < costs_[state.row].size(); ++col)
144 std::cout <<
"Assignment:";
145 for (
size_t row = 0; row < state.assigned_column.size(); ++row)
146 std::cout <<
" row" << row <<
"->col" << state.assigned_column[row];
164 policy.
strategy = Search::ExplorationPolicy::Strategy::Best_First;
167 auto result =
engine.search(AssignmentState(
costs.size()));
169 std::cout <<
"Optimal assignment cost: " << result.incumbent.best_value() <<
'\n';
170 std::cout <<
"Visited states: " << result.stats.visited_states <<
'\n';
171 std::cout <<
"Pruned by bound: " << result.stats.pruned_by_bound <<
'\n';
Umbrella header for the implicit state-space search framework.
Simple dynamic array with automatic resizing and functional operations.
Reusable branch-and-bound engine over implicit state spaces.
User-facing facade exported by the umbrella search header.
and
Check uniqueness with explicit hash + equality functors.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
Exploration controls shared across engines.
Strategy strategy
Traversal strategy.
Objective policy for minimization problems.
Dynamic array container with automatic resizing.