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)
114 if (not visit(Move{2, 0,
'L'}))
116 return visit(Move{3, 0,
'R'});
119 if (not visit(Move{4, 7,
'L'}))
121 return visit(Move{5, 9,
'R'});
124 if (not visit(Move{6, 5,
'L'}))
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)
184 if (not visit(Move{2, 0,
'L'}))
186 return visit(Move{3, 0,
'R'});
189 if (not visit(Move{4, 8,
'L'}))
191 return visit(Move{5, 6,
'R'});
194 if (not visit(Move{6, 7,
'L'}))
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)
254 if (not visit(Move{3, 0,
'R'}))
256 return visit(Move{2, 0,
'L'});
259 if (not visit(Move{4, 7,
'L'}))
261 return visit(Move{5, 9,
'R'});
264 if (not visit(Move{6, 5,
'L'}))
266 return visit(Move{7, 4,
'R'});
277 for (
const auto &move : path)
278 out.push_back(move.label);
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);
302 ordered_policy.
move_ordering = MoveOrderingMode::Estimated_Bound;
306 print_summary(
"Maximization (depth-first, bound-ordered)", max_ordered);
310 max_best_policy.
strategy = ExplorationPolicy::Strategy::Best_First;
314 print_summary(
"Maximization (best-first)", max_best);
318 min_policy.
strategy = ExplorationPolicy::Strategy::Best_First;
322 auto min_result = min_engine.
search(ArtificialState{});
323 print_summary(
"Minimization (best-first)", min_result);
Umbrella header for the implicit state-space search framework.
size_t size_t int32_t value
size_t size_t int32_t * out
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.
constexpr std::uint32_t delta
File contains only the cells that changed relative to a baseline.
Main namespace for Aleph-w library functions.
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.
Strategy strategy
Traversal strategy.
MoveOrderingMode move_ordering
Successor-ordering mode.
Objective policy for minimization problems.