Clingo
Loading...
Searching...
No Matches
solver.hh
1#pragma once
2
3#include <clingo/control/grounder.hh>
4
5#include <clingo/output/backend.hh>
6
7#include <clasp/clasp_facade.h>
8#include <clasp/cli/clasp_options.h>
9
10namespace CppClingo::Control {
11
14
15class Solver;
16
21 public:
23 void main(Solver &slv) { do_main(slv); }
25 void exec(std::string_view code) { do_exec(code); }
26
27 private:
28 virtual void do_exec(std::string_view code) = 0;
29 virtual void do_main(Solver &slv) = 0;
30};
32using UScript = std::unique_ptr<Script>;
33
39 public:
41 void register_script(std::string_view name, UScript script);
43 void main(Solver &slv);
44
45 private:
46 void do_exec(Location const &loc, Logger &log, std::string_view name, std::string_view code) override;
47 auto do_callable(std::string_view name, size_t args) -> bool override;
48 void do_call(Location const &loc, std::string_view name, SymbolSpan args, SymbolVec &out) override;
49
50 std::vector<std::pair<std::string, UScript>> scripts_;
51};
52
54enum class IStop : uint8_t {
55 none,
56 sat,
57 unsat,
58 unknown
59};
60
62enum class AppMode : uint8_t {
63 parse,
64 rewrite,
65 ground,
66 solve
67};
68
74 size_t imin = 0;
76 std::optional<size_t> imax = std::nullopt;
80 bool single_shot = false;
82 bool profile = false;
83};
84
86enum class SymbolSelectFlags : uint8_t {
87 none = 0,
88 shown = 1,
89 atoms = 2,
90 terms = 4,
91 theory = 8,
92 all = 15,
93};
96
98enum class ModelType : uint8_t {
99 model = 0,
102};
103
105enum class ConsequenceType : uint8_t {
106 false_ = 0,
107 true_ = 1,
108 unknown = 2
109};
110
113 public:
116
125 template <class F> auto add(Symbol sym, F &&fun) -> prg_id_t {
126 auto [it, ins] = map_.emplace(sym, 0);
127 if (ins) {
128 it.value() = std::invoke(std::forward<F>(fun));
129 }
130 return it.value();
131 }
132
139 void add(Symbol sym, prg_id_t id) {
140 if (!map_.emplace(sym, id).second) {
141 throw std::runtime_error("collision of term ids");
142 }
143 }
144
149 [[nodiscard]] auto term_id(size_t i) const -> prg_id_t {
150 if (i < size()) {
151 return map_.nth(i).value();
152 }
153 throw std::range_error{"index out of range"};
154 }
155
160 [[nodiscard]] auto symbol(size_t i) const -> Symbol {
161 if (i < size()) {
162 return *map_.nth(i).key();
163 }
164 throw std::range_error{"index out of range"};
165 }
166
174 [[nodiscard]] auto index(Symbol sym) const -> size_t { return map_.find(sym) - map_.begin(); }
175
179 [[nodiscard]] auto size() const -> size_t { return map_.size(); }
180
185 [[nodiscard]] auto begin() const -> Map::const_iterator { return map_.cbegin(); }
186
191 [[nodiscard]] auto end() const -> Map::const_iterator { return map_.cend(); }
192
193 private:
195};
196
198class BaseView {
199 public:
201 virtual ~BaseView() = default;
203 [[nodiscard]] auto bases() const -> Ground::Bases const & { return do_bases(); }
205 [[nodiscard]] auto term_base() const -> TermBaseMap const & { return do_term_base(); }
207 [[nodiscard]] auto clasp_program() const -> Clasp::Asp::LogicProgram const & { return do_clasp_program(); }
209 [[nodiscard]] auto clasp_theory() const -> Potassco::TheoryData const & { return clasp_program().theoryData(); }
210
211 private:
212 [[nodiscard]] virtual auto do_bases() const -> Ground::Bases const & = 0;
213 [[nodiscard]] virtual auto do_term_base() const -> TermBaseMap const & = 0;
214 [[nodiscard]] virtual auto do_clasp_program() const -> Clasp::Asp::LogicProgram const & = 0;
215};
216
218class SolveControl : public BaseView {
219 public:
221 void add_clause(PrgLitSpan lits) { do_add_clause(lits); }
222
223 private:
224 virtual void do_add_clause(PrgLitSpan lits) = 0;
225};
226
228class Model {
229 public:
230 virtual ~Model() = default;
231
236 void symbols(SymbolSelectFlags type, SymbolVec &res) const { do_symbols(type, res); }
240 [[nodiscard]] auto number() const -> uint64_t { return do_number(); }
244 [[nodiscard]] auto type() const -> ModelType { return do_type(); }
249 [[nodiscard]] auto contains(Symbol sym) const -> bool { return do_contains(sym); }
254 [[nodiscard]] auto is_true(prg_lit_t lit) const -> bool { return do_is_true(lit); }
259 [[nodiscard]] auto is_consequence(prg_lit_t lit) const -> ConsequenceType { return do_is_consequence(lit); }
263 [[nodiscard]] auto costs() const -> std::span<prg_sum_t const> { return do_costs(); }
267 [[nodiscard]] auto priorities() const -> std::span<prg_weight_t const> { return do_priorities(); }
271 [[nodiscard]] auto optimality_proven() const -> bool { return do_optimality_proven(); }
275 [[nodiscard]] auto thread_id() const -> prg_id_t { return do_thread_id(); }
279 [[nodiscard]] auto context() -> SolveControl & { return do_control(); }
280
282 virtual void extend(SymbolSpan symbols) { do_extend(symbols); }
283
284 private:
285 virtual void do_symbols(SymbolSelectFlags type, SymbolVec &res) const = 0;
286 [[nodiscard]] virtual auto do_number() const -> uint64_t = 0;
287 [[nodiscard]] virtual auto do_type() const -> ModelType = 0;
288 [[nodiscard]] virtual auto do_contains(Symbol sym) const -> bool = 0;
289 virtual void do_extend(SymbolSpan symbols) = 0;
290 [[nodiscard]] virtual auto do_is_true(prg_lit_t lit) const -> bool = 0;
291 [[nodiscard]] virtual auto do_is_consequence(prg_lit_t lit) const -> ConsequenceType = 0;
292 [[nodiscard]] virtual auto do_costs() const -> std::span<prg_sum_t const> = 0;
293 [[nodiscard]] virtual auto do_priorities() const -> std::span<prg_weight_t const> = 0;
294 [[nodiscard]] virtual auto do_optimality_proven() const -> bool = 0;
295 [[nodiscard]] virtual auto do_thread_id() const -> prg_id_t = 0;
296 [[nodiscard]] virtual auto do_control() -> SolveControl & = 0;
297};
299using UModel = std::unique_ptr<Model>;
300
305enum class SolveResult : uint8_t {
306 empty = 0,
307 satisfiable = 1,
308 unsatisfiable = 2,
309 exhausted = 4,
310 interrupted = 8,
311};
314
317 public:
319 virtual ~SolveHandle() = default;
320
326 auto get() -> SolveResult { return do_get(); }
330 void cancel() { do_cancel(); }
336 void resume() { do_resume(); }
346 auto model() -> Model const * { return do_model(); }
352 auto last() -> Model const * { return do_last(); }
359 auto core() -> PrgLitSpan { return do_core(); }
369 auto wait(double timeout) -> bool { return do_wait(timeout); }
370
371 private:
372 virtual auto do_get() -> SolveResult = 0;
373 virtual void do_cancel() = 0;
374 virtual void do_resume() = 0;
375 virtual auto do_model() -> Model const * = 0;
376 virtual auto do_last() -> Model const * = 0;
377 virtual auto do_core() -> PrgLitSpan = 0;
378 virtual auto do_wait(double timeout) -> bool = 0;
379};
381using USolveHandle = std::unique_ptr<SolveHandle>;
382
385 public:
386 virtual ~EventHandler() = default;
387
394 auto on_model(Model &mdl) -> bool { return do_on_model(mdl); }
402 void on_stats(Potassco::AbstractStatistics &stats) { do_on_stats(stats); }
409 void on_unsat(Clasp::SumView bound) { do_on_unsat(bound); }
414 void on_core(Potassco::LitSpan core) { do_on_core(core); }
421 void on_finish(SolveResult result) { do_on_finish(result); }
422
423 private:
424 virtual auto do_on_model([[maybe_unused]] Model &mdl) -> bool { return true; }
425 virtual void do_on_stats([[maybe_unused]] Potassco::AbstractStatistics &stats) {}
426 virtual void do_on_unsat([[maybe_unused]] Clasp::SumView bound) {}
427 virtual void do_on_core([[maybe_unused]] Potassco::LitSpan core) {}
428 virtual void do_on_finish([[maybe_unused]] SolveResult result) {}
429};
431using UEventHandler = std::unique_ptr<EventHandler>;
432
436enum class SolveMode : uint8_t {
437 none = 0,
438 async = 1,
439 yield = 2,
440};
443
457 public:
461 [[nodiscard]] auto program() -> Clasp::Asp::LogicProgram & { return do_program(); }
465 [[nodiscard]] auto theory() -> Output::TheoryData & { return do_theory(); }
469 [[nodiscard]] auto store() -> SymbolStore & { return do_store(); }
476 [[nodiscard]] auto add_atom(Symbol atom) -> prg_lit_t { return do_add_atom(atom); }
481 void close() { do_close(); }
483 virtual ~BackendHandle() = default;
484
485 private:
486 virtual auto do_program() -> Clasp::Asp::LogicProgram & = 0;
487 virtual auto do_theory() -> Output::TheoryData & = 0;
488 virtual auto do_store() -> SymbolStore & = 0;
489 virtual auto do_add_atom(Symbol atom) -> prg_lit_t = 0;
490 virtual void do_close() = 0;
491};
493using UBackendHandle = std::unique_ptr<BackendHandle>;
494
496class Propagator : public Potassco::AbstractPropagator, public Potassco::AbstractHeuristic {
497 public:
499 [[nodiscard]] virtual auto hasHeuristic() const -> bool = 0;
500};
502using UPropagator = std::unique_ptr<Propagator>;
503
509 public:
511 void lock() {
512 if (mut_) {
513 mut_->lock();
514 }
515 }
517 void unlock() {
518 if (mut_) {
519 mut_->unlock();
520 }
521 }
523 void enable(bool state) {
524 if (!state) {
525 mut_.reset();
526 } else if (!mut_) {
527 mut_.emplace();
528 mut_->lock();
529 }
530 }
531
532 private:
533 std::optional<std::mutex> mut_;
534};
535
537template <class M> class unlock_guard {
538 public:
540 explicit unlock_guard(M &mut) : mut_{&mut} { mut_->unlock(); }
542 unlock_guard(const unlock_guard &) = delete;
543 ~unlock_guard() { mut_->lock(); }
544 auto operator=(const unlock_guard &) -> unlock_guard & = delete;
545
546 private:
547 M *mut_;
548};
549
552 public:
554 void init(CppClingo::Control::BaseView &view, std::ostream &out);
558 void end_step();
560 auto out() -> std::ostream & { return *out_; }
561
562 private:
563 struct State {
564 State() = default;
565 size_t atom : 1 = 0;
566 size_t term : 1 = 0;
567 size_t index : (8 * sizeof(size_t)) - 2 = 0;
568 };
569
570 auto output(CppClingo::Symbol const &sym) -> State &;
571
572 CppClingo::Control::BaseView *view_ = nullptr;
573 std::ostream *out_ = nullptr;
574 size_t ids_ = 0;
575 std::vector<size_t> buf_;
577};
579using USymbolTable = std::unique_ptr<SymbolTable>;
580
584class Solver : public BaseView {
585 public:
587 Solver(Clasp::ClaspFacade &clasp, Clasp::Cli::ClaspCliConfig &config, Logger &log, SymbolStore &store,
588 Scripts &scripts, Input::RewriteOptions ropts, SolverOptions sopts, FILE *out = stdout);
589
591 void main(std::span<std::string_view const> const &files);
593 void main();
594
598 void parse(std::string_view str);
600 void parse(std::span<std::string_view const> const &files);
602 void parse_with(std::function<void(ProgramBackend *, TheoryBackend *)> cb);
603
605 void add_const(String name, Symbol value);
607 [[nodiscard]] auto const_map() -> Input::ConstMap const &;
609 void ground(ProgramParamVec const &params, Ground::ScriptCallback *ctx);
616 auto solve(UEventHandler handler = {}, PrgLitSpan assumptions = {}, SolveMode mode = SolveMode::none)
617 -> USolveHandle;
618
620 void output_unprocessed_program(std::ostream &out);
621
623 void output_program(std::ostream &out);
624
626 auto map_model(Clasp::Model const &mdl) -> Model &;
627
632 [[nodiscard]] auto buf() -> Util::OutputBuffer & { return buf_; };
633
638 [[nodiscard]] auto backend() -> UBackendHandle;
639
641 [[nodiscard]] auto clasp_facade() -> Clasp::ClaspFacade & { return *clasp_; }
642
644 [[nodiscard]] auto clasp_facade() const -> Clasp::ClaspFacade const & { return *clasp_; }
645
647 [[nodiscard]] auto clasp_config() -> Clasp::Cli::ClaspCliConfig & {
648 return clasp_config_ != nullptr ? *clasp_config_ : throw std::runtime_error("not in solving mode");
649 }
650
652 [[nodiscard]] auto clasp_stats() -> Potassco::AbstractStatistics const & {
653 auto const *stats = clasp_->getStats();
654 return stats != nullptr ? *stats : throw std::runtime_error("not in solving mode");
655 }
656
661
663 auto get_lock() -> CallbackLock & { return lock_; }
664
666 void block_main(bool block) { block_main_ = block; }
667
669 [[nodiscard]] auto get_mode() const -> AppMode { return opts_.mode; }
670
672 auto user_data() -> void *& { return data_; }
673
675 void interrupt() noexcept;
676
678 [[nodiscard]] auto get_parts() -> std::optional<Input::StmParts> const & { return grd_.get_parts(); }
679
681 void set_parts(std::optional<Input::StmParts> parts) { grd_.set_parts(std::move(parts)); }
684 auto pos = Position{*grd_.store().string("<cmd>"), 1, 1};
685 auto loc = Location{pos, pos};
686 grd_.set_parts(std::make_optional<Input::StmParts>(loc, Input::Precedence::override_, std::move(parts)));
687 }
688
690 void show(Input::SharedSig const &sig) { grd_.show(sig); }
691
693 auto sym_tab() -> SymbolTable & {
694 if (!sym_tab_) {
695 sym_tab_ = std::make_unique<SymbolTable>();
696 }
697 return *sym_tab_;
698 }
699
700 private:
701 class ProgramBackendAdapter;
702
710 enum class State : uint8_t {
711 initial, //< initial step
712 grounded, //< step has been grounded
713 prepared, //< step is prepared for solving
714 solved, //< step has been solved
715 };
716
724 auto make_output_(SymbolStore &store, AppMode mode) -> UOutputStm;
725
727 void prepare_();
728
730 void simplify_();
731
733 void enable_updates_();
734
735 [[nodiscard]] auto do_bases() const -> Ground::Bases const & override { return grd_.base(); }
736
737 [[nodiscard]] auto do_term_base() const -> TermBaseMap const & override { return terms_; }
738
739 [[nodiscard]] auto do_clasp_program() const -> Clasp::Asp::LogicProgram const & override {
740 return clasp_->asp() != nullptr ? *clasp_->asp() : throw std::runtime_error("not in solving mode");
741 }
742
743 void incmode_();
744
745 CallbackLock lock_;
746 std::vector<UPropagator> propagators_;
747 TermBaseMap terms_;
748 Clasp::ClaspFacade *clasp_;
749 Clasp::Cli::ClaspCliConfig *clasp_config_;
750 Util::OutputBuffer buf_;
751 UProgramBackend backend_;
752 std::unique_ptr<Output::TheoryData> theory_;
753 UOutputStm out_;
754 UModel mdl_;
755 USymbolTable sym_tab_;
756 Grounder grd_;
757 Scripts *scripts_;
758 State state_ = State::initial;
759 SolverOptions opts_;
760 BuiltinIncludes includes_ = BuiltinIncludes::empty;
761 void *data_ = nullptr;
762 bool block_main_ = false;
763};
764
766
767} // namespace CppClingo::Control
Object to provide access to the backend.
Definition solver.hh:456
auto store() -> SymbolStore &
The symbol store.
Definition solver.hh:469
auto theory() -> Output::TheoryData &
Get the theory.
Definition solver.hh:465
void close()
Close the handle.
Definition solver.hh:481
auto program() -> Clasp::Asp::LogicProgram &
Get the logic program.
Definition solver.hh:461
virtual ~BackendHandle()=default
Destroy the handle.
auto add_atom(Symbol atom) -> prg_lit_t
Add a literal for the given symbol.
Definition solver.hh:476
Interface providing the necessary data to inspect atom, term, and theory bases.
Definition solver.hh:198
auto clasp_theory() const -> Potassco::TheoryData const &
Get a reference to the underlying facade.
Definition solver.hh:209
virtual ~BaseView()=default
The default destructor.
auto bases() const -> Ground::Bases const &
Get a reference to the underlying atom bases.
Definition solver.hh:203
auto term_base() const -> TermBaseMap const &
Get a reference to the underlying term bases.
Definition solver.hh:205
auto clasp_program() const -> Clasp::Asp::LogicProgram const &
Get a reference to the underlying facade.
Definition solver.hh:207
This lock ensures that callbacks during solving are called in lock-step.
Definition solver.hh:508
void enable(bool state)
Enable or disable the lock.
Definition solver.hh:523
void unlock()
Release the lock.
Definition solver.hh:517
void lock()
Acquire the lock.
Definition solver.hh:511
The event handler interface.
Definition solver.hh:384
void on_finish(SolveResult result)
Callback to inform that the search has finished.
Definition solver.hh:421
void on_stats(Potassco::AbstractStatistics &stats)
Callback to update statistics.
Definition solver.hh:402
void on_unsat(Clasp::SumView bound)
Callback to intercept lower bounds.
Definition solver.hh:409
void on_core(Potassco::LitSpan core)
The unsatisfiable core of the current problem.
Definition solver.hh:414
auto on_model(Model &mdl) -> bool
Callback to intercept models.
Definition solver.hh:394
The model class.
Definition solver.hh:228
auto contains(Symbol sym) const -> bool
Check if the model contains a (symbolic) atom.
Definition solver.hh:249
auto context() -> SolveControl &
Get the context object to control the search.
Definition solver.hh:279
auto is_true(prg_lit_t lit) const -> bool
Check if a program literal is true in a model.
Definition solver.hh:254
auto is_consequence(prg_lit_t lit) const -> ConsequenceType
Check whether the given literal is a consequence.
Definition solver.hh:259
auto number() const -> uint64_t
Get the running number of the model.
Definition solver.hh:240
auto optimality_proven() const -> bool
Check if the model corresponds to an optimal solution.
Definition solver.hh:271
auto thread_id() const -> prg_id_t
Get the solver/thread id the model was found in.
Definition solver.hh:275
auto type() const -> ModelType
Get the type of the model.
Definition solver.hh:244
auto priorities() const -> std::span< prg_weight_t const >
get the priorities of the costs.
Definition solver.hh:267
virtual void extend(SymbolSpan symbols)
Extend the model with the given symbols.
Definition solver.hh:282
void symbols(SymbolSelectFlags type, SymbolVec &res) const
Get the selected symbols in the model.
Definition solver.hh:236
auto costs() const -> std::span< prg_sum_t const >
Get the costs associated with a model.
Definition solver.hh:263
The propagator interface.
Definition solver.hh:496
virtual auto hasHeuristic() const -> bool=0
Can return false to not also register the propagator as a heuristic.
Script providing code execution, main, and callbacks.
Definition solver.hh:20
void main(Solver &slv)
Run the main function.
Definition solver.hh:23
void exec(std::string_view code)
Execute the given code.
Definition solver.hh:25
Helper to run specific code and callbacks.
Definition solver.hh:38
void register_script(std::string_view name, UScript script)
Register the given script.
void main(Solver &slv)
Run the main function.
Simple control class to add clauses while enumerating models.
Definition solver.hh:218
void add_clause(PrgLitSpan lits)
Add a clause over the given literal.
Definition solver.hh:221
A handle to control a running search.
Definition solver.hh:316
auto last() -> Model const *
Get the last model after the search has finished.
Definition solver.hh:352
void resume()
Resume search after a model has been found to start search for the next one.
Definition solver.hh:336
auto wait(double timeout) -> bool
Wait for the given amount of time or until the next result is ready.
Definition solver.hh:369
auto get() -> SolveResult
Get the result of a search.
Definition solver.hh:326
auto model() -> Model const *
Get the current model or a nullptr if there is none.
Definition solver.hh:346
auto core() -> PrgLitSpan
Get a subset of the assumptions that made the problem unsatisfiable.
Definition solver.hh:359
virtual ~SolveHandle()=default
The default destructor.
void cancel()
Cancel the current search.
Definition solver.hh:330
A grounder and solver for logic programs.
Definition solver.hh:584
void parse(std::string_view str)
Parse a program from the given string.
auto solve(UEventHandler handler={}, PrgLitSpan assumptions={}, SolveMode mode=SolveMode::none) -> USolveHandle
Solve the program.
void output_program(std::ostream &out)
Output the current program.
void join(Input::UnprocessedProgram const &prg)
Join with the given program.
void parse_with(std::function< void(ProgramBackend *, TheoryBackend *)> cb)
Parse with optional backends.
void set_parts(Input::ProgramParamVec parts)
Set the program parts to ground.
Definition solver.hh:683
void main(std::span< std::string_view const > const &files)
Parse, ground, and solve a program.
auto clasp_facade() -> Clasp::ClaspFacade &
Get a pointer to the underlying clasp facade.
Definition solver.hh:641
void interrupt() noexcept
Interrupt the running (or next search).
void parse(std::span< std::string_view const > const &files)
Parse the given files.
auto backend() -> UBackendHandle
Get a handle that provides access to the backend to add atoms and rules.
void block_main(bool block)
Block execution of the main function in scripts.
Definition solver.hh:666
auto clasp_config() -> Clasp::Cli::ClaspCliConfig &
Only non-null in solving mode.
Definition solver.hh:647
void ground(ProgramParamVec const &params, Ground::ScriptCallback *ctx)
Ground the program.
auto buf() -> Util::OutputBuffer &
Get the output buffer.
Definition solver.hh:632
void main()
Ground and solve a program.
auto const_map() -> Input::ConstMap const &
Get the const map.
auto clasp_stats() -> Potassco::AbstractStatistics const &
Get the statistics.
Definition solver.hh:652
auto get_lock() -> CallbackLock &
Get the solvers callback lock.
Definition solver.hh:663
void add_const(String name, Symbol value)
Define a constant.
auto sym_tab() -> SymbolTable &
Get the symbol table.
Definition solver.hh:693
Solver(Clasp::ClaspFacade &clasp, Clasp::Cli::ClaspCliConfig &config, Logger &log, SymbolStore &store, Scripts &scripts, Input::RewriteOptions ropts, SolverOptions sopts, FILE *out=stdout)
Create a solver object.
auto clasp_facade() const -> Clasp::ClaspFacade const &
Get a pointer to the underlying clasp facade.
Definition solver.hh:644
void set_parts(std::optional< Input::StmParts > parts)
Set the program parts to ground.
Definition solver.hh:681
void register_propagator(UPropagator propagator)
Register the given propagator with the control object.
auto map_model(Clasp::Model const &mdl) -> Model &
Map the given clasp model to the clingo one.
void show(Input::SharedSig const &sig)
Show the given signature.
Definition solver.hh:690
void output_unprocessed_program(std::ostream &out)
Output the current unprocessed program.
auto user_data() -> void *&
Get user data for C integration.
Definition solver.hh:672
auto get_mode() const -> AppMode
Get the application mode.
Definition solver.hh:669
Helper to output symbols.
Definition solver.hh:551
void init(CppClingo::Control::BaseView &view, std::ostream &out)
Initialize the table before output.
void end_step()
Output atoms in extended aspif format.
auto out() -> std::ostream &
Get the underlying output stream.
Definition solver.hh:560
void begin_step()
Output ids of shown terms in extended aspif format.
Map from symbols to show term ids.
Definition solver.hh:112
auto size() const -> size_t
Get the number of mapped symbols.
Definition solver.hh:179
auto add(Symbol sym, F &&fun) -> prg_id_t
Add a new symbol to the map.
Definition solver.hh:125
auto end() const -> Map::const_iterator
Get an iterator over the symbol id pairs in the map pointing to the end of the sequence.
Definition solver.hh:191
void add(Symbol sym, prg_id_t id)
Add a symbol with the given id.
Definition solver.hh:139
auto index(Symbol sym) const -> size_t
Get the index of the symbol.
Definition solver.hh:174
auto term_id(size_t i) const -> prg_id_t
Get the id at the given index.
Definition solver.hh:149
auto begin() const -> Map::const_iterator
Get an iterator over the symbol id pairs in the map pointing to the beginning of the sequence.
Definition solver.hh:185
Util::ordered_map< SharedSymbol, prg_id_t > Map
The container storing the mapping (internal).
Definition solver.hh:115
auto symbol(size_t i) const -> Symbol
Get the symbol at the given index.
Definition solver.hh:160
RAII helper to unlock a mutex.
Definition solver.hh:537
unlock_guard(const unlock_guard &)=delete
Destructor re-locking the mutex.
unlock_guard(M &mut)
Constructor unlocking the mutex.
Definition solver.hh:540
Interface to call functions during parsing/grounding.
Definition script.hh:28
Interface to execute code in source files.
Definition script.hh:12
Program grouping unprocessed statements.
Definition program.hh:52
The Location of an expression in an input source.
Definition location.hh:44
Simple logger to report message to stderr or via a callback.
Definition logger.hh:63
Class similar to Potassco::TheoryData but with automatic id generation.
Definition backend.hh:17
A point in an input source.
Definition location.hh:15
Abstract class connecting grounder and solver.
Definition backend.hh:54
Reference to a string stored in a symbol store.
Definition symbol.hh:18
A store for symbols.
Definition symbol.hh:454
Variant-like class to store symbols stored in a symbol store.
Definition symbol.hh:225
Abstract class connecting grounder and theory data.
Definition backend.hh:213
Create an output buffer that bears some similarities with C++'s iostreams.
Definition print.hh:24
std::unique_ptr< EventHandler > UEventHandler
A unique pointer for an event handler.
Definition solver.hh:431
std::unique_ptr< Propagator > UPropagator
A unique pointer to a propagator.
Definition solver.hh:502
std::unique_ptr< SolveHandle > USolveHandle
A unique pointer for a solve handle.
Definition solver.hh:381
ModelType
Enumeration of available model flags.
Definition solver.hh:98
IStop
Stop condition for incremental mode.
Definition solver.hh:54
SolveMode
The available solve modes.
Definition solver.hh:436
BuiltinIncludes
Bitset of enabled builtin includes.
Definition parse.hh:23
SymbolSelectFlags
A bit set of symbol selection flags.
Definition solver.hh:86
AppMode
Enumeration of available application modes.
Definition solver.hh:62
std::unique_ptr< SymbolTable > USymbolTable
A unique pointer to a symbol table.
Definition solver.hh:579
SolveResult
The solve result.
Definition solver.hh:305
std::unique_ptr< Model > UModel
A unique pointer to a model.
Definition solver.hh:299
ConsequenceType
Enumeration of available consequence types.
Definition solver.hh:105
std::unique_ptr< BackendHandle > UBackendHandle
A unique pointer to a backend handle.
Definition solver.hh:493
std::unique_ptr< Script > UScript
A unique pointer to a script.
Definition solver.hh:32
@ cautious_consequences
The model represents a set of cautious consequences.
@ model
The model represents a stable model.
@ brave_consequences
The model represents a set of brave consequences.
@ none
Do not consider solve result.
@ sat
Stop when satisfiable.
@ unsat
Stop when unsat.
@ unknown
Stop when interrupted.
@ async
Solve asynchronously in background threads.
@ yield
Yield models while solving via SolveHandle::model().
@ shown
Select shown atoms and terms.
@ theory
Select symbols added by theory.
@ parse
Stop processing after parsing.
@ ground
Stop processing after grounding.
@ rewrite
Stop processing after rewriting.
@ solve
Stop processing after solving.
@ satisfiable
The search produced at least one model.
@ unsatisfiable
The search finished and no model was produced.
@ exhausted
The search has been exhausted.
@ interrupted
The search has been interrupted.
@ true_
The literal is a consequence.
@ false_
The literal is not a consequence.
int32_t prg_lit_t
A program literal.
Definition backend.hh:27
std::unique_ptr< OutputStm > UOutputStm
Unique pointer for statement output.
Definition output.hh:253
std::span< prg_lit_t const > PrgLitSpan
A span of program literals.
Definition backend.hh:37
int32_t prg_weight_t
A weight used in weight and minimize constraints.
Definition backend.hh:33
int64_t prg_sum_t
Type to represent sums of weights.
Definition backend.hh:35
uint32_t prg_id_t
An id to refer to elements of a logic program.
Definition backend.hh:16
std::unique_ptr< ProgramBackend > UProgramBackend
A unique pointer for a program backend.
Definition backend.hh:210
std::span< Symbol const > SymbolSpan
A span of symbols.
Definition symbol.hh:218
std::vector< Symbol > SymbolVec
A vector of symbols.
Definition symbol.hh:220
Util::ordered_map< SharedString, std::pair< StmConst, SharedSymbol > > ConstMap
Map from identifiers to constants.
Definition program.hh:34
std::vector< ProgramParam > ProgramParamVec
A list of program params.
Definition statement.hh:761
std::tuple< SharedString, size_t, bool > SharedSig
The signature of a predicate.
Definition term.hh:40
tsl::ordered_map< Key, T, Hash, KeyEqual, Allocator, ValueTypeContainer, IndexType > ordered_map
Alias for ordered maps.
Definition ordered_map.hh:16
tsl::hopscotch_map< Key, T, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy > unordered_map
Alias for unordered maps.
Definition unordered_map.hh:17
#define CLINGO_ENABLE_BITSET_ENUM(E,...)
Opt-in macro for enabling bit operations for a given enum type.
Definition enum.hh:18
Options for the solver.
Definition solver.hh:70
size_t imin
The minimum number of incremental steps.
Definition solver.hh:74
bool single_shot
Restrict to single shot-solving.
Definition solver.hh:80
AppMode mode
Operation mode of the solver.
Definition solver.hh:72
bool profile
Enable profiling.
Definition solver.hh:82
std::optional< size_t > imax
The maximum number of incremental steps.
Definition solver.hh:76
IStop istop
The stop condition for the incremental mode.
Definition solver.hh:78
Options to configure rewriting.
Definition program.hh:26