3#ifndef LALA_POWER_SEARCH_TREE_HPP
4#define LALA_POWER_SEARCH_TREE_HPP
6#include "battery/vector.hpp"
7#include "battery/shared_ptr.hpp"
8#include "lala/logic/logic.hpp"
9#include "lala/universes/arith_bound.hpp"
10#include "lala/abstract_deps.hpp"
11#include "lala/vstore.hpp"
16template <
class A,
class S,
class Allocator>
class SearchTree;
19 struct is_search_tree_like {
20 static constexpr bool value =
false;
22 template<
class A,
class S,
class Alloc>
23 struct is_search_tree_like<SearchTree<A, S, Alloc>> {
24 static constexpr bool value =
true;
28template <
class A,
class Split,
class Allocator =
typename A::allocator_type>
43 constexpr static const bool sequential = sub_type::sequential;
52 constexpr static const char*
name =
"SearchTree";
54 template <
class Alloc>
64 template <
class SearchTreeTellType>
65 CUDA NI
tell_type(
const SearchTreeTellType& other,
const Alloc& alloc = Alloc{})
74 template <
class Alloc2>
82 template <
class A2,
class S2,
class Alloc2>
91 battery::vector<branch_type, allocator_type> stack;
94 using root_type = battery::tuple<sub_snapshot_type, split_snapshot_type>;
98 struct root_tell_type {
99 battery::vector<typename A::template tell_type<allocator_type>,
allocator_type> sub_tells;
100 battery::vector<typename split_type::template tell_type<allocator_type>,
allocator_type> split_tells;
101 CUDA root_tell_type(
const allocator_type& alloc): sub_tells(alloc), split_tells(alloc) {}
102 template <
class RootTellType>
103 CUDA root_tell_type(
const RootTellType& other,
const allocator_type& alloc)
104 : sub_tells(other.sub_tells, alloc), split_tells(other.split_tells, alloc) {}
106 root_tell_type root_tell;
112 , split(std::move(split))
114 , root(battery::make_tuple(this->a->
snapshot(alloc), this->split->
snapshot(alloc)))
118 template<
class A2,
class S2,
class Alloc2,
class... Allocators>
121 , a(deps.template clone<
sub_type>(other.a))
122 , split(deps.template clone<
split_type>(other.split))
135 return stack.get_allocator();
139 return stack.empty() && bool(a);
151 template <
class Alloc2>
164 template <
class SnapshotType>
165 CUDA
snapshot_type(
const SnapshotType& other,
const Alloc2& alloc = Alloc2())
178 template <
class Alloc2 = allocator_type>
184 template <
class Alloc2>
190 root = battery::make_tuple(
197 template <
bool diagnose = false,
class F,
class Env,
class Alloc2>
200 if(f.is(F::ESeq) && f.esig() ==
"search") {
208 template <
bool diagnose = false,
class F,
class Env,
class Alloc2>
214 template <IKind kind,
bool diagnose = false,
class F,
class Env,
class I>
215 CUDA NI
bool interpret(
const F& f, Env& env, I& intermediate, IDiagnostics& diagnostics)
const {
216 if constexpr(kind == IKind::TELL) {
225 template <
class Alloc>
226 CUDA local::B deduce_current(
const tell_type<Alloc>& t) {
227 local::B has_changed = a->deduce(t.sub_tell);
228 has_changed |= split->deduce(t.split_tell);
233 template <
class Alloc>
238 root_tell.sub_tells.push_back(t.
sub_tell);
239 root_tell.split_tells.push_back(t.
split_tell);
242 return deduce_current(t);
253 return pop(push(split->split()));
256 template <
class ExtractionStrategy = NonAtomicExtraction>
257 CUDA
bool is_extractable(
const ExtractionStrategy& strategy = ExtractionStrategy())
const {
258 return !
is_bot() && a->is_extractable(strategy);
265 if constexpr(impl::is_search_tree_like<B>::value) {
269 ua.root_tell.sub_tells.clear();
270 ua.root_tell.split_tells.clear();
282 return local_universe::bot();
286 return a->project(x);
290 return local_universe::top();
303 template <
class Univ>
326 if(branch.size() > 0) {
328 root = battery::make_tuple(
332 stack.push_back(std::move(branch));
339 CUDA
bool pop(
bool pruned) {
341 return commit_left();
344 bool has_changed = backtrack();
345 has_changed |= commit_right();
352 CUDA
bool commit_left() {
354 return a->deduce(stack.back().next());
358 CUDA
bool commit_right() {
368 CUDA
bool backtrack() {
369 while(!stack.empty() && !stack.back().has_next()) {
373 a->restore(battery::get<0>(root));
374 split->restore(battery::get<1>(root));
375 return deduce_root();
386 CUDA
bool deduce_root() {
387 bool has_changed =
false;
388 if(root_tell.sub_tells.size() > 0 || root_tell.split_tells.size() > 0) {
389 for(
int i = 0; i < root_tell.sub_tells.size(); ++i) {
390 has_changed |= a->deduce(root_tell.sub_tells[i]);
392 for(
int i = 0; i < root_tell.split_tells.size(); ++i) {
393 has_changed |= split->deduce(root_tell.split_tells[i]);
395 root_tell.sub_tells.clear();
396 root_tell.split_tells.clear();
398 root = battery::make_tuple(
407 bool has_changed =
false;
408 for(
int i = 0; i < stack.size(); ++i) {
409 has_changed |= a->deduce(stack[i].current());
Definition search_tree.hpp:29
CUDA size_t depth() const
Definition search_tree.hpp:319
typename A::template ask_type< Alloc > ask_type
Definition search_tree.hpp:79
static constexpr const bool injective_concretization
Definition search_tree.hpp:50
CUDA bool is_extractable(const ExtractionStrategy &strategy=ExtractionStrategy()) const
Definition search_tree.hpp:257
static constexpr const bool preserve_top
Definition search_tree.hpp:46
static constexpr const bool preserve_bot
Definition search_tree.hpp:45
CUDA local::B is_bot() const
Definition search_tree.hpp:147
typename A::universe_type universe_type
Definition search_tree.hpp:35
A sub_type
Definition search_tree.hpp:37
CUDA void restore(const snapshot_type< Alloc2 > &snap)
Definition search_tree.hpp:185
CUDA local::B deduce(const tell_type< Alloc > &t)
Definition search_tree.hpp:234
static constexpr const bool preserve_meet
Definition search_tree.hpp:49
typename split_type::branch_type branch_type
Definition search_tree.hpp:34
CUDA NI bool interpret_ask(const F &f, Env &env, ask_type< Alloc2 > &ask, IDiagnostics &diagnostics) const
Definition search_tree.hpp:209
typename A::allocator_type sub_allocator_type
Definition search_tree.hpp:32
CUDA allocator_type get_allocator() const
Definition search_tree.hpp:134
CUDA NI bool interpret_tell(const F &f, Env &env, tell_type< Alloc2 > &tell, IDiagnostics &diagnostics) const
Definition search_tree.hpp:198
static constexpr const bool preserve_concrete_covers
Definition search_tree.hpp:51
static constexpr const char * name
Definition search_tree.hpp:52
static constexpr const bool preserve_join
Definition search_tree.hpp:48
CUDA local_universe project(AVar x) const
Definition search_tree.hpp:280
CUDA AType aty() const
Definition search_tree.hpp:130
CUDA NI bool interpret(const F &f, Env &env, I &intermediate, IDiagnostics &diagnostics) const
Definition search_tree.hpp:215
static constexpr const bool sequential
Definition search_tree.hpp:43
CUDA void extract(B &ua) const
Definition search_tree.hpp:264
static constexpr const bool is_totally_ordered
Definition search_tree.hpp:44
abstract_ptr< split_type > split_ptr
Definition search_tree.hpp:39
abstract_ptr< sub_type > sub_ptr
Definition search_tree.hpp:38
static constexpr const bool is_abstract_universe
Definition search_tree.hpp:42
Allocator allocator_type
Definition search_tree.hpp:31
CUDA SearchTree(AType uid, sub_ptr a, split_ptr split, const allocator_type &alloc=allocator_type())
Definition search_tree.hpp:109
CUDA local::B is_top() const
Definition search_tree.hpp:142
CUDA snapshot_type< Alloc2 > snapshot(const Alloc2 &alloc=Alloc2()) const
Definition search_tree.hpp:179
CUDA NI SearchTree(const SearchTree< A2, S2, Alloc2 > &other, AbstractDeps< Allocators... > &deps)
Definition search_tree.hpp:119
CUDA local::B is_singleton() const
Definition search_tree.hpp:138
typename universe_type::local_type local_universe
Definition search_tree.hpp:36
CUDA bool deduce()
Definition search_tree.hpp:252
Split split_type
Definition search_tree.hpp:33
CUDA void project(AVar x, Univ &r) const
Definition search_tree.hpp:304
Definition search_tree.hpp:152
CUDA snapshot_type(const SnapshotType &other, const Alloc2 &alloc=Alloc2())
Definition search_tree.hpp:165
snapshot_type< Alloc2 > & operator=(const snapshot_type< Alloc2 > &)=default
split_type::template snapshot_type< Alloc2 > split_snap_type
Definition search_tree.hpp:154
snapshot_type(snapshot_type< Alloc2 > &&)=default
snapshot_type< Alloc2 > & operator=(snapshot_type< Alloc2 > &&)=default
snapshot_type(const snapshot_type< Alloc2 > &)=default
sub_ptr sub
Definition search_tree.hpp:157
CUDA snapshot_type(sub_snap_type &&sub_snap, split_snap_type &&split_snap, sub_ptr sub)
Definition search_tree.hpp:171
sub_type::template snapshot_type< Alloc2 > sub_snap_type
Definition search_tree.hpp:153
sub_snap_type sub_snap
Definition search_tree.hpp:155
split_snap_type split_snap
Definition search_tree.hpp:156
Definition search_tree.hpp:55
tell_type & operator=(const tell_type &)=default
tell_type(tell_type &&)=default
tell_type & operator=(tell_type &&)=default
tell_type(const tell_type &)=default
CUDA tell_type(const Alloc &alloc=Alloc{})
Definition search_tree.hpp:58
split_type::template tell_type< Alloc > split_tell
Definition search_tree.hpp:57
CUDA NI tell_type(const SearchTreeTellType &other, const Alloc &alloc=Alloc{})
Definition search_tree.hpp:65
CUDA allocator_type get_allocator() const
Definition search_tree.hpp:70
A::template tell_type< Alloc > sub_tell
Definition search_tree.hpp:56
Alloc allocator_type
Definition search_tree.hpp:69