64struct ArtificialMaxDomain
66 using State = ArtificialState;
67 using Move = ArtificialMove;
68 using Objective =
int;
70 bool is_complete(
const State &state)
const
72 return state.depth == 2;
75 Objective objective_value(
const State &state)
const
80 Objective bound(
const State &state)
const
87 default:
return state.value;
91 void apply(State &state,
const Move &move)
const
93 state.code = move.target_code;
94 state.value += move.delta;
98 void undo(State &state,
const Move &move)
const
101 state.value -= move.delta;
105 template <
typename Visitor>
106 bool for_each_successor(
const State &state,
Visitor visit)
const
108 if (state.depth >= 2)
116 return visit(Move{3, 0,
'R'});
121 return visit(Move{5, 9,
'R'});
126 return visit(Move{7, 4,
'R'});
134struct ArtificialMinDomain
136 using State = ArtificialState;
137 using Move = ArtificialMove;
138 using Objective =
int;
140 bool is_complete(
const State &state)
const
142 return state.depth == 2;
145 Objective objective_value(
const State &state)
const
150 Objective bound(
const State &state)
const
157 default:
return state.value;
161 void apply(State &state,
const Move &move)
const
163 state.code = move.target_code;
164 state.value += move.delta;
168 void undo(State &state,
const Move &move)
const
171 state.value -= move.delta;
175 template <
typename Visitor>
176 bool for_each_successor(
const State &state,
Visitor visit)
const
178 if (state.depth >= 2)
186 return visit(Move{3, 0,
'R'});
191 return visit(Move{5, 6,
'R'});
196 return visit(Move{7, 9,
'R'});
204struct ArtificialMaxBadOrderDomain
206 using State = ArtificialState;
207 using Move = ArtificialMove;
208 using Objective =
int;
210 bool is_complete(
const State &state)
const
212 return state.depth == 2;
215 Objective objective_value(
const State &state)
const
220 Objective bound(
const State &state)
const
227 default:
return state.value;
231 void apply(State &state,
const Move &move)
const
233 state.code = move.target_code;
234 state.value += move.delta;
238 void undo(State &state,
const Move &move)
const
241 state.value -= move.delta;
245 template <
typename Visitor>
246 bool for_each_successor(
const State &state,
Visitor visit)
const
248 if (state.depth >= 2)
256 return visit(Move{2, 0,
'L'});
261 return visit(Move{5, 9,
'R'});
266 return visit(Move{7, 4,
'R'});
277 for (
const auto &move : path)
282template <
typename Result>
283void print_summary(
const char *title,
const Result &result)
285 std::cout << title <<
'\n';
286 std::cout <<
" objective: " << result.incumbent.best_value() <<
'\n';
287 std::cout <<
" path: " <<
signature(result.incumbent.get().path) <<
'\n';
288 std::cout <<
" visited: " << result.stats.visited_states <<
'\n';
289 std::cout <<
" pruned by bound: " << result.stats.pruned_by_bound <<
'\n';
290 std::cout <<
" ordered batches: " << result.stats.move_ordering.ordered_batches <<
'\n';
298 print_summary(
"Maximization (depth-first, domain order)",
max_plain);
306 print_summary(
"Maximization (depth-first, bound-ordered)",
max_ordered);
314 print_summary(
"Maximization (best-first)",
max_best);
318 min_policy.strategy = ExplorationPolicy::Strategy::Best_First;
323 print_summary(
"Minimization (best-first)",
min_result);
Umbrella header for the implicit state-space search framework.
Reusable branch-and-bound engine over implicit state spaces.
static ExplorationPolicy default_policy() noexcept
Return the default branch-and-bound exploration policy.
Result search(State initial_state)
Execute branch and bound and keep only the incumbent.
Main namespace for Aleph-w library functions.
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.
std::string code(Node *root)
Compute a string with the Lukasiewicz`s word of a tree.
auto branch_and_bound_search(Domain domain, typename Domain::State initial_state, ExplorationPolicy policy=Branch_And_Bound< Domain, ObjectivePolicy >::default_policy(), SearchLimits limits={}, ObjectivePolicy objective={})
Convenience wrapper for one-shot branch and bound.
Exploration controls shared across engines.
Objective policy for minimization problems.