clingo
|
A class for defining a logic program. More...
#include <logic_program.h>
Classes | |
struct | AspOptions |
Options for the Asp-Preprocessor. More... | |
Public Types | |
enum | ExtendedRuleMode { mode_native = 0, mode_transform = 1, mode_transform_choice = 2, mode_transform_card = 3, mode_transform_weight = 4, mode_transform_scc = 5, mode_transform_nhcf = 6, mode_transform_integ = 7, mode_transform_dynamic = 8 } |
Defines the possible modes for handling extended rules, i.e. choice, cardinality, and weight rules. More... | |
Public Types inherited from Clasp::ProgramBuilder | |
typedef SharedMinimizeData | SharedMinimize |
typedef SingleOwnerPtr < SharedMinimize, ReleaseObject > | MinPtr |
Public Member Functions | |
LogicProgram () | |
~LogicProgram () | |
Step control functions | |
LogicProgram & | start (SharedContext &ctx, const AspOptions &opts=AspOptions()) |
Starts the definition of a logic program. More... | |
void | setExtendedRuleMode (ExtendedRuleMode m) |
Sets the mode for handling extended rules (default: mode_native). More... | |
void | setOptions (const AspOptions &opts) |
Sets preprocessing options. More... | |
void | setNonHcfConfiguration (Configuration *c) |
Sets the configuration to be used for checker solvers in disjunctive LP solving. More... | |
bool | update () |
Unfreezes a currently frozen program and starts an incremental step. More... | |
bool | end () |
Finishes the definition of the logic program (or its current increment). More... | |
void | write (std::ostream &os) |
Writes the (possibly simplified) program in lparse-format to the given stream. More... | |
void | dispose (bool forceFullDispose) |
Disposes (parts of) the internal representation of the logic program. More... | |
bool | clone (SharedContext &ctx, bool shareSymbols=false) |
Clones the program and adds it to the given ctx. More... | |
Program mutating functions | |
Var | newAtom () |
Adds a new atom to the program. More... | |
LogicProgram & | setAtomName (Var atomId, const char *name) |
Sets the name of the given atom and adds it to the program's symbol table. More... | |
LogicProgram & | setCompute (Var atomId, bool value) |
Forces the atom's truth-value to value. More... | |
LogicProgram & | freeze (Var atomId, ValueRep value=value_false) |
Protects an otherwise undefined atom from preprocessing. More... | |
LogicProgram & | unfreeze (Var atomId) |
Removes any protection from the given atom. More... | |
LogicProgram & | addRule (const Rule &r) |
Adds the given rule to the program. More... | |
Rule creation functions | |
Functions in this group may be used to construct logic program rules. The construction of a rule must start with a call to startRule() and ends with a call to endRule(). Functions for adding elements to a rule shall only be called between calls to startRule()/endRule() and only one rule can be under construction at any one time. | |
LogicProgram & | startRule (RuleType t=BASICRULE, weight_t bound=-1) |
Starts the construction of a rule. More... | |
LogicProgram & | setBound (weight_t bound) |
Sets the bound (resp. min weight) of the currently active rule. More... | |
LogicProgram & | addHead (Var atomId) |
Adds the atom with the given id as a head to the currently active rule. More... | |
LogicProgram & | addToBody (Var atomId, bool pos, weight_t weight=1) |
Adds a subgoal to the currently active rule. More... | |
LogicProgram & | endRule () |
Finishes the construction of the active rule and adds it to the program. More... | |
Public Member Functions inherited from Clasp::ProgramBuilder | |
ProgramBuilder () | |
virtual | ~ProgramBuilder () |
bool | startProgram (SharedContext &ctx) |
Starts the definition of a program. More... | |
bool | parseProgram (StreamSource &prg) |
Parses the given stream as a program of type() and adds it to this object. More... | |
bool | parseProgram (std::istream &prg) |
bool | updateProgram () |
Unfreezes a currently frozen program. More... | |
bool | endProgram () |
Loads the program into the shared context passed to startProgram(). More... | |
void | getAssumptions (LitVec &out) const |
Returns any assumptions that shall hold during solving. More... | |
SharedMinimize * | getMinimizeConstraint (SumVec *softBound=0) const |
Returns an optimized representation of the program's minimize statements (if any). More... | |
void | disposeMinimizeConstraint () |
Removes a previously created minimize constraint. More... | |
int | type () const |
Returns the type of program that is created by this builder. More... | |
bool | frozen () const |
Returns true if the program is currently frozen. More... | |
SharedContext * | ctx () const |
Returns the stored context object. More... | |
Query functions | |
Functions in this group are useful to query important information once the program is frozen, i.e. after end() was called. | |
LpStats | stats |
LpStats * | accu |
bool | hasMinimize () const |
Returns whether the program contains any minimize statements. More... | |
uint32 | numAtoms () const |
Returns the number of atoms in the logic program. More... | |
uint32 | numBodies () const |
Returns the number of bodies in the current (slice of the) logic program. More... | |
uint32 | numDisjunctions () const |
Returns the number of disjunctive heads. More... | |
Var | startAtom () const |
Returns the id of the first atom of the current step. More... | |
Literal | getLiteral (Var atomId) const |
Returns the internal literal that is associated with the given atom. More... | |
Implementation functions | |
Low-level implementation functions. Use with care and only if you know what you are doing! | |
typedef VarVec::const_iterator | VarIter |
typedef PrgHead *const * | HeadIter |
typedef std::pair < EdgeIterator, EdgeIterator > | EdgeRange |
typedef std::pair< HeadIter, HeadIter > | HeadRange |
const AspOptions & | options () const |
bool | hasConflict () const |
bool | ok () const |
Returns true if the program is not conflicting. More... | |
PrgAtom * | getAtom (Var atomId) const |
PrgHead * | getHead (PrgEdge it) const |
PrgNode * | getSupp (PrgEdge it) const |
Var | getEqAtom (Var a) const |
PrgBody * | getBody (Var bodyId) const |
Var | getEqBody (Var b) const |
PrgDisj * | getDisj (Var disjId) const |
bool | isFact (PrgAtom *a) const |
HeadIter | disj_begin () const |
HeadIter | disj_end () const |
HeadIter | atom_begin () const |
HeadIter | atom_end () const |
VarIter | unfreeze_begin () const |
VarIter | unfreeze_end () const |
const char * | getAtomName (Var id) const |
RuleType | simplifyRule (const Rule &r, VarVec &head, BodyInfo &info) |
VarVec & | getSupportedBodies (bool sorted) |
uint32 | update (PrgBody *b, uint32 oldHash, uint32 newHash) |
bool | assignValue (PrgAtom *a, ValueRep v) |
bool | assignValue (PrgHead *h, ValueRep v) |
bool | propagate (bool backprop) |
PrgAtom * | mergeEqAtoms (PrgAtom *a, Var rootAtom) |
PrgBody * | mergeEqBodies (PrgBody *b, Var rootBody, bool hashEq, bool atomsAssigned) |
bool | propagate () |
void | setConflict () |
RuleState & | ruleState () |
void | addMinimize () |
void | upRules (RuleType r, int i) |
void | incTr (RuleType r, uint32 n) |
void | incTrAux (uint32 n) |
void | incEqs (VarType t) |
Additional Inherited Members | |
Protected Member Functions inherited from Clasp::ProgramBuilder | |
void | addMinLit (WeightLiteral x) |
void | addMinRule (const WeightLitVec &lits) |
void | disposeMin () |
void | setFrozen (bool frozen) |
void | setCtx (SharedContext *x) |
A class for defining a logic program.
Use this class to specify a logic program. Once the program is completly defined, call endProgram() to load the logic program into a SharedContext object.
typedef std::pair<EdgeIterator, EdgeIterator> Clasp::Asp::LogicProgram::EdgeRange |
typedef PrgHead* const* Clasp::Asp::LogicProgram::HeadIter |
typedef std::pair<HeadIter, HeadIter> Clasp::Asp::LogicProgram::HeadRange |
typedef VarVec::const_iterator Clasp::Asp::LogicProgram::VarIter |
Defines the possible modes for handling extended rules, i.e. choice, cardinality, and weight rules.
Clasp::Asp::LogicProgram::LogicProgram | ( | ) |
Clasp::Asp::LogicProgram::~LogicProgram | ( | ) |
|
inline |
Adds the atom with the given id as a head to the currently active rule.
void Clasp::Asp::LogicProgram::addMinimize | ( | ) |
LogicProgram & Clasp::Asp::LogicProgram::addRule | ( | const Rule & | r | ) |
Adds the given rule to the program.
Simplifies the given rule and adds it to the program if it is neither tautological (e.g. a :- a) nor contradictory (e.g. a :- b, not b). Atoms in the simplified rule that are not yet known are implicitly created.
RedefinitionError | if the precondition is violated. |
|
inline |
Adds a subgoal to the currently active rule.
atomId | The id of the atom to be added to the rule. |
pos | true if the atom is positive. Fals otherwise |
weight | The weight the new predecessor should have in the rule. |
|
inline |
|
inline |
bool Clasp::Asp::LogicProgram::clone | ( | SharedContext & | ctx, |
bool | shareSymbols = false |
||
) |
Clones the program and adds it to the given ctx.
|
inline |
|
inline |
void Clasp::Asp::LogicProgram::dispose | ( | bool | forceFullDispose | ) |
Disposes (parts of) the internal representation of the logic program.
forceFullDispose | If set to true, the whole program is disposed. Otherwise, only the rules (of the current step) are disposed but atoms and any incremental control data remain. |
|
inline |
Finishes the definition of the logic program (or its current increment).
Applies program mutating operations issued in the current step and transforms the new program into the solver's internal representation.
|
inline |
Finishes the construction of the active rule and adds it to the program.
LogicProgram & Clasp::Asp::LogicProgram::freeze | ( | Var | atomId, |
ValueRep | value = value_false |
||
) |
Protects an otherwise undefined atom from preprocessing.
If the atom is defined in this or a previous step, the operation has no effect.
const char * Clasp::Asp::LogicProgram::getAtomName | ( | Var | id | ) | const |
Returns the internal literal that is associated with the given atom.
std::logic_error | if precondition is violated. |
VarVec & Clasp::Asp::LogicProgram::getSupportedBodies | ( | bool | sorted | ) |
|
inline |
|
inline |
Returns whether the program contains any minimize statements.
|
inline |
|
inline |
|
inline |
|
inline |
PrgBody * Clasp::Asp::LogicProgram::mergeEqBodies | ( | PrgBody * | b, |
Var | rootBody, | ||
bool | hashEq, | ||
bool | atomsAssigned | ||
) |
Var Clasp::Asp::LogicProgram::newAtom | ( | ) |
Adds a new atom to the program.
|
inline |
Returns the number of atoms in the logic program.
|
inline |
Returns the number of bodies in the current (slice of the) logic program.
|
inline |
Returns the number of disjunctive heads.
|
inlinevirtual |
Returns true if the program is not conflicting.
Reimplemented from Clasp::ProgramBuilder.
|
inline |
bool Clasp::Asp::LogicProgram::propagate | ( | bool | backprop | ) |
|
inline |
|
inline |
LogicProgram & Clasp::Asp::LogicProgram::setAtomName | ( | Var | atomId, |
const char * | name | ||
) |
Sets the name of the given atom and adds it to the program's symbol table.
atomId | The id of the atom for which a name should be set |
name | The new name of the atom with the given id. |
RedefinitionError | precondition is violated. |
std::logic_error | program is frozen. |
|
inline |
Sets the bound (resp. min weight) of the currently active rule.
bound | The lower bound (resp. min weight) of the rule to be created. |
LogicProgram & Clasp::Asp::LogicProgram::setCompute | ( | Var | atomId, |
bool | value | ||
) |
Forces the atom's truth-value to value.
atomId | Id of the Atom for which a truth-value should be set. |
pos | If true, atom is set to true (forced to be in every answer set). Otherwise atom is set to false (not part of any answer set). |
|
inline |
|
inline |
Sets the mode for handling extended rules (default: mode_native).
|
inline |
Sets the configuration to be used for checker solvers in disjunctive LP solving.
void Clasp::Asp::LogicProgram::setOptions | ( | const AspOptions & | opts | ) |
Sets preprocessing options.
|
inline |
Starts the definition of a logic program.
|
inline |
Returns the id of the first atom of the current step.
|
inline |
Starts the construction of a rule.
t | The type of the new rule. |
bound | The lower bound (resp. min weight) of the rule to be created. |
LogicProgram & Clasp::Asp::LogicProgram::unfreeze | ( | Var | atomId | ) |
Removes any protection from the given atom.
If the atom is defined in this or a previous step, the operation has no effect.
|
inline |
|
inline |
|
inline |
Unfreezes a currently frozen program and starts an incremental step.
If a program is to be defined incrementally, this function must be called exactly once for each step before any new rules or atoms are added.
std::logic_error | precondition is violated. |
uint32 Clasp::Asp::LogicProgram::update | ( | PrgBody * | b, |
uint32 | oldHash, | ||
uint32 | newHash | ||
) |
|
inline |
void Clasp::Asp::LogicProgram::write | ( | std::ostream & | os | ) |
Writes the (possibly simplified) program in lparse-format to the given stream.
LpStats* Clasp::Asp::LogicProgram::accu |
LpStats Clasp::Asp::LogicProgram::stats |