3#include <clingo/base.hh>
4#include <clingo/core.hh>
6#include <clingo/propagate.h>
63 using pointer = Detail::ArrowProxy<value_type>;
65 using iterator = Detail::RandomAccessIterator<Trail>;
80 return Detail::call<clingo_assignment_trail_at>(assignment_, index);
106 return iterator{*
this, Detail::call<clingo_assignment_trail_begin>(assignment_,
level)};
114 return iterator{*
this, Detail::call<clingo_assignment_trail_end>(assignment_,
level)};
151 using pointer = Detail::ArrowProxy<value_type>;
153 using iterator = Detail::RandomAccessIterator<Assignment>;
171 return Detail::call<clingo_assignment_at>(assignment_,
size);
182 return Detail::call<clingo_assignment_decision>(assignment_,
level);
189 return Detail::call<clingo_assignment_decision_level>(assignment_);
196 return Detail::call<clingo_assignment_has_conflict>(assignment_);
203 return Detail::call<clingo_assignment_has_literal>(assignment_, lit);
211 return Detail::call<clingo_assignment_is_false>(assignment_, lit);
219 return Detail::call<clingo_assignment_is_fixed>(assignment_, lit);
235 return Detail::call<clingo_assignment_is_true>(assignment_, lit);
250 return Detail::call<clingo_assignment_level>(assignment_, lit);
282 return Detail::call<clingo_assignment_root_level>(assignment_);
329 return Assignment{Detail::call<clingo_propagate_init_assignment>(init_)};
336 return Library{Detail::call<clingo_propagate_init_library>(init_),
true};
348 return static_cast<PropagatorCheckMode>(Detail::call<clingo_propagate_init_get_check_mode>(init_));
355 Detail::handle_error(
363 return Detail::call<clingo_propagate_init_number_of_threads>(init_);
370 return static_cast<PropagatorUndoMode>(Detail::call<clingo_propagate_init_get_undo_mode>(init_));
377 Detail::handle_error(
390 return Detail::call<clingo_propagate_init_add_clause>(init_,
literals.data(),
literals.size());
413 return Detail::call<clingo_propagate_init_add_literal>(init_,
freeze);
453 return Detail::call<clingo_propagate_init_add_weight_constraint>(init_, literal,
literals.data(),
493 return Detail::call<clingo_propagate_init_solver_literal>(init_, literal);
518 return Detail::call<clingo_propagate_control_add_literal>(ctl_);
531 return Detail::call<clingo_propagate_control_add_clause>(ctl_,
literals.data(),
literals.size(),
571 return Detail::call<clingo_propagate_control_has_watch>(ctl_, literal);
594 return Assignment{Detail::call<clingo_propagate_control_assignment>(ctl_)};
645 do_undo(thread_id, assignment,
changes);
683 return do_decide(thread_id, assignment, literal);
699 auto &self = *
static_cast<Propagator *
>(data);
701 self.init(PropagateInit{
init});
706 auto &self = *
static_cast<Propagator *
>(data);
713 auto &self = *
static_cast<Propagator *
>(data);
715 uint32_t thread_id = Detail::call<clingo_propagate_control_thread_id>(control);
716 clingo_assignment_t const *assignment = Detail::call<clingo_propagate_control_assignment>(control);
718 }
catch (std::exception
const &
e) {
719 printf(
"panic: %s\n",
e.what());
724 auto &self = *
static_cast<Propagator *
>(data);
726 self.check(PropagateControl{control});
731 [](
void *data) { std::ignore = std::unique_ptr<Propagator>(
static_cast<Propagator *
>(data)); },
736 c_propagator.propagate,
741 auto &self = *
static_cast<Propagator *
>(data);
744 *decision =
static_cast<Heuristic &
>(self).decide(thread_id, Assignment{assignment},
fallback);
Represents a (partial) assignment of a particular solver.
Definition propagate.hh:140
value_type reference
The reference type, which simply refers to the value type.
Definition propagate.hh:149
auto has_conflict() const -> bool
Check if the assignment is conflicting.
Definition propagate.hh:195
SolverLiteral value_type
The value type, which is a solver literal.
Definition propagate.hh:143
auto contains(SolverLiteral lit) const -> bool
Check whether the assignment contains the given literal.
Definition propagate.hh:202
auto is_free(SolverLiteral lit) const -> bool
Check if the truth value of the given literal is free.
Definition propagate.hh:226
auto begin() const -> iterator
Get an iterator to the beginning of the assignment.
Definition propagate.hh:293
auto trail() const -> Trail
Get the trail of the assignment.
Definition propagate.hh:288
auto size() const -> size_type
Get the size of the assignment.
Definition propagate.hh:164
auto decision(ProgramId level) const -> SolverLiteral
Get the decision literal for the given decision level.
Definition propagate.hh:181
auto is_fixed(SolverLiteral lit) const -> bool
Check if the truth value of the given literal is fixed.
Definition propagate.hh:218
auto value(SolverLiteral lit) const -> std::optional< bool >
Get the truth value of the given literal.
Definition propagate.hh:260
auto is_total() const -> bool
Check whether the assignment is total.
Definition propagate.hh:243
Assignment(clingo_assignment_t const *assignment)
Construct an assignment from the underlying C representation.
Definition propagate.hh:156
auto at(size_type size) const -> value_type
Get the literal at the given index in the assignment.
Definition propagate.hh:170
Detail::RandomAccessIterator< Assignment > iterator
The iterator type, which is a random access iterator over the assignment.
Definition propagate.hh:153
auto level(SolverLiteral lit) const -> ProgramId
Get the level on which the given literal was assigned.
Definition propagate.hh:249
std::ptrdiff_t difference_type
The difference type.
Definition propagate.hh:147
auto end() const -> iterator
Get an iterator to the end of the assignment.
Definition propagate.hh:298
auto decision_level() const -> ProgramId
Get the current decision level.
Definition propagate.hh:188
auto root_level() const -> ProgramId
Get the root level of the assignment.
Definition propagate.hh:281
auto is_true(SolverLiteral lit) const -> bool
Check if the given literal is true.
Definition propagate.hh:234
auto is_false(SolverLiteral lit) const -> bool
Check if the given literal is false.
Definition propagate.hh:210
std::size_t size_type
The size type.
Definition propagate.hh:145
auto operator[](size_type size) const -> value_type
Get the literal at the given index in the assignment.
Definition propagate.hh:175
Detail::ArrowProxy< value_type > pointer
The pointer type, which is a proxy to the value type.
Definition propagate.hh:151
A base that maps signatures to atom bases, and captures term and theory bases.
Definition base.hh:608
Interface for user-defined propagators with a decision heuristic.
Definition propagate.hh:668
Heuristic()=default
The default constructor.
auto decide(ProgramId thread_id, Assignment assignment, SolverLiteral literal) -> SolverLiteral
Callback to decide on the next literal to assign.
Definition propagate.hh:682
The main library class for managing global information and logging.
Definition core.hh:471
Class to control propagation of a user-defined propagator.
Definition propagate.hh:504
auto add_clause(SolverLiteralSpan literals, ClauseFlags flags=ClauseFlags::none) const -> bool
Add a clause to the solver.
Definition propagate.hh:530
auto thread_id() const -> ProgramId
Get the thread id of the current solver.
Definition propagate.hh:600
auto add_clause(SolverLiteralList literals, ClauseFlags flags=ClauseFlags::none) const -> bool
Add a clause to the solver.
Definition propagate.hh:544
auto propagate() const -> bool
Propagate consequences of previously added clauses.
Definition propagate.hh:581
PropagateControl(clingo_propagate_control_t *ctl)
Constructor from the underlying C representation.
Definition propagate.hh:509
auto add_literal() const -> SolverLiteral
Add solver local literal to the solver.
Definition propagate.hh:517
void remove_watch(SolverLiteral lit) const
Remove a watch for the given solver literal.
Definition propagate.hh:586
auto assignment() const -> Assignment
Get the assignment of the current solver.
Definition propagate.hh:593
auto add_nogood(SolverLiteralSpan literals, ClauseFlags flags=ClauseFlags::none) const -> bool
Add a nogood to the solver.
Definition propagate.hh:555
void add_watch(SolverLiteral literal) const
Add a watch for the given solver literal.
Definition propagate.hh:562
auto has_watch(SolverLiteral literal) const -> bool
Check whether the given solver literal is watched.
Definition propagate.hh:570
Object to initialize a user-defined propagator before each solving step.
Definition propagate.hh:318
auto add_clause(SolverLiteralSpan literals) const -> bool
Add a clause to the solver.
Definition propagate.hh:389
PropagateInit(clingo_propagate_init_t *init)
Constructor from the underlying C representation.
Definition propagate.hh:323
auto propagate() const -> bool
Propagate consequences of the underlying problem.
Definition propagate.hh:472
auto add_literal(bool freeze=true) const -> SolverLiteral
Add a literal to the solver.
Definition propagate.hh:412
auto library() const -> Library
Get the library object associated with the propagator.
Definition propagate.hh:335
void freeze_literal(SolverLiteral literal) const
Freeze the given literal in the solver.
Definition propagate.hh:462
void add_minimize(SolverLiteral literal, Weight weight, Weight priority) const
Add a weighted literal to minimize to the solver.
Definition propagate.hh:421
void remove_watch(SolverLiteral literal, std::optional< ProgramId > thread_id) const
Remove a watch for the given solver literal.
Definition propagate.hh:480
auto check_mode() const -> PropagatorCheckMode
Get the check mode of the propagator.
Definition propagate.hh:347
void undo_mode(PropagatorUndoMode mode) const
Set the undo mode of the propagator.
Definition propagate.hh:376
auto assignment() const -> Assignment
Get the assignment of the current solver.
Definition propagate.hh:328
auto add_weight_constraint(SolverLiteral literal, WeightedLiteralSpan literals, Weight bound, WeightConstraintType type, bool compare_equal) const -> bool
Add a weight constraint to the solver.
Definition propagate.hh:451
auto solver_literal(ProgramLiteral literal) const -> SolverLiteral
Map a program literal to a solver literal.
Definition propagate.hh:492
auto undo_mode() const -> PropagatorUndoMode
Get the undo mode of the propagator.
Definition propagate.hh:369
auto base() const -> Base
Get the base object associated with the propagator.
Definition propagate.hh:342
void check_mode(PropagatorCheckMode mode)
Set the check mode of the propagator.
Definition propagate.hh:354
auto number_of_threads() const -> ProgramId
Get the number of threads used in subsequent solving.
Definition propagate.hh:362
auto add_clause(SolverLiteralList literals) const -> bool
Add a clause to the solver.
Definition propagate.hh:401
void add_watch(SolverLiteral literal, std::optional< ProgramId > thread_id=std::nullopt) const
Add a watch for the given solver literal.
Definition propagate.hh:435
Interface for user-defined propagators.
Definition propagate.hh:607
void check(PropagateControl ctl)
Callback that is called on propagation fixpoints or total assignments.
Definition propagate.hh:657
void init(PropagateInit init)
Callback to initialize the propagator before each solving step.
Definition propagate.hh:619
Propagator()=default
The default constructor.
void propagate(PropagateControl ctl, ProgramLiteralSpan changes)
Callback to propagate consequences of the given literals.
Definition propagate.hh:631
Propagator(Propagator &&other)=delete
Disable copy and move operations.
void undo(ProgramId thread_id, Assignment assignment, ProgramLiteralSpan changes)
Called when the solver backtracks to a previous decision level.
Definition propagate.hh:644
virtual ~Propagator()=default
The default destructor.
A trail is a sequence of solver literals.
Definition propagate.hh:52
value_type reference
The reference type, which simply refers to the value type.
Definition propagate.hh:61
auto end(ProgramId level) const -> iterator
Get an iterator to the end of the given decision level.
Definition propagate.hh:113
Trail(clingo_assignment_t const *assignment)
Construct a trail from the underlying C representation.
Definition propagate.hh:72
Detail::RandomAccessIterator< Trail > iterator
The iterator type, which is a random access iterator over the trail.
Definition propagate.hh:65
auto size() const -> size_type
Get the size of the trail.
Definition propagate.hh:89
auto operator[](size_type index) const -> value_type
Get the literal at the given index in the trail.
Definition propagate.hh:84
auto level(ProgramId level) const
Get the subrange of the literals of the given decision level.
Definition propagate.hh:121
std::ptrdiff_t difference_type
The difference type.
Definition propagate.hh:59
Detail::ArrowProxy< value_type > pointer
The pointer type, which is a proxy to the value type.
Definition propagate.hh:63
auto begin() const -> iterator
Get an iterator to the beginning of the trail.
Definition propagate.hh:94
SolverLiteral value_type
The value type is a solver literal.
Definition propagate.hh:55
auto at(size_type index) const -> value_type
Get the literal at the given index in the trail.
Definition propagate.hh:79
auto begin(ProgramId level) const -> iterator
Get an iterator to the beginning of the given decision level.
Definition propagate.hh:105
std::size_t size_type
The size type.
Definition propagate.hh:57
auto end() const -> iterator
Get an iterator to the end of the trail.
Definition propagate.hh:99
int32_t clingo_literal_t
Signed integer type used for aspif and solver literals.
Definition core.h:78
uint32_t clingo_id_t
Unsigned integer type used in various places.
Definition core.h:82
CLINGO_VISIBILITY_DEFAULT bool clingo_propagate_control_add_watch(clingo_propagate_control_t *control, clingo_literal_t literal)
Add a watch for the solver literal in the given phase.
CLINGO_VISIBILITY_DEFAULT bool clingo_propagate_init_set_undo_mode(clingo_propagate_init_t *init, clingo_propagator_undo_mode_t mode)
Configure when to call the undo method of the propagator.
struct clingo_propagate_control clingo_propagate_control_t
This object can be used to add clauses and propagate literals while solving.
Definition propagate.h:450
CLINGO_VISIBILITY_DEFAULT bool clingo_propagate_control_remove_watch(clingo_propagate_control_t *control, clingo_literal_t literal)
Removes the watch (if any) for the given solver literal.
int clingo_weight_constraint_type_t
Corresponding type to clingo_weight_constraint_type_e.
Definition propagate.h:230
CLINGO_VISIBILITY_DEFAULT bool clingo_propagate_init_add_minimize(clingo_propagate_init_t *init, clingo_literal_t solver_literal, clingo_weight_t weight, clingo_weight_t priority)
Add the given literal to minimize to the solver.
int clingo_propagator_undo_mode_t
Corresponding type to clingo_propagator_undo_mode_e.
Definition propagate.h:221
CLINGO_VISIBILITY_DEFAULT bool clingo_propagate_init_add_watch_to_thread(clingo_propagate_init_t *init, clingo_literal_t solver_literal, clingo_id_t thread_id)
Add a watch for the solver literal in the given phase to the given solver thread.
struct clingo_assignment clingo_assignment_t
Represents a (partial) assignment of a particular solver.
Definition propagate.h:46
struct clingo_propagate_init clingo_propagate_init_t
Object to initialize a user-defined propagator before each solving step.
Definition propagate.h:243
int clingo_propagator_check_mode_t
Corresponding type to clingo_propagator_check_mode_e.
Definition propagate.h:213
CLINGO_VISIBILITY_DEFAULT bool clingo_propagate_init_remove_watch(clingo_propagate_init_t *init, clingo_literal_t solver_literal)
Remove the watch for the solver literal in the given phase.
int clingo_truth_value_t
Corresponding type to clingo_truth_value_e.
Definition propagate.h:55
CLINGO_VISIBILITY_DEFAULT bool clingo_propagate_init_set_check_mode(clingo_propagate_init_t *init, clingo_propagator_check_mode_t mode)
Configure when to call the check method of the propagator.
CLINGO_VISIBILITY_DEFAULT bool clingo_propagate_init_add_watch(clingo_propagate_init_t *init, clingo_literal_t solver_literal)
Add a watch for the solver literal in the given phase.
CLINGO_VISIBILITY_DEFAULT bool clingo_propagate_init_remove_watch_from_thread(clingo_propagate_init_t *init, clingo_literal_t solver_literal, uint32_t thread_id)
Remove the watch for the solver literal in the given phase from the given solver thread.
CLINGO_VISIBILITY_DEFAULT bool clingo_propagate_init_freeze_literal(clingo_propagate_init_t *init, clingo_literal_t solver_literal)
Freeze the given solver literal.
int clingo_clause_type_t
Corresponding type to clingo_clause_type_e.
Definition propagate.h:447
@ clingo_propagator_check_mode_both
call clingo_propagator::check() on propagation fixpoints and total assignments
Definition propagate.h:209
@ clingo_propagator_check_mode_none
do not call clingo_propagator::check() at all
Definition propagate.h:206
@ clingo_propagator_check_mode_fixpoint
call clingo_propagator::check() on propagation fixpoints
Definition propagate.h:208
@ clingo_propagator_check_mode_total
call clingo_propagator::check() on total assignments
Definition propagate.h:207
@ clingo_truth_value_false
false
Definition propagate.h:52
@ clingo_truth_value_true
true
Definition propagate.h:51
@ clingo_truth_value_free
no truth value
Definition propagate.h:50
@ clingo_clause_type_learnt
clause is subject to the solvers deletion policy
Definition propagate.h:439
@ clingo_clause_type_volatile
like clingo_clause_type_learnt but the clause is deleted after a solving step
Definition propagate.h:441
@ clingo_clause_type_static
clause is not subject to the solvers deletion policy
Definition propagate.h:440
@ clingo_propagator_undo_mode_default
call clingo_propagator::undo() for non-empty change lists
Definition propagate.h:217
@ clingo_propagator_undo_mode_always
also call clingo_propagator::check() when check has been called
Definition propagate.h:218
@ clingo_weight_constraint_type_implication_right
the literal implies the weight constraint
Definition propagate.h:226
@ clingo_weight_constraint_type_implication_left
the weight constraint implies the literal
Definition propagate.h:225
@ clingo_weight_constraint_type_equivalence
the weight constraint is equivalent to the literal
Definition propagate.h:227
@ tuple
Theory tuples "(t1,...,tn)".
clingo_literal_t SolverLiteral
A solver literal.
Definition core.hh:399
std::initializer_list< SolverLiteral const > SolverLiteralList
A list of solver literals.
Definition core.hh:403
clingo_weight_t Weight
A weight used in sum aggregates and minimize constraints.
Definition core.hh:408
clingo_literal_t ProgramLiteral
A program literal.
Definition core.hh:392
std::span< SolverLiteral const > SolverLiteralSpan
A span of solver literals.
Definition core.hh:401
std::span< WeightedLiteral const > WeightedLiteralSpan
A span of weighted literals.
Definition core.hh:415
clingo_id_t ProgramId
A program id used for various kinds of indices.
Definition core.hh:382
std::span< ProgramLiteral const > ProgramLiteralSpan
A span of program literals.
Definition core.hh:394
@ level
Set the level of an atom.
@ init
Modify the initial VSIDS score of an atom.
WeightConstraintType
Enumeration of weight constraint types.
Definition propagate.hh:30
ClauseFlags
Enumeration of clause flags.
Definition propagate.hh:37
PropagatorCheckMode
Enumeration of propagator check modes.
Definition propagate.hh:16
PropagatorUndoMode
Enumeration of propagator undo modes.
Definition propagate.hh:24
@ equivalence
The weight constraint is equivalent to the literal.
Definition propagate.hh:33
@ implication_left
The weight constraint implies the literal.
Definition propagate.hh:31
@ implication_right
The literal implies the weight constraint.
Definition propagate.hh:32
@ lock
Exempt the clause from deletion.
Definition propagate.hh:39
@ tag
Delete the clause at the end of the current solving step.
Definition propagate.hh:40
@ none
The empty set of flags.
Definition propagate.hh:38
@ fixpoint
Call check on propagation fixpoints.
@ both
Call check on propagation fixpoints and total assignments.
@ total
Call check on total assignments.
@ default_
Call undo for non-empty change lists.
@ always
Also call undo for empty change lists.
#define CLINGO_ENABLE_BITSET_ENUM(E,...)
Opt-in macro for enabling bit operations for a given enum type.
Definition enum.hh:18
An instance of this struct has to be registered with a solver to implement a custom propagator.
Definition propagate.h:557