Clingo
Loading...
Searching...
No Matches
solver.hh
1#pragma once
2
3#include <clingo/control/config.hh>
4#include <clingo/control/grounder.hh>
5
6#include <clingo/output/backend.hh>
7
8#include <clasp/clasp_facade.h>
9#include <clasp/cli/clasp_options.h>
10
11namespace CppClingo::Control {
12
15
16class Solver;
17
22 public:
24 void main(Solver &slv) { do_main(slv); }
26 void exec(std::string_view code) { do_exec(code); }
27
28 private:
29 virtual void do_exec(std::string_view code) = 0;
30 virtual void do_main(Solver &slv) = 0;
31};
33using UScript = std::unique_ptr<Script>;
34
40 public:
42 void register_script(std::string_view name, UScript script);
44 void main(Solver &slv);
45
46 private:
47 void do_exec(Location const &loc, Logger &log, std::string_view name, std::string_view code) override;
48 auto do_callable(std::string_view name, size_t args) -> bool override;
49 void do_call(Location const &loc, std::string_view name, SymbolSpan args, SymbolVec &out) override;
50
51 std::vector<std::pair<std::string, UScript>> scripts_;
52};
53
55enum class IStop : uint8_t {
56 none,
57 sat,
58 unsat,
59 unknown
60};
61
63enum class AppMode : uint8_t {
64 parse,
65 rewrite,
66 ground,
67 solve
68};
69
75 size_t imin = 0;
77 std::optional<size_t> imax = std::nullopt;
81 bool single_shot = false;
82};
83
85enum class SymbolSelectFlags : uint8_t {
86 none = 0,
87 shown = 1,
88 atoms = 2,
89 terms = 4,
90 theory = 8,
91 all = 15,
92};
95
97enum class ModelType : uint8_t {
98 model = 0,
101};
102
104enum class ConsequenceType : uint8_t {
105 false_ = 0,
106 true_ = 1,
107 unknown = 2
108};
109
112 public:
115
124 template <class F> auto add(Symbol sym, F &&fun) -> prg_id_t {
125 auto [it, ins] = map_.emplace(sym, 0);
126 if (ins) {
127 it.value() = std::invoke(std::forward<F>(fun));
128 }
129 return it.value();
130 }
131
138 void add(Symbol sym, prg_id_t id) {
139 if (!map_.emplace(sym, id).second) {
140 throw std::runtime_error("collision of term ids");
141 }
142 }
143
148 [[nodiscard]] auto term_id(size_t i) const -> prg_id_t {
149 if (i < size()) {
150 return map_.nth(i).value();
151 }
152 throw std::range_error{"index out of range"};
153 }
154
159 [[nodiscard]] auto symbol(size_t i) const -> Symbol {
160 if (i < size()) {
161 return *map_.nth(i).key();
162 }
163 throw std::range_error{"index out of range"};
164 }
165
173 [[nodiscard]] auto index(Symbol sym) const -> size_t { return map_.find(sym) - map_.begin(); }
174
178 [[nodiscard]] auto size() const -> size_t { return map_.size(); }
179
184 [[nodiscard]] auto begin() const -> Map::const_iterator { return map_.cbegin(); }
185
190 [[nodiscard]] auto end() const -> Map::const_iterator { return map_.cend(); }
191
192 private:
194};
195
197class BaseView {
198 public:
200 virtual ~BaseView() = default;
202 [[nodiscard]] auto bases() const -> Ground::Bases const & { return do_bases(); }
204 [[nodiscard]] auto term_base() const -> TermBaseMap const & { return do_term_base(); }
206 [[nodiscard]] auto clasp_program() const -> Clasp::Asp::LogicProgram const & { return do_clasp_program(); }
208 [[nodiscard]] auto clasp_theory() const -> Potassco::TheoryData const & { return clasp_program().theoryData(); }
209
210 private:
211 [[nodiscard]] virtual auto do_bases() const -> Ground::Bases const & = 0;
212 [[nodiscard]] virtual auto do_term_base() const -> TermBaseMap const & = 0;
213 [[nodiscard]] virtual auto do_clasp_program() const -> Clasp::Asp::LogicProgram const & = 0;
214};
215
217class SolveControl : public BaseView {
218 public:
220 void add_clause(PrgLitSpan lits) { do_add_clause(lits); }
221
222 private:
223 virtual void do_add_clause(PrgLitSpan lits) = 0;
224};
225
227class Model {
228 public:
229 virtual ~Model() = default;
230
235 void symbols(SymbolSelectFlags type, SymbolVec &res) const { do_symbols(type, res); }
239 [[nodiscard]] auto number() const -> uint64_t { return do_number(); }
243 [[nodiscard]] auto type() const -> ModelType { return do_type(); }
248 [[nodiscard]] auto contains(Symbol sym) const -> bool { return do_contains(sym); }
253 [[nodiscard]] auto is_true(prg_lit_t lit) const -> bool { return do_is_true(lit); }
258 [[nodiscard]] auto is_consequence(prg_lit_t lit) const -> ConsequenceType { return do_is_consequence(lit); }
262 [[nodiscard]] auto costs() const -> std::span<prg_sum_t const> { return do_costs(); }
266 [[nodiscard]] auto priorities() const -> std::span<prg_weight_t const> { return do_priorities(); }
270 [[nodiscard]] auto optimality_proven() const -> bool { return do_optimality_proven(); }
274 [[nodiscard]] auto thread_id() const -> prg_id_t { return do_thread_id(); }
278 [[nodiscard]] auto context() -> SolveControl & { return do_control(); }
279
281 virtual void extend(SymbolSpan symbols) { do_extend(symbols); }
282
283 private:
284 virtual void do_symbols(SymbolSelectFlags type, SymbolVec &res) const = 0;
285 [[nodiscard]] virtual auto do_number() const -> uint64_t = 0;
286 [[nodiscard]] virtual auto do_type() const -> ModelType = 0;
287 [[nodiscard]] virtual auto do_contains(Symbol sym) const -> bool = 0;
288 virtual void do_extend(SymbolSpan symbols) = 0;
289 [[nodiscard]] virtual auto do_is_true(prg_lit_t lit) const -> bool = 0;
290 [[nodiscard]] virtual auto do_is_consequence(prg_lit_t lit) const -> ConsequenceType = 0;
291 [[nodiscard]] virtual auto do_costs() const -> std::span<prg_sum_t const> = 0;
292 [[nodiscard]] virtual auto do_priorities() const -> std::span<prg_weight_t const> = 0;
293 [[nodiscard]] virtual auto do_optimality_proven() const -> bool = 0;
294 [[nodiscard]] virtual auto do_thread_id() const -> prg_id_t = 0;
295 [[nodiscard]] virtual auto do_control() -> SolveControl & = 0;
296};
298using UModel = std::unique_ptr<Model>;
299
304enum class SolveResult : uint8_t {
305 empty = 0,
306 satisfiable = 1,
307 unsatisfiable = 2,
308 exhausted = 4,
309 interrupted = 8,
310};
313
316 public:
318 virtual ~SolveHandle() = default;
319
325 auto get() -> SolveResult { return do_get(); }
329 void cancel() { do_cancel(); }
335 void resume() { do_resume(); }
345 auto model() -> Model const * { return do_model(); }
351 auto last() -> Model const * { return do_last(); }
358 auto core() -> PrgLitSpan { return do_core(); }
368 auto wait(double timeout) -> bool { return do_wait(timeout); }
369
370 private:
371 virtual auto do_get() -> SolveResult = 0;
372 virtual void do_cancel() = 0;
373 virtual void do_resume() = 0;
374 virtual auto do_model() -> Model const * = 0;
375 virtual auto do_last() -> Model const * = 0;
376 virtual auto do_core() -> PrgLitSpan = 0;
377 virtual auto do_wait(double timeout) -> bool = 0;
378};
380using USolveHandle = std::unique_ptr<SolveHandle>;
381
384 public:
385 virtual ~EventHandler() = default;
386
393 auto on_model(Model &mdl) -> bool { return do_on_model(mdl); }
401 void on_stats(Potassco::AbstractStatistics &stats) { do_on_stats(stats); }
408 void on_unsat(Clasp::SumView bound) { do_on_unsat(bound); }
413 void on_core(Potassco::LitSpan core) { do_on_core(core); }
420 void on_finish(SolveResult result) { do_on_finish(result); }
421
422 private:
423 virtual auto do_on_model([[maybe_unused]] Model &mdl) -> bool { return true; }
424 virtual void do_on_stats([[maybe_unused]] Potassco::AbstractStatistics &stats) {}
425 virtual void do_on_unsat([[maybe_unused]] Clasp::SumView bound) {}
426 virtual void do_on_core([[maybe_unused]] Potassco::LitSpan core) {}
427 virtual void do_on_finish([[maybe_unused]] SolveResult result) {}
428};
430using UEventHandler = std::unique_ptr<EventHandler>;
431
435enum class SolveMode : uint8_t {
436 none = 0,
437 async = 1,
438 yield = 2,
439};
442
456 public:
460 [[nodiscard]] auto program() -> Clasp::Asp::LogicProgram & { return do_program(); }
464 [[nodiscard]] auto theory() -> Output::TheoryData & { return do_theory(); }
468 [[nodiscard]] auto store() -> SymbolStore & { return do_store(); }
475 [[nodiscard]] auto add_atom(Symbol atom) -> prg_lit_t { return do_add_atom(atom); }
480 void close() { do_close(); }
482 virtual ~BackendHandle() = default;
483
484 private:
485 virtual auto do_program() -> Clasp::Asp::LogicProgram & = 0;
486 virtual auto do_theory() -> Output::TheoryData & = 0;
487 virtual auto do_store() -> SymbolStore & = 0;
488 virtual auto do_add_atom(Symbol atom) -> prg_lit_t = 0;
489 virtual void do_close() = 0;
490};
492using UBackendHandle = std::unique_ptr<BackendHandle>;
493
495class Propagator : public Potassco::AbstractPropagator, public Potassco::AbstractHeuristic {
496 public:
498 [[nodiscard]] virtual auto hasHeuristic() const -> bool = 0;
499};
501using UPropagator = std::unique_ptr<Propagator>;
502
508 public:
510 void lock() {
511 if (mut_) {
512 mut_->lock();
513 }
514 }
516 void unlock() {
517 if (mut_) {
518 mut_->unlock();
519 }
520 }
522 void enable(bool state) {
523 if (!state) {
524 mut_.reset();
525 } else if (!mut_) {
526 mut_.emplace();
527 mut_->lock();
528 }
529 }
530
531 private:
532 std::optional<std::mutex> mut_;
533};
534
536template <class M> class unlock_guard {
537 public:
539 explicit unlock_guard(M &mut) : mut_{&mut} { mut_->unlock(); }
541 unlock_guard(const unlock_guard &) = delete;
542 ~unlock_guard() { mut_->lock(); }
543 auto operator=(const unlock_guard &) -> unlock_guard & = delete;
544
545 private:
546 M *mut_;
547};
548
551 public:
553 void init(CppClingo::Control::BaseView &view, std::ostream &out);
557 void end_step();
559 auto out() -> std::ostream & { return *out_; }
560
561 private:
562 struct State {
563 State() = default;
564 size_t atom : 1 = 0;
565 size_t term : 1 = 0;
566 size_t index : (8 * sizeof(size_t)) - 2 = 0;
567 };
568
569 auto output(CppClingo::Symbol const &sym) -> State &;
570
571 CppClingo::Control::BaseView *view_ = nullptr;
572 std::ostream *out_ = nullptr;
573 size_t ids_ = 0;
574 std::vector<size_t> buf_;
576};
578using USymbolTable = std::unique_ptr<SymbolTable>;
579
581// TODO: Simplify/Move on next output refactoring
582class Grounded : public Clasp::Event {
583 public:
585 explicit Grounded(Input::ProgramParamVec const &params)
586 : Event(this, subsystem_load, verbosity_quiet), params(params) {}
588 std::span<Input::ProgramParamVec::value_type const> params;
589};
590
594class Solver : public BaseView {
595 public:
597 Solver(Clasp::ClaspFacade &clasp, Clasp::Cli::ClaspCliConfig &config, Logger &log, SymbolStore &store,
598 Scripts &scripts, Input::RewriteOptions ropts, SolverOptions sopts, FILE *out = stdout);
599
601 void main(std::span<std::string_view const> const &files);
603 void main();
604
608 void parse(std::string_view str);
610 void parse(std::span<std::string_view const> const &files);
612 void parse_with(std::function<void(ProgramBackend *, TheoryBackend *)> cb);
613
615 void add_const(String name, Symbol value);
617 [[nodiscard]] auto const_map() -> Input::ConstMap const &;
619 void ground(ProgramParamVec const &params, Ground::ScriptCallback *ctx);
626 auto solve(UEventHandler handler = {}, PrgLitSpan assumptions = {}, SolveMode mode = SolveMode::none)
627 -> USolveHandle;
628
630 void output_unprocessed_program(std::ostream &out);
631
633 void output_program(std::ostream &out);
634
636 auto map_model(Clasp::Model const &mdl) -> Model &;
637
642 [[nodiscard]] auto buf() -> Util::OutputBuffer & { return buf_; };
643
648 [[nodiscard]] auto backend() -> UBackendHandle;
649
651 [[nodiscard]] auto clasp_facade() -> Clasp::ClaspFacade & { return *clasp_; }
652
654 [[nodiscard]] auto clasp_facade() const -> Clasp::ClaspFacade const & { return *clasp_; }
655
657 [[nodiscard]] auto config() -> ClingoConfig & { return config_; }
658
660 [[nodiscard]] auto clasp_stats() -> Potassco::AbstractStatistics const & {
661 auto const *stats = clasp_->getStats();
662 return stats != nullptr ? *stats : throw std::runtime_error("not in solving mode");
663 }
664
669
671 auto get_lock() -> CallbackLock & { return lock_; }
672
674 void block_main(bool block) { block_main_ = block; }
675
677 [[nodiscard]] auto get_mode() const -> AppMode { return opts_.mode; }
678
680 auto user_data() -> void *& { return data_; }
681
683 void interrupt() noexcept;
684
686 [[nodiscard]] auto get_parts() -> std::optional<Input::StmParts> const & { return grd_.get_parts(); }
687
689 void set_parts(std::optional<Input::StmParts> parts) { grd_.set_parts(std::move(parts)); }
692 auto pos = Position{*grd_.store().string("<cmd>"), 1, 1};
693 auto loc = Location{pos, pos};
694 grd_.set_parts(std::make_optional<Input::StmParts>(loc, Input::Precedence::override_, std::move(parts)));
695 }
696
698 void show(Input::SharedSig const &sig) { grd_.show(sig); }
699
701 auto sym_tab() -> SymbolTable & {
702 if (!sym_tab_) {
703 sym_tab_ = std::make_unique<SymbolTable>();
704 }
705 return *sym_tab_;
706 }
707
711 auto print_summary(bool final) { grd_.print_summary(final); }
712
714 void accept(Ground::ProfileNode::Visitor const &visit) const { grd_.accept(visit); }
715
716 private:
717 class ProgramBackendAdapter;
718
726 enum class State : uint8_t {
727 initial, //< initial step
728 grounded, //< step has been grounded
729 prepared, //< step is prepared for solving
730 solved, //< step has been solved
731 };
732
740 auto make_output_(SymbolStore &store, AppMode mode) -> UOutputStm;
741
743 void prepare_();
744
746 void simplify_();
747
749 void enable_updates_();
750
751 [[nodiscard]] auto do_bases() const -> Ground::Bases const & override { return grd_.base(); }
752
753 [[nodiscard]] auto do_term_base() const -> TermBaseMap const & override { return terms_; }
754
755 [[nodiscard]] auto do_clasp_program() const -> Clasp::Asp::LogicProgram const & override {
756 return clasp_->asp() != nullptr ? *clasp_->asp() : throw std::runtime_error("not in solving mode");
757 }
758
759 void incmode_();
760
761 CallbackLock lock_;
762 std::vector<UPropagator> propagators_;
763 TermBaseMap terms_;
764 Clasp::ClaspFacade *clasp_;
765 ClingoConfig config_;
766 Util::OutputBuffer buf_;
767 UProgramBackend backend_;
768 std::unique_ptr<Output::TheoryData> theory_;
769 UOutputStm out_;
770 UModel mdl_;
771 USymbolTable sym_tab_;
772 Grounder grd_;
773 Scripts *scripts_;
774 State state_ = State::initial;
775 SolverOptions opts_;
776 BuiltinIncludes includes_ = BuiltinIncludes::empty;
777 void *data_ = nullptr;
778 bool block_main_ = false;
779};
780
782
783} // namespace CppClingo::Control
Object to provide access to the backend.
Definition solver.hh:455
auto store() -> SymbolStore &
The symbol store.
Definition solver.hh:468
auto theory() -> Output::TheoryData &
Get the theory.
Definition solver.hh:464
void close()
Close the handle.
Definition solver.hh:480
auto program() -> Clasp::Asp::LogicProgram &
Get the logic program.
Definition solver.hh:460
virtual ~BackendHandle()=default
Destroy the handle.
auto add_atom(Symbol atom) -> prg_lit_t
Add a literal for the given symbol.
Definition solver.hh:475
Interface providing the necessary data to inspect atom, term, and theory bases.
Definition solver.hh:197
auto clasp_theory() const -> Potassco::TheoryData const &
Get a reference to the underlying facade.
Definition solver.hh:208
virtual ~BaseView()=default
The default destructor.
auto bases() const -> Ground::Bases const &
Get a reference to the underlying atom bases.
Definition solver.hh:202
auto term_base() const -> TermBaseMap const &
Get a reference to the underlying term bases.
Definition solver.hh:204
auto clasp_program() const -> Clasp::Asp::LogicProgram const &
Get a reference to the underlying facade.
Definition solver.hh:206
This lock ensures that callbacks during solving are called in lock-step.
Definition solver.hh:507
void enable(bool state)
Enable or disable the lock.
Definition solver.hh:522
void unlock()
Release the lock.
Definition solver.hh:516
void lock()
Acquire the lock.
Definition solver.hh:510
This class provides a hierarchical configuration interface for clingo.
Definition config.hh:24
The event handler interface.
Definition solver.hh:383
void on_finish(SolveResult result)
Callback to inform that the search has finished.
Definition solver.hh:420
void on_stats(Potassco::AbstractStatistics &stats)
Callback to update statistics.
Definition solver.hh:401
void on_unsat(Clasp::SumView bound)
Callback to intercept lower bounds.
Definition solver.hh:408
void on_core(Potassco::LitSpan core)
The unsatisfiable core of the current problem.
Definition solver.hh:413
auto on_model(Model &mdl) -> bool
Callback to intercept models.
Definition solver.hh:393
Event emitted by a solver after the program is grounded.
Definition solver.hh:582
std::span< Input::ProgramParamVec::value_type const > params
The program parts that have been grounded.
Definition solver.hh:588
Grounded(Input::ProgramParamVec const &params)
Construct a grounded event.
Definition solver.hh:585
The model class.
Definition solver.hh:227
auto contains(Symbol sym) const -> bool
Check if the model contains a (symbolic) atom.
Definition solver.hh:248
auto context() -> SolveControl &
Get the context object to control the search.
Definition solver.hh:278
auto is_true(prg_lit_t lit) const -> bool
Check if a program literal is true in a model.
Definition solver.hh:253
auto is_consequence(prg_lit_t lit) const -> ConsequenceType
Check whether the given literal is a consequence.
Definition solver.hh:258
auto number() const -> uint64_t
Get the running number of the model.
Definition solver.hh:239
auto optimality_proven() const -> bool
Check if the model corresponds to an optimal solution.
Definition solver.hh:270
auto thread_id() const -> prg_id_t
Get the solver/thread id the model was found in.
Definition solver.hh:274
auto type() const -> ModelType
Get the type of the model.
Definition solver.hh:243
auto priorities() const -> std::span< prg_weight_t const >
get the priorities of the costs.
Definition solver.hh:266
virtual void extend(SymbolSpan symbols)
Extend the model with the given symbols.
Definition solver.hh:281
void symbols(SymbolSelectFlags type, SymbolVec &res) const
Get the selected symbols in the model.
Definition solver.hh:235
auto costs() const -> std::span< prg_sum_t const >
Get the costs associated with a model.
Definition solver.hh:262
The propagator interface.
Definition solver.hh:495
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:21
void main(Solver &slv)
Run the main function.
Definition solver.hh:24
void exec(std::string_view code)
Execute the given code.
Definition solver.hh:26
Helper to run specific code and callbacks.
Definition solver.hh:39
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:217
void add_clause(PrgLitSpan lits)
Add a clause over the given literal.
Definition solver.hh:220
A handle to control a running search.
Definition solver.hh:315
auto last() -> Model const *
Get the last model after the search has finished.
Definition solver.hh:351
void resume()
Resume search after a model has been found to start search for the next one.
Definition solver.hh:335
auto wait(double timeout) -> bool
Wait for the given amount of time or until the next result is ready.
Definition solver.hh:368
auto get() -> SolveResult
Get the result of a search.
Definition solver.hh:325
auto model() -> Model const *
Get the current model or a nullptr if there is none.
Definition solver.hh:345
auto core() -> PrgLitSpan
Get a subset of the assumptions that made the problem unsatisfiable.
Definition solver.hh:358
virtual ~SolveHandle()=default
The default destructor.
void cancel()
Cancel the current search.
Definition solver.hh:329
A grounder and solver for logic programs.
Definition solver.hh:594
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:691
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:651
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:674
void ground(ProgramParamVec const &params, Ground::ScriptCallback *ctx)
Ground the program.
auto buf() -> Util::OutputBuffer &
Get the output buffer.
Definition solver.hh:642
void main()
Ground and solve a program.
auto const_map() -> Input::ConstMap const &
Get the const map.
auto print_summary(bool final)
Print per step summaries.
Definition solver.hh:711
auto clasp_stats() -> Potassco::AbstractStatistics const &
Get the statistics.
Definition solver.hh:660
auto get_lock() -> CallbackLock &
Get the solvers callback lock.
Definition solver.hh:671
void accept(Ground::ProfileNode::Visitor const &visit) const
Accept a visitor for the profile nodes.
Definition solver.hh:714
void add_const(String name, Symbol value)
Define a constant.
auto sym_tab() -> SymbolTable &
Get the symbol table.
Definition solver.hh:701
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:654
void set_parts(std::optional< Input::StmParts > parts)
Set the program parts to ground.
Definition solver.hh:689
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.
auto config() -> ClingoConfig &
Only non-null in solving mode.
Definition solver.hh:657
void show(Input::SharedSig const &sig)
Show the given signature.
Definition solver.hh:698
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:680
auto get_mode() const -> AppMode
Get the application mode.
Definition solver.hh:677
Helper to output symbols.
Definition solver.hh:550
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:559
void begin_step()
Output ids of shown terms in extended aspif format.
Map from symbols to show term ids.
Definition solver.hh:111
auto size() const -> size_t
Get the number of mapped symbols.
Definition solver.hh:178
auto add(Symbol sym, F &&fun) -> prg_id_t
Add a new symbol to the map.
Definition solver.hh:124
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:190
void add(Symbol sym, prg_id_t id)
Add a symbol with the given id.
Definition solver.hh:138
auto index(Symbol sym) const -> size_t
Get the index of the symbol.
Definition solver.hh:173
auto term_id(size_t i) const -> prg_id_t
Get the id at the given index.
Definition solver.hh:148
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:184
Util::ordered_map< SharedSymbol, prg_id_t > Map
The container storing the mapping (internal).
Definition solver.hh:114
auto symbol(size_t i) const -> Symbol
Get the symbol at the given index.
Definition solver.hh:159
RAII helper to unlock a mutex.
Definition solver.hh:536
unlock_guard(const unlock_guard &)=delete
Destructor re-locking the mutex.
unlock_guard(M &mut)
Constructor unlocking the mutex.
Definition solver.hh:539
std::function< void(std::variant< std::pair< std::string_view, bool >, std::pair< ProfileStats const *, ProfileType > >, size_t)> Visitor
The type of visitor function to use for visiting profile nodes.
Definition profile.hh:106
Interface to call functions during parsing/grounding.
Definition script.hh:28
void call(Location const &loc, std::string_view name, SymbolSpan args, SymbolVec &out)
Call the function with the given name and arguments.
Definition script.hh:35
Interface to execute code in source files.
Definition script.hh:12
Program grouping unprocessed statements.
Definition program.hh:70
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:430
std::unique_ptr< Propagator > UPropagator
A unique pointer to a propagator.
Definition solver.hh:501
std::unique_ptr< SolveHandle > USolveHandle
A unique pointer for a solve handle.
Definition solver.hh:380
ModelType
Enumeration of available model flags.
Definition solver.hh:97
IStop
Stop condition for incremental mode.
Definition solver.hh:55
SolveMode
The available solve modes.
Definition solver.hh:435
BuiltinIncludes
Bitset of enabled builtin includes.
Definition parse.hh:23
SymbolSelectFlags
A bit set of symbol selection flags.
Definition solver.hh:85
AppMode
Enumeration of available application modes.
Definition solver.hh:63
std::unique_ptr< SymbolTable > USymbolTable
A unique pointer to a symbol table.
Definition solver.hh:578
SolveResult
The solve result.
Definition solver.hh:304
std::unique_ptr< Model > UModel
A unique pointer to a model.
Definition solver.hh:298
ConsequenceType
Enumeration of available consequence types.
Definition solver.hh:104
std::unique_ptr< BackendHandle > UBackendHandle
A unique pointer to a backend handle.
Definition solver.hh:492
std::unique_ptr< Script > UScript
A unique pointer to a script.
Definition solver.hh:33
@ 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:48
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:42
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:71
size_t imin
The minimum number of incremental steps.
Definition solver.hh:75
bool single_shot
Restrict to single shot-solving.
Definition solver.hh:81
AppMode mode
Operation mode of the solver.
Definition solver.hh:73
std::optional< size_t > imax
The maximum number of incremental steps.
Definition solver.hh:77
IStop istop
The stop condition for the incremental mode.
Definition solver.hh:79
Options to configure rewriting.
Definition program.hh:38