clingo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
Classes | Public Types | List of all members
Clasp::SharedContext Class Reference

Aggregates information to be shared between solver objects. More...

#include <shared_context.h>

Collaboration diagram for Clasp::SharedContext:
Collaboration graph

Public Types

enum  InitMode { init_share_symbols, init_copy_symbols }
 
typedef SharedDependencyGraph SDG
 
typedef PodVector< Solver * >::type SolverVec
 
typedef SingleOwnerPtr< SDGSccGraph
 
typedef ConfigurationConfigPtr
 
typedef SingleOwnerPtr
< Distributor
DistrPtr
 
typedef const ProblemStatsStatsRef
 
typedef SymbolTableSymbolsRef
 
typedef LitVec::size_type size_type
 
typedef ShortImplicationsGraph ImpGraph
 
typedef const ImpGraphImpGraphRef
 
typedef EventHandlerLogPtr
 
typedef SingleOwnerPtr
< SatPreprocessor
SatPrePtr
 

Public Member Functions

Problem introspection

Functions for querying information about the problem.

bool ok () const
 Returns true unless the master has an unresolvable top-level conflict. More...
 
bool frozen () const
 Returns whether the problem is currently frozen and therefore ready for being solved. More...
 
bool isShared () const
 Returns whether more than one solver is actively working on the problem. More...
 
bool isExtended () const
 
bool hasSolver (uint32 id) const
 Returns whether this object has a solver associcated with the given id. More...
 
Solvermaster () const
 Returns the master solver associated with this object. More...
 
Solversolver (uint32 id) const
 Returns the solver with the given id. More...
 
uint32 numVars () const
 Returns the number of problem variables. More...
 
uint32 numEliminatedVars () const
 Returns the number of eliminated vars. More...
 
bool validVar (Var var) const
 Returns true if var represents a valid variable in this problem. More...
 
VarInfo varInfo (Var v) const
 Returns information about the given variable. More...
 
bool eliminated (Var v) const
 Returns true if v is currently eliminated, i.e. no longer part of the problem. More...
 
bool marked (Literal p) const
 
Literal stepLiteral () const
 
uint32 numConstraints () const
 Returns the number of problem constraints. More...
 
uint32 numBinary () const
 Returns the number of binary constraints. More...
 
uint32 numTernary () const
 Returns the number of ternary constraints. More...
 
uint32 numUnary () const
 Returns the number of unary constraints. More...
 
uint32 problemComplexity () const
 Returns an estimate of the problem complexity based on the number and type of constraints. More...
 
StatsRef stats () const
 
SymbolsRef symbolTable () const
 
Problem setup

Functions for specifying the problem. Problem specification is a four-stage process:

  1. Add variables to the SharedContext object.
  2. Call startAddConstraints().
  3. Add problem constraints to the master solver.
  4. Call endInit() to finish the initialization process.
Note
After endInit() was called, other solvers can be attached to this object.
In incremental setting, the process must be repeated for each incremental step.
Problem specification is not thread-safe, i.e. during initialization no other thread shall access the context.
!frozen() is a precondition for all functions in this group!
bool unfreeze ()
 Unfreezes a frozen program and prepares it for updates. More...
 
void cloneVars (const SharedContext &other, InitMode m=init_copy_symbols)
 Clones vars and symbol table from other. More...
 
void resizeVars (uint32 maxVar)
 Sets the range of problem variables to [1, maxVar) More...
 
Var addVar (VarType t, bool eq=false)
 Adds a new variable of type t. More...
 
void requestStepVar ()
 Requests a special variable for tagging volatile knowledge in incremental setting. More...
 
void requestData (Var v)
 Request additional reason data slot for variable v. More...
 
void setFrozen (Var v, bool b)
 Freezes/defreezes a variable (a frozen var is exempt from Sat-preprocessing). More...
 
void setNant (Var v, bool b)
 Marks/unmarks v as contained in a negative loop or head of a choice rule. More...
 
void setInDisj (Var v, bool b)
 Marks/unmarks v as contained in a non-hcf disjunction. More...
 
void setProject (Var v, bool b)
 Marks/unmarks v as projection variable. More...
 
void setVarEq (Var v, bool b)
 
void mark (Literal p)
 
void unmark (Var v)
 
void eliminate (Var v)
 Eliminates the variable v from the problem. More...
 
SolverstartAddConstraints (uint32 constraintGuess=100)
 Prepares the master solver so that constraints can be added. More...
 
bool addUnary (Literal x)
 A convenience method for adding facts to the master. More...
 
bool addBinary (Literal x, Literal y)
 A convenience method for adding binary clauses. More...
 
bool addTernary (Literal x, Literal y, Literal z)
 A convenience method for adding ternary clauses. More...
 
void add (Constraint *c)
 A convenience method for adding constraints to the master. More...
 
bool endInit (bool attachAll=false)
 Finishes initialization of the master solver. More...
 

Configuration

SatPrePtr satPrepro
 
SccGraph sccGraph
 
 SharedContext ()
 Creates a new object for sharing variables and the binary and ternary implication graph. More...
 
 ~SharedContext ()
 
void reset ()
 Resets this object to the state after default construction. More...
 
void setEventHandler (EventHandler *r)
 Enables event reporting via the given event handler. More...
 
void setShareMode (ContextParams::ShareMode m)
 Sets how to handle physical sharing of constraints. More...
 
void setShortMode (ContextParams::ShortMode m)
 Sets whether the short implication graph should be used for storing short learnt constraints. More...
 
void setConcurrency (uint32 numSolver)
 Sets maximal number of solvers sharing this object. More...
 
SolveraddSolver ()
 Adds an additional solver to this object and returns it. More...
 
void enableStats (uint32 level)
 Configures the statistic object of attached solvers. More...
 
void accuStats ()
 
void setPreserveModels (bool b=true)
 If b is true, sets preprocessing mode to model-preserving operations only. More...
 
void setConfiguration (Configuration *c, bool own)
 Sets the configuration for this object and its attached solvers. More...
 
ConfigPtr configuration () const
 Returns the current configuration used in this object. More...
 
LogPtr eventHandler () const
 Returns the active event handler or 0 if none was set. More...
 
bool seedSolvers () const
 Returns whether this object seeds the RNG of new solvers. More...
 
uint32 concurrency () const
 Returns the number of solvers that can share this object. More...
 
bool preserveModels () const
 
bool physicalShare (ConstraintType t) const
 Returns whether physical sharing is enabled for constraints of type t. More...
 
bool physicalShareProblem () const
 Returns whether pyhiscal sharing of problem constraints is enabled. More...
 
bool allowImplicit (ConstraintType t) const
 Returns whether short constraints of type t can be stored in the short implication graph. More...
 

(Parallel) solving

Functions to be called during (parallel) solving.

Note
If not otherwise noted, the functions in this group can be safely called from multiple threads.
DistrPtr distributor
 
bool attach (uint32 id)
 Attaches the solver with the given id to this object. More...
 
bool attach (Solver &s)
 
void detach (uint32 id, bool reset=false)
 Detaches the solver with the given id from this object. More...
 
void detach (Solver &s, bool reset=false)
 
uint32 winner () const
 
void setWinner (uint32 sId)
 
void simplify (bool shuffle)
 Simplifies the problem constraints w.r.t the master's assignment. More...
 
void removeConstraint (uint32 idx, bool detach)
 Removes the constraint with the given idx from the master's db. More...
 
int addImp (ImpGraph::ImpType t, const Literal *lits, ConstraintType ct)
 Adds the given short implication to the short implication graph if possible. More...
 
uint32 numLearntShort () const
 Returns the number of learnt short implications. More...
 
ImpGraphRef shortImplications () const
 
void simplifyShort (const Solver &s, Literal p)
 
void report (const Event &ev) const
 
bool report (const Solver &s, const Model &m) const
 
void initStats (Solver &s) const
 
const SolverStatsstats (const Solver &s, bool accu) const
 

Detailed Description

Aggregates information to be shared between solver objects.

Among other things, SharedContext objects store static information on variables, the (possibly unused) symbol table, as well as the binary and ternary implication graph of the input problem.

Furthermore, a SharedContext object always stores a distinguished master solver that is used to store and simplify problem constraints. Additional solvers can be added via SharedContext::addSolver(). Once initialization is completed, any additional solvers must be attached to this object by calling SharedContext::attach().

Member Typedef Documentation

typedef LitVec::size_type Clasp::SharedContext::size_type

Member Enumeration Documentation

Enumerator
init_share_symbols 
init_copy_symbols 

Constructor & Destructor Documentation

Clasp::SharedContext::SharedContext ( )
explicit

Creates a new object for sharing variables and the binary and ternary implication graph.

Here is the call graph for this function:

Clasp::SharedContext::~SharedContext ( )

Member Function Documentation

void Clasp::SharedContext::accuStats ( )

Here is the call graph for this function:

void Clasp::SharedContext::add ( Constraint c)

A convenience method for adding constraints to the master.

Here is the call graph for this function:

bool Clasp::SharedContext::addBinary ( Literal  x,
Literal  y 
)

A convenience method for adding binary clauses.

Here is the call graph for this function:

int Clasp::SharedContext::addImp ( ImpGraph::ImpType  t,
const Literal lits,
ConstraintType  ct 
)

Adds the given short implication to the short implication graph if possible.

Returns
  • > 0 if implication was added.
  • < 0 if implication can't be added because allowImplicit() is false for ct.
  • = 0 if implication is subsumed by some constraint in the short implication graph.

Here is the call graph for this function:

Solver & Clasp::SharedContext::addSolver ( )

Adds an additional solver to this object and returns it.

bool Clasp::SharedContext::addTernary ( Literal  x,
Literal  y,
Literal  z 
)

A convenience method for adding ternary clauses.

Here is the call graph for this function:

bool Clasp::SharedContext::addUnary ( Literal  x)

A convenience method for adding facts to the master.

Here is the call graph for this function:

Var Clasp::SharedContext::addVar ( VarType  t,
bool  eq = false 
)

Adds a new variable of type t.

Parameters
tType of the new variable (either Var_t::atom_var or Var_t::body_var).
eqTrue if var represents both an atom and a body. In that case t is the variable's primary type and determines the preferred literal.
Returns
The index of the new variable.
Note
Problem variables are numbered from 1 onwards!

Here is the call graph for this function:

bool Clasp::SharedContext::allowImplicit ( ConstraintType  t) const
inline

Returns whether short constraints of type t can be stored in the short implication graph.

bool Clasp::SharedContext::attach ( uint32  id)
inline

Attaches the solver with the given id to this object.

Note
It is safe to attach multiple solvers concurrently but the master solver shall not change during the whole operation.
Precondition
hasSolver(id)

Here is the call graph for this function:

bool Clasp::SharedContext::attach ( Solver s)

Here is the call graph for this function:

void Clasp::SharedContext::cloneVars ( const SharedContext other,
InitMode  m = init_copy_symbols 
)

Clones vars and symbol table from other.

Here is the call graph for this function:

uint32 Clasp::SharedContext::concurrency ( ) const
inline

Returns the number of solvers that can share this object.

ConfigPtr Clasp::SharedContext::configuration ( ) const
inline

Returns the current configuration used in this object.

void Clasp::SharedContext::detach ( uint32  id,
bool  reset = false 
)
inline

Detaches the solver with the given id from this object.

The function removes any tentative constraints from s. Shall be called once after search has stopped.

Note
The function is concurrency-safe w.r.t to different solver objects, i.e. in a parallel search different solvers may call detach() concurrently.

Here is the call graph for this function:

void Clasp::SharedContext::detach ( Solver s,
bool  reset = false 
)

Here is the call graph for this function:

void Clasp::SharedContext::eliminate ( Var  v)

Eliminates the variable v from the problem.

Precondition
v must not occur in any constraint and frozen(v) == false and value(v) == value_free

Here is the call graph for this function:

bool Clasp::SharedContext::eliminated ( Var  v) const

Returns true if v is currently eliminated, i.e. no longer part of the problem.

Here is the call graph for this function:

void Clasp::SharedContext::enableStats ( uint32  level)

Configures the statistic object of attached solvers.

The level determines the amount of extra statistics. Currently two levels are supported:

Here is the call graph for this function:

bool Clasp::SharedContext::endInit ( bool  attachAll = false)

Finishes initialization of the master solver.

The function must be called once before search is started. After endInit() was called, previously added solvers can be attached to the shared context and learnt constraints may be added to solver.

Parameters
attachAllIf true, also calls attach() for all solvers that were added to this object.
Returns
If the constraints are initially conflicting, false. Otherwise, true.
Note
The master solver can't recover from top-level conflicts, i.e. if endInit() returned false, the solver is in an unusable state.
Postcondition
frozen()

Here is the call graph for this function:

LogPtr Clasp::SharedContext::eventHandler ( ) const
inline

Returns the active event handler or 0 if none was set.

bool Clasp::SharedContext::frozen ( ) const
inline

Returns whether the problem is currently frozen and therefore ready for being solved.

bool Clasp::SharedContext::hasSolver ( uint32  id) const
inline

Returns whether this object has a solver associcated with the given id.

void Clasp::SharedContext::initStats ( Solver s) const

Here is the call graph for this function:

bool Clasp::SharedContext::isExtended ( ) const
inline
bool Clasp::SharedContext::isShared ( ) const
inline

Returns whether more than one solver is actively working on the problem.

void Clasp::SharedContext::mark ( Literal  p)
inline

Here is the call graph for this function:

bool Clasp::SharedContext::marked ( Literal  p) const
inline

Here is the call graph for this function:

Solver* Clasp::SharedContext::master ( ) const
inline

Returns the master solver associated with this object.

uint32 Clasp::SharedContext::numBinary ( ) const
inline

Returns the number of binary constraints.

uint32 Clasp::SharedContext::numConstraints ( ) const

Returns the number of problem constraints.

Here is the call graph for this function:

uint32 Clasp::SharedContext::numEliminatedVars ( ) const
inline

Returns the number of eliminated vars.

uint32 Clasp::SharedContext::numLearntShort ( ) const
inline

Returns the number of learnt short implications.

uint32 Clasp::SharedContext::numTernary ( ) const
inline

Returns the number of ternary constraints.

uint32 Clasp::SharedContext::numUnary ( ) const
inline

Returns the number of unary constraints.

uint32 Clasp::SharedContext::numVars ( ) const
inline

Returns the number of problem variables.

Note
The special sentinel-var 0 is not counted, i.e. numVars() returns the number of problem-variables. To iterate over all problem variables use a loop like:
for (Var i = 1; i <= numVars(); ++i) {...}
bool Clasp::SharedContext::ok ( ) const

Returns true unless the master has an unresolvable top-level conflict.

Here is the call graph for this function:

bool Clasp::SharedContext::physicalShare ( ConstraintType  t) const
inline

Returns whether physical sharing is enabled for constraints of type t.

bool Clasp::SharedContext::physicalShareProblem ( ) const
inline

Returns whether pyhiscal sharing of problem constraints is enabled.

bool Clasp::SharedContext::preserveModels ( ) const
inline
uint32 Clasp::SharedContext::problemComplexity ( ) const

Returns an estimate of the problem complexity based on the number and type of constraints.

Here is the call graph for this function:

void Clasp::SharedContext::removeConstraint ( uint32  idx,
bool  detach 
)

Removes the constraint with the given idx from the master's db.

Here is the call graph for this function:

void Clasp::SharedContext::report ( const Event ev) const
inline
bool Clasp::SharedContext::report ( const Solver s,
const Model m 
) const
inline
void Clasp::SharedContext::requestData ( Var  v)

Request additional reason data slot for variable v.

Here is the call graph for this function:

void Clasp::SharedContext::requestStepVar ( )

Requests a special variable for tagging volatile knowledge in incremental setting.

Here is the call graph for this function:

void Clasp::SharedContext::reset ( )

Resets this object to the state after default construction.

Here is the call graph for this function:

void Clasp::SharedContext::resizeVars ( uint32  maxVar)
inline

Sets the range of problem variables to [1, maxVar)

bool Clasp::SharedContext::seedSolvers ( ) const
inline

Returns whether this object seeds the RNG of new solvers.

void Clasp::SharedContext::setConcurrency ( uint32  numSolver)

Sets maximal number of solvers sharing this object.

Here is the call graph for this function:

void Clasp::SharedContext::setConfiguration ( Configuration c,
bool  own 
)

Sets the configuration for this object and its attached solvers.

Note
If own is true, ownership of c is transferred.

Here is the call graph for this function:

void Clasp::SharedContext::setEventHandler ( EventHandler r)
inline

Enables event reporting via the given event handler.

void Clasp::SharedContext::setFrozen ( Var  v,
bool  b 
)

Freezes/defreezes a variable (a frozen var is exempt from Sat-preprocessing).

Here is the call graph for this function:

void Clasp::SharedContext::setInDisj ( Var  v,
bool  b 
)
inline

Marks/unmarks v as contained in a non-hcf disjunction.

void Clasp::SharedContext::setNant ( Var  v,
bool  b 
)
inline

Marks/unmarks v as contained in a negative loop or head of a choice rule.

void Clasp::SharedContext::setPreserveModels ( bool  b = true)
inline

If b is true, sets preprocessing mode to model-preserving operations only.

void Clasp::SharedContext::setProject ( Var  v,
bool  b 
)
inline

Marks/unmarks v as projection variable.

void Clasp::SharedContext::setShareMode ( ContextParams::ShareMode  m)

Sets how to handle physical sharing of constraints.

void Clasp::SharedContext::setShortMode ( ContextParams::ShortMode  m)

Sets whether the short implication graph should be used for storing short learnt constraints.

void Clasp::SharedContext::setVarEq ( Var  v,
bool  b 
)
inline
void Clasp::SharedContext::setWinner ( uint32  sId)
inline
ImpGraphRef Clasp::SharedContext::shortImplications ( ) const
inline
void Clasp::SharedContext::simplify ( bool  shuffle)

Simplifies the problem constraints w.r.t the master's assignment.

Here is the call graph for this function:

void Clasp::SharedContext::simplifyShort ( const Solver s,
Literal  p 
)

Here is the call graph for this function:

Solver* Clasp::SharedContext::solver ( uint32  id) const
inline

Returns the solver with the given id.

Solver & Clasp::SharedContext::startAddConstraints ( uint32  constraintGuess = 100)

Prepares the master solver so that constraints can be added.

Must be called to publish previously added variables to master solver and before constraints over these variables can be added.

Returns
The master solver associated with this object.

Here is the call graph for this function:

StatsRef Clasp::SharedContext::stats ( ) const
inline
const SolverStats & Clasp::SharedContext::stats ( const Solver s,
bool  accu 
) const

Here is the call graph for this function:

Literal Clasp::SharedContext::stepLiteral ( ) const
inline
SymbolsRef Clasp::SharedContext::symbolTable ( ) const
inline
bool Clasp::SharedContext::unfreeze ( )

Unfreezes a frozen program and prepares it for updates.

The function also triggers forgetting of volatile knowledge and removes any auxiliary variables.

See also
requestStepVar()
Solver::popAuxVar()

Here is the call graph for this function:

void Clasp::SharedContext::unmark ( Var  v)
inline
bool Clasp::SharedContext::validVar ( Var  var) const
inline

Returns true if var represents a valid variable in this problem.

Note
The range of valid variables is [1..numVars()]. The variable 0 is a special sentinel variable.
VarInfo Clasp::SharedContext::varInfo ( Var  v) const
inline

Returns information about the given variable.

uint32 Clasp::SharedContext::winner ( ) const
inline

Member Data Documentation

DistrPtr Clasp::SharedContext::distributor

Distributor object to use for distribution of learnt constraints.

SatPrePtr Clasp::SharedContext::satPrepro

Preprocessor for simplifying problem.

SccGraph Clasp::SharedContext::sccGraph

Program dependency graph - only used for ASP-problems.


The documentation for this class was generated from the following files: