clingo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
shared_context.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2010-2012, Benjamin Kaufmann
3 //
4 // This file is part of Clasp. See http://www.cs.uni-potsdam.de/clasp/
5 //
6 // Clasp is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // Clasp is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with Clasp; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 #ifndef CLASP_SHARED_CONTEXT_H_INCLUDED
21 #define CLASP_SHARED_CONTEXT_H_INCLUDED
22 #ifdef _MSC_VER
23 #pragma warning (disable : 4200) // nonstandard extension used : zero-sized array
24 #pragma once
25 #endif
26 
27 #include <clasp/literal.h>
28 #include <clasp/constraint.h>
30 #include <clasp/util/misc_types.h>
31 #include <clasp/util/atomic.h>
37 namespace Clasp {
38 class Solver;
39 class ClauseInfo;
40 class Assignment;
41 class SharedContext;
42 class SharedLiterals;
43 class SharedDependencyGraph;
44 struct SolverStats;
45 
50 class SatPreprocessor {
52 public:
54  class Clause {
55  public:
56  static Clause* newClause(const Literal* lits, uint32 size);
57  static uint64 abstractLit(Literal p) { return uint64(1) << ((p.var()-1) & 63); }
58  uint32 size() const { return size_; }
59  const Literal& operator[](uint32 x) const { return lits_[x]; }
60  bool inQ() const { return inQ_ != 0; }
61  uint64 abstraction() const { return data_.abstr; }
62  Clause* next() const { return data_.next; }
63  bool marked() const { return marked_ != 0;}
64  Literal& operator[](uint32 x) { return lits_[x]; }
65  void setInQ(bool b) { inQ_ = (uint32)b;}
66  void setMarked(bool b) { marked_ = (uint32)b;}
67  uint64& abstraction() { return data_.abstr; }
68  Clause* linkRemoved(Clause* next) { data_.next = next; return this; }
69  void strengthen(Literal p);
70  void simplify(Solver& s);
71  void destroy();
72  private:
73  Clause(const Literal* lits, uint32 size);
74  union {
75  uint64 abstr; // abstraction of literals
76  Clause* next; // next removed clause
77  } data_;
78  uint32 size_ : 30; // size of the clause
79  uint32 inQ_ : 1; // in todo-queue?
80  uint32 marked_ : 1; // a marker flag
81  Literal lits_[1]; // literals of the clause: [lits_[0], lits_[size_])
82  };
83 
84  SatPreprocessor() : ctx_(0), elimTop_(0), seen_(1,1) {}
85  virtual ~SatPreprocessor();
86 
88 
91  virtual SatPreprocessor* clone() = 0;
92 
93  uint32 numClauses() const { return (uint32)clauses_.size(); }
95 
100  bool addClause(const LitVec& cl) { return addClause(!cl.empty() ? &cl[0] : 0, cl.size()); }
101  bool addClause(const Literal* clause, uint32 size);
103 
106  bool preprocess(SharedContext& ctx, SatPreParams& opts);
107  bool preprocess(SharedContext& ctx);
108 
110  void cleanUp(bool discardEliminated = false);
111 
113  void extendModel(ValueVec& m, LitVec& open);
114  struct Stats {
115  Stats() : clRemoved(0), clAdded(0), litsRemoved(0) {}
116  uint32 clRemoved;
117  uint32 clAdded;
118  uint32 litsRemoved;
119  } stats;
121 protected:
123  virtual bool initPreprocess(SatPreParams& opts) = 0;
124  virtual bool doPreprocess() = 0;
125  virtual void doExtendModel(ValueVec& m, LitVec& open) = 0;
126  virtual void doCleanUp() = 0;
127  Clause* clause(uint32 clId) { return clauses_[clId]; }
128  const Clause* clause(uint32 clId) const { return clauses_[clId]; }
129  void freezeSeen();
130  void discardClauses(bool discardEliminated);
131  void setClause(uint32 clId, const LitVec& cl) {
132  clauses_[clId] = Clause::newClause(&cl[0], (uint32)cl.size());
133  }
134  void destroyClause(uint32 clId){
135  clauses_[clId]->destroy();
136  clauses_[clId] = 0;
137  ++stats.clRemoved;
138  }
139  void eliminateClause(uint32 id){
140  elimTop_ = clauses_[id]->linkRemoved(elimTop_);
141  clauses_[id] = 0;
142  ++stats.clRemoved;
143  }
144  SharedContext* ctx_; // current context
145  Clause* elimTop_; // stack of blocked/eliminated clauses
146 private:
148  SatPreprocessor& operator=(const SatPreprocessor&);
149  ClauseList clauses_; // initial non-unit clauses
150  LitVec units_; // initial unit clauses
151  Range32 seen_; // vars seen in previous step
152 };
154 
159 
161 // Problem statistics
164 
167 struct ProblemStats {
169  uint32 vars;
171  uint32 vars_frozen;
172  uint32 constraints;
175  uint32 complexity;
176  void reset() { std::memset(this, 0, sizeof(*this)); }
178  void diff(const ProblemStats& o) {
179  vars = std::max(vars, o.vars)-std::min(vars, o.vars);
181  vars_frozen = std::max(vars_frozen, o.vars_frozen)-std::min(vars_frozen, o.vars_frozen);
182  constraints = std::max(constraints, o.constraints) - std::min(constraints, o.constraints);
185  }
186  double operator[](const char* key) const;
187  static const char* keys(const char* = 0);
188 };
189 
191 struct VarInfo {
192  enum FLAG {
193  MARK_P = 0x1u, // mark for positive literal
194  MARK_N = 0x2u, // mark for negative literal
195  NANT = 0x4u, // var in NAnt(P)?
196  PROJECT= 0x8u, // do we project on this var?
197  BODY = 0x10u,// is this var representing a body?
198  EQ = 0x20u,// is the var representing both a body and an atom?
199  DISJ = 0x40u,// in non-hcf disjunction?
200  FROZEN = 0x80u // is the variable frozen?
201  };
202  VarInfo() : rep(0) {}
203 
207  bool nant() const { return has(VarInfo::NANT); }
209  bool project() const { return has(VarInfo::PROJECT);}
210  bool inDisj() const { return has(VarInfo::DISJ);}
212  bool frozen() const { return has(VarInfo::FROZEN); }
214 
217  bool preferredSign() const { return !has(VarInfo::BODY); }
218 
219  bool has(FLAG f) const { return (rep & flag(f)) != 0; }
220  bool has(uint32 f) const { return (rep & f) != 0; }
221  void set(FLAG f) { rep |= flag(f); }
222  void toggle(FLAG f) { rep ^= flag(f); }
223  static uint8 flag(FLAG x) { return uint8(x); }
224  uint8 rep;
225 };
226 
229 public:
232  enum ImpType { binary_imp = 2, ternary_imp = 3 };
233 
235  void resize(uint32 nodes);
237 
241  void markShared(bool b) { shared_ = b; }
243 
246  bool add(ImpType t, bool learnt, const Literal* lits);
247 
249 
252  void removeTrue(const Solver& s, Literal p);
253 
255 
258  bool propagate(Solver& s, Literal p) const;
260  bool propagateBin(Assignment& out, Literal p, uint32 dl) const;
262  bool reverseArc(const Solver& s, Literal p, uint32 maxLev, Antecedent& out) const;
263 
264  uint32 numBinary() const { return bin_[0]; }
265  uint32 numTernary()const { return tern_[0]; }
266  uint32 numLearnt() const { return bin_[1] + tern_[1]; }
267  uint32 numEdges(Literal p) const;
268  uint32 size() const { return graph_.size(); }
270 
278  template <class OP>
279  bool forEach(Literal p, const OP& op) const {
280  const ImplicationList& x = graph_[p.index()];
281  if (x.empty()) return true;
282  ImplicationList::const_right_iterator rEnd = x.right_end(); // prefetch
283  for (ImplicationList::const_left_iterator it = x.left_begin(), end = x.left_end(); it != end; ++it) {
284  if (!op.unary(p, *it)) { return false; }
285  }
286  for (ImplicationList::const_right_iterator it = x.right_begin(); it != rEnd; ++it) {
287  if (!op.binary(p, it->first, it->second)) { return false; }
288  }
289 #if WITH_THREADS
290  for (Block* b = (x).learnt; b ; b = b->next) {
291  p.watch(); bool r = true;
292  for (Block::const_iterator imp = b->begin(), endOf = b->end(); imp != endOf; ) {
293  if (!imp->watched()) { r = op.binary(p, imp[0], imp[1]); imp += 2; }
294  else { r = op.unary(p, imp[0]); imp += 1; }
295  if (!r) { return false; }
296  }
297  }
298 #endif
299  return true;
300  }
301 private:
304  struct Propagate;
305  struct ReverseArc;
306 #if WITH_THREADS
307  struct Block {
308  typedef Clasp::atomic<uint32> atomic_size;
309  typedef Clasp::atomic<Block*> atomic_ptr;
310  typedef const Literal* const_iterator;
311  typedef Literal* iterator;
312  enum { block_cap = (64 - (sizeof(atomic_size)+sizeof(atomic_ptr)))/sizeof(Literal) };
313  explicit Block();
314  const_iterator begin() const { return data; }
315  const_iterator end() const { return data+size(); }
316  iterator end() { return data+size(); }
317  uint32 size() const { return size_lock >> 1; }
318  bool tryLock(uint32& lockedSize);
319  void addUnlock(uint32 lockedSize, const Literal* x, uint32 xs);
320  atomic_ptr next;
321  atomic_size size_lock;
322  Literal data[block_cap];
323  };
324  typedef Block::atomic_ptr SharedBlockPtr;
325  typedef bk_lib::left_right_sequence<Literal, std::pair<Literal,Literal>, 64-sizeof(SharedBlockPtr)> ImpListBase;
326  struct ImplicationList : public ImpListBase {
327  ImplicationList() : ImpListBase() { learnt = 0; }
328  ImplicationList(const ImplicationList& other) : ImpListBase(other), learnt(other.learnt) {}
329  ~ImplicationList();
330  bool hasLearnt(Literal q, Literal r = negLit(0)) const;
331  void addLearnt(Literal q, Literal r = negLit(0));
332  void simplifyLearnt(const Solver& s);
333  bool empty() const { return ImpListBase::empty() && learnt == 0; }
334  void move(ImplicationList& other);
335  void clear(bool b);
336  SharedBlockPtr learnt;
337  };
338 #else
340 #endif
341  ImplicationList& getList(Literal p) { return graph_[p.index()]; }
342  void remove_bin(ImplicationList& w, Literal p);
343  void remove_tern(ImplicationList& w, Literal p);
344  typedef PodVector<ImplicationList>::type ImpLists;
345  ImpLists graph_; // one implication list for each literal
346  uint32 bin_[2]; // number of binary constraints (0: problem / 1: learnt)
347  uint32 tern_[2]; // number of ternary constraints(0: problem / 1: learnt)
348  bool shared_;
349 };
350 
352 class Distributor {
353 public:
354  struct Policy {
355  enum Types {
356  no = 0,
359  all = conflict | loop,
360  implicit = all + 1
361  };
362  Policy(uint32 a_sz = 0, uint32 a_lbd = 0, uint32 a_type = 0) : size(a_sz), lbd(a_lbd), types(a_type) {}
363  uint32 size : 22;
364  uint32 lbd : 7;
365  uint32 types : 3;
366  };
367  static uint64 mask(uint32 i) { return uint64(1) << i; }
368  static uint32 initSet(uint32 sz) { return (uint64(1) << sz) - 1; }
369  static bool inSet(uint64 s, uint32 id) { return (s & mask(id)) != 0; }
370  explicit Distributor(const Policy& p);
371  virtual ~Distributor();
372  bool isCandidate(uint32 size, uint32 lbd, uint32 type) const {
373  return size <= policy_.size && lbd <= policy_.lbd && ((type & policy_.types) != 0);
374  }
375  virtual void publish(const Solver& source, SharedLiterals* lits) = 0;
376  virtual uint32 receive(const Solver& in, SharedLiterals** out, uint32 maxOut) = 0;
377 private:
378  Distributor(const Distributor&);
379  Distributor& operator=(const Distributor&);
380  Policy policy_;
381 };
382 
384 
397 public:
403  typedef const ProblemStats& StatsRef;
405  typedef LitVec::size_type size_type;
407  typedef const ImpGraph& ImpGraphRef;
410  enum InitMode { init_share_symbols, init_copy_symbols };
415  explicit SharedContext();
417  ~SharedContext();
419  void reset();
421  void setEventHandler(EventHandler* r) { progress_ = r; }
423  void setShareMode(ContextParams::ShareMode m);
425  void setShortMode(ContextParams::ShortMode m);
427  void setConcurrency(uint32 numSolver);
429  Solver& addSolver();
431 
439  void enableStats(uint32 level);
440  void accuStats();
444 
447  void setConfiguration(Configuration* c, bool own);
451  ConfigPtr configuration() const { return config_.get(); }
454  LogPtr eventHandler() const { return progress_; }
456  bool seedSolvers() const { return share_.seed != 0; }
458  uint32 concurrency() const { return share_.count; }
459  bool preserveModels() const { return static_cast<SatPreParams::Mode>(share_.satPreM) == SatPreParams::prepro_preserve_models; }
461  bool physicalShare(ConstraintType t) const { return (share_.shareM & (1 + (t != Constraint_t::static_constraint))) != 0; }
463  bool physicalShareProblem() const { return (share_.shareM & ContextParams::share_problem) != 0; }
465  bool allowImplicit(ConstraintType t) const { return t != Constraint_t::static_constraint ? share_.shortM != ContextParams::short_explicit : !isShared(); }
467 
473  bool ok() const;
476  bool frozen() const { return share_.frozen;}
478  bool isShared() const { return frozen() && concurrency() > 1; }
479  bool isExtended() const { return problem_.vars_frozen || symbolTable().type() == SymbolTable::map_indirect; }
481  bool hasSolver(uint32 id) const { return id < solvers_.size(); }
483  Solver* master() const { return solver(0); }
485  Solver* solver(uint32 id) const { return solvers_[id]; }
486 
488 
496  uint32 numVars() const { return static_cast<uint32>(varInfo_.size() - 1); }
498  uint32 numEliminatedVars() const { return problem_.vars_eliminated; }
500 
504  bool validVar(Var var) const { return var < static_cast<uint32>(varInfo_.size()); }
506  VarInfo varInfo(Var v) const { assert(validVar(v)); return varInfo_[v]; }
508  bool eliminated(Var v) const;
509  bool marked(Literal p) const { return varInfo(p.var()).has(VarInfo::MARK_P + p.sign()); }
510  Literal stepLiteral() const { return step_; }
512  uint32 numConstraints() const;
514  uint32 numBinary() const { return btig_.numBinary(); }
516  uint32 numTernary() const { return btig_.numTernary(); }
518  uint32 numUnary() const { return lastTopLevel_; }
520  uint32 problemComplexity() const;
521  StatsRef stats() const { return problem_; }
522  SymbolsRef symbolTable() const { return symTabPtr_->symTab; }
524 
543 
550  bool unfreeze();
552  void cloneVars(const SharedContext& other, InitMode m = init_copy_symbols);
554  void resizeVars(uint32 maxVar) { varInfo_.resize(std::max(Var(1), maxVar)); problem_.vars = numVars(); }
556 
563  Var addVar(VarType t, bool eq = false);
565  void requestStepVar();
567  void requestData(Var v);
569  void setFrozen(Var v, bool b);
571  void setNant(Var v, bool b) { if (b != varInfo(v).has(VarInfo::NANT)) varInfo_[v].toggle(VarInfo::NANT); }
573  void setInDisj(Var v, bool b) { if (b != varInfo(v).has(VarInfo::DISJ)) varInfo_[v].toggle(VarInfo::DISJ); }
575  void setProject(Var v, bool b) { if (b != varInfo(v).has(VarInfo::PROJECT)) varInfo_[v].toggle(VarInfo::PROJECT); }
576  void setVarEq(Var v, bool b) { if (b != varInfo(v).has(VarInfo::EQ)) varInfo_[v].toggle(VarInfo::EQ); }
577  void mark(Literal p) { assert(validVar(p.var())); varInfo_[p.var()].rep |= (VarInfo::MARK_P + p.sign()); }
578  void unmark(Var v) { assert(validVar(v)); varInfo_[v].rep &= ~(VarInfo::MARK_P|VarInfo::MARK_N); }
580 
583  void eliminate(Var v);
584 
586 
591  Solver& startAddConstraints(uint32 constraintGuess = 100);
592 
594  bool addUnary(Literal x);
596  bool addBinary(Literal x, Literal y);
598  bool addTernary(Literal x, Literal y, Literal z);
600  void add(Constraint* c);
601 
603 
614  bool endInit(bool attachAll = false);
616 
625 
632  bool attach(uint32 id) { return attach(*solver(id)); }
633  bool attach(Solver& s);
634 
635 
637 
644  void detach(uint32 id, bool reset = false) { return detach(*solver(id), reset); }
645  void detach(Solver& s, bool reset = false);
646 
649  uint32 winner() const { return share_.winner; }
650  void setWinner(uint32 sId) { share_.winner = std::min(sId, concurrency()); }
651 
653  void simplify(bool shuffle);
655  void removeConstraint(uint32 idx, bool detach);
656 
658 
664  int addImp(ImpGraph::ImpType t, const Literal* lits, ConstraintType ct);
666  uint32 numLearntShort() const { return btig_.numLearnt(); }
667  ImpGraphRef shortImplications() const { return btig_; }
668  void simplifyShort(const Solver& s, Literal p);
669  void report(const Event& ev) const { if (progress_) progress_->dispatch(ev); }
670  bool report(const Solver& s, const Model& m) const { return !progress_ || progress_->onModel(s, m); }
671  void initStats(Solver& s) const;
672  const SolverStats& stats(const Solver& s, bool accu) const;
674 private:
676  SharedContext& operator=(const SharedContext&);
677  void init();
678  bool unfreezeStep();
679  Literal addAuxLit();
680  typedef SingleOwnerPtr<Configuration> Config;
682  typedef PodVector<SolverStats*>::type StatsVec;
683  struct SharedSymTab {
684  SharedSymTab() : refs(1) {}
685  SymbolTable symTab;
686  uint32 refs;
687  }* symTabPtr_; // pointer to shared symbol table
688  ProblemStats problem_; // problem statistics
689  VarVec varInfo_; // varInfo[v] stores info about variable v
690  ImpGraph btig_; // binary-/ternary implication graph
691  Config config_; // active configuration
692  SolverVec solvers_; // solvers associated with this context
693  LogPtr progress_; // event handler or 0 if not used
694  Literal step_; // literal for tagging enumeration/step constraints
695  uint32 lastTopLevel_;// size of master's top-level after last init
696  struct Share { // Additional data
697  uint32 count :12; // max number of objects sharing this object
698  uint32 winner :12; // id of solver that terminated the search
699  uint32 shareM : 3; // physical sharing mode
700  uint32 shortM : 1; // short clause mode
701  uint32 frozen : 1; // is adding of problem constraints allowed?
702  uint32 seed : 1; // set seed of new solvers
703  uint32 satPreM : 1; // preprocessing mode
704  Share() : count(1), winner(0), shareM((uint32)ContextParams::share_auto), shortM(0), frozen(0), seed(0), satPreM(0) {}
705  } share_;
706  StatsVec accu_; // optional stats accumulator for incremental solving
707 };
709 }
710 #endif
Definition: shared_context.h:194
BinderType type
Definition: statements.cc:1283
bool forEach(Literal p, const OP &op) const
Applies op on all unary- and binary implications following from p.
Definition: shared_context.h:279
Definition: shared_context.h:196
struct Clasp::SatPreprocessor::Stats stats
ProblemStats()
Definition: shared_context.h:168
Var var() const
Returns the variable of the literal.
Definition: literal.h:117
PodVector< ValueRep >::type ValueVec
Definition: literal.h:207
Definition: shared_context.h:114
uint32 winner() const
Definition: shared_context.h:649
void mark(Literal p)
Definition: shared_context.h:577
ImpType
Definition: shared_context.h:232
VarType type() const
Returns the type of the variable (or Var_t::atom_body_var if variable was created with parameter eq=t...
Definition: shared_context.h:205
SccGraph sccGraph
Definition: shared_context.h:449
uint32 numBinary() const
Returns the number of binary constraints.
Definition: shared_context.h:514
SingleOwnerPtr< SDG > SccGraph
Definition: shared_context.h:400
uint32 numClauses() const
Definition: shared_context.h:93
Stores a reference to the constraint that implied a literal.
Definition: constraint.h:399
uint32 size() const
Definition: shared_context.h:268
void cleanUp(bool discardEliminated=false)
Force removal of state & clauses.
Definition: shared_context.cpp:329
uint32 index() const
Returns the unique index of this literal.
Definition: literal.h:99
void setProject(Var v, bool b)
Marks/unmarks v as projection variable.
Definition: shared_context.h:575
static Clause * newClause(const Literal *lits, uint32 size)
Definition: shared_context.cpp:444
PodVector< Solver * >::type SolverVec
Definition: shared_context.h:399
Solver * master() const
Returns the master solver associated with this object.
Definition: shared_context.h:483
PodVector< Clause * >::type ClauseList
Definition: shared_context.h:122
Definition: constraint.h:53
uint32 vars_eliminated
Definition: shared_context.h:170
Types
Definition: shared_context.h:355
Definition: literal.h:55
Type for storing a model.
Definition: enumerator.h:38
void watch()
Sets the watched-flag of this literal.
Definition: literal.h:128
SharedContext * ctx_
Definition: shared_context.h:144
SingleOwnerPtr< SatPreprocessor > SatPrePtr
Definition: shared_context.h:409
VarInfo varInfo(Var v) const
Returns information about the given variable.
Definition: shared_context.h:506
bool isExtended() const
Definition: shared_context.h:479
const ImpGraph & ImpGraphRef
Definition: shared_context.h:407
Definition: solver_strategies.h:337
Definition: shared_context.h:197
uint32 vars_frozen
Definition: shared_context.h:171
bool hasSolver(uint32 id) const
Returns whether this object has a solver associcated with the given id.
Definition: shared_context.h:481
uint32 complexity
Definition: shared_context.h:175
void setVarEq(Var v, bool b)
Definition: shared_context.h:576
base_type::const_right_iterator const_right_iterator
Definition: left_right_sequence.h:258
Definition: solver_strategies.h:371
Literal negLit(Var v)
Creates the negative literal of variable v.
Definition: literal.h:166
bool isShared() const
Returns whether more than one solver is actively working on the problem.
Definition: shared_context.h:478
bool project() const
Returns true if var is a projection variable.
Definition: shared_context.h:209
static bool inSet(uint64 s, uint32 id)
Definition: shared_context.h:369
uint8 rep
Definition: shared_context.h:224
bool propagate(Solver &s, Literal p) const
Propagates consequences of p following from binary and ternary clauses.
Definition: shared_context.cpp:298
Base class for (boolean) constraints to be used in a Solver.
Definition: constraint.h:85
bool allowImplicit(ConstraintType t) const
Returns whether short constraints of type t can be stored in the short implication graph...
Definition: shared_context.h:465
Parameters for (optional) Sat-preprocessing.
Definition: solver_strategies.h:335
uint32 constraints_binary
Definition: shared_context.h:173
void report(const Event &ev) const
Definition: shared_context.h:669
void setMarked(bool b)
Definition: shared_context.h:66
void init(BoundVec const &bounds, IntervalSet< Value > &set)
Definition: statements.cc:332
const ProblemStats & StatsRef
Definition: shared_context.h:403
uint32 numConstraints() const
Definition: shared_context.h:177
Stores static information about a variable.
Definition: shared_context.h:191
bool inQ() const
Definition: shared_context.h:60
PodVector< Var >::type VarVec
Definition: literal.h:192
bool sign() const
Returns the sign of the literal.
Definition: literal.h:123
tuple s
Definition: server.py:45
bk_lib::pod_vector< ImplicationList > type
Definition: pod_vector.h:37
A struct for aggregating statistics maintained in a solver object.
Definition: solver_types.h:287
bool preprocess(SharedContext &ctx, SatPreParams &opts)
Runs the preprocessor on all clauses that were previously added.
Definition: shared_context.cpp:357
void removeTrue(const Solver &s, Literal p)
Removes p and its implications.
Definition: shared_context.cpp:228
Definition: constraint.h:52
virtual bool initPreprocess(SatPreParams &opts)=0
auto f
Definition: statements.cc:122
uint32 constraints_ternary
Definition: shared_context.h:174
uint32 Var
A variable is currently nothing more but an integer in the range [0..varMax).
Definition: literal.h:42
uint32 numLearnt() const
Definition: shared_context.h:266
Definition: misc_types.h:83
void setNant(Var v, bool b)
Marks/unmarks v as contained in a negative loop or head of a choice rule.
Definition: shared_context.h:571
uint32 numTernary() const
Definition: shared_context.h:265
Aggregates information to be shared between solver objects.
Definition: shared_context.h:396
uint32 clRemoved
Definition: shared_context.h:116
void destroyClause(uint32 clId)
Definition: shared_context.h:134
bool report(const Solver &s, const Model &m) const
Definition: shared_context.h:670
LitVec::size_type size_type
Definition: shared_context.h:405
void setPreserveModels(bool b=true)
If b is true, sets preprocessing mode to model-preserving operations only.
Definition: shared_context.h:442
A struct for aggregating basic problem statistics.
Definition: shared_context.h:167
Type
Definition: constraint.h:50
void setEventHandler(EventHandler *r)
Enables event reporting via the given event handler.
Definition: shared_context.h:421
Definition: literal.h:55
bool has(uint32 f) const
Definition: shared_context.h:220
Stats()
Definition: shared_context.h:115
double operator[](const char *key) const
Definition: shared_context.cpp:28
ShortImplicationsGraph ImpGraph
Definition: shared_context.h:406
uint32 numBinary() const
Definition: shared_context.h:264
ImpGraphRef shortImplications() const
Definition: shared_context.h:667
uint32 numLearntShort() const
Returns the number of learnt short implications.
Definition: shared_context.h:666
PodVector< Literal >::type LitVec
Definition: literal.h:193
bool validVar(Var var) const
Returns true if var represents a valid variable in this problem.
Definition: shared_context.h:504
void resize(uint32 nodes)
Makes room for nodes number of nodes.
Definition: shared_context.cpp:163
Mode
Definition: solver_strategies.h:336
bool reverseArc(const Solver &s, Literal p, uint32 maxLev, Antecedent &out) const
Checks whether there is a reverse arc implying p and if so returns it in out.
Definition: shared_context.cpp:299
static uint64 abstractLit(Literal p)
Definition: shared_context.h:57
void resizeVars(uint32 maxVar)
Sets the range of problem variables to [1, maxVar)
Definition: shared_context.h:554
InitMode
Definition: shared_context.h:410
Definition: shared_context.h:198
bool marked(Literal p) const
Definition: shared_context.h:509
void detach(uint32 id, bool reset=false)
Detaches the solver with the given id from this object.
Definition: shared_context.h:644
uint32 litsRemoved
Definition: shared_context.h:118
const Literal & operator[](uint32 x) const
Definition: shared_context.h:59
A clause class optimized for preprocessing.
Definition: shared_context.h:54
SatPrePtr satPrepro
Definition: shared_context.h:448
bool preferredSign() const
Returns the preferred sign of this variable w.r.t its type.
Definition: shared_context.h:217
EventHandler * LogPtr
Definition: shared_context.h:408
Base class for distributing learnt knowledge between solvers.
Definition: shared_context.h:352
Definition: shared_context.h:193
uint32 numEliminatedVars() const
Returns the number of eliminated vars.
Definition: shared_context.h:498
Clause * elimTop_
Definition: shared_context.h:145
bool add(ImpType t, bool learnt, const Literal *lits)
Adds the given constraint to the implication graph.
Definition: shared_context.cpp:178
Stores two sequences in one contiguous memory block.
Definition: left_right_sequence.h:245
void setClause(uint32 clId, const LitVec &cl)
Definition: shared_context.h:131
Stores assignment related information.
Definition: solver_types.h:653
StatsRef stats() const
Definition: shared_context.h:521
Definition: solver_strategies.h:366
void reset()
Definition: shared_context.h:176
Literal stepLiteral() const
Definition: shared_context.h:510
virtual SatPreprocessor * clone()=0
Creates a clone of this preprocessor.
SingleOwnerPtr< Distributor > DistrPtr
Definition: shared_context.h:402
bool isCandidate(uint32 size, uint32 lbd, uint32 type) const
Definition: shared_context.h:372
void eliminateClause(uint32 id)
Definition: shared_context.h:139
VarInfo()
Definition: shared_context.h:202
bool attach(uint32 id)
Attaches the solver with the given id to this object.
Definition: shared_context.h:632
uint32 clAdded
Definition: shared_context.h:117
static uint8 flag(FLAG x)
Definition: shared_context.h:223
void discardClauses(bool discardEliminated)
Definition: shared_context.cpp:314
uint32 numVars() const
Returns the number of problem variables.
Definition: shared_context.h:496
tuple b
Definition: pyclingo.py:47
Symbol table that maps external ids to internal literals.
Definition: literal.h:249
base_type::const_left_iterator const_left_iterator
Definition: left_right_sequence.h:256
~ShortImplicationsGraph()
Definition: shared_context.cpp:160
uint32 vars
Definition: shared_context.h:169
SymbolsRef symbolTable() const
Definition: shared_context.h:522
Definition: atomic.h:33
uint32 numTernary() const
Returns the number of ternary constraints.
Definition: shared_context.h:516
Definition: shared_context.h:200
void setWinner(uint32 sId)
Definition: shared_context.h:650
SatPreParams Options
Definition: shared_context.h:120
uint64 abstr
Definition: shared_context.h:75
Definition: shared_context.h:199
Definition: shared_context.h:354
A class for efficiently storing and propagating binary and ternary clauses.
Definition: shared_context.h:228
void setInDisj(Var v, bool b)
Marks/unmarks v as contained in a non-hcf disjunction.
Definition: shared_context.h:573
void set(FLAG f)
Definition: shared_context.h:221
static const char * keys(const char *=0)
Definition: shared_context.cpp:40
void destroy()
Definition: shared_context.cpp:472
bool propagateBin(Assignment &out, Literal p, uint32 dl) const
Propagates immediate consequences of p following from binary clauses only.
Definition: shared_context.cpp:300
LogPtr eventHandler() const
Returns the active event handler or 0 if none was set.
Definition: shared_context.h:454
Type
Definition: literal.h:55
void markShared(bool b)
Mark the instance as shared/unshared.
Definition: shared_context.h:241
Interface for configuring a SharedContext object and its associated solvers.
Definition: solver_strategies.h:389
const Clause * clause(uint32 clId) const
Definition: shared_context.h:128
Definition: literal.h:270
static uint64 mask(uint32 i)
Definition: shared_context.h:367
bool nant() const
Returns true if var is contained in a negative loop or head of a choice rule.
Definition: shared_context.h:207
SharedDependencyGraph SDG
Definition: shared_context.h:398
ShortImplicationsGraph()
Definition: shared_context.cpp:155
tuple p
Definition: server.py:49
void strengthen(Literal p)
Definition: shared_context.cpp:452
bool inDisj() const
Definition: shared_context.h:210
bool preserveModels() const
Definition: shared_context.h:459
ShareMode
How to handle physical sharing of (explicit) constraints.
Definition: solver_strategies.h:369
bool frozen() const
Returns whether the problem is currently frozen and therefore ready for being solved.
Definition: shared_context.h:476
void simplify(Solver &s)
Definition: shared_context.cpp:460
virtual ~SatPreprocessor()
Definition: shared_context.cpp:311
SymbolTable & SymbolsRef
Definition: shared_context.h:404
tuple c
Definition: visualize.py:132
FLAG
Definition: shared_context.h:192
uint32 constraints
Definition: shared_context.h:172
Base class for library events.
Definition: misc_types.h:37
uint64 & abstraction()
Definition: shared_context.h:67
Base class for preprocessors working on clauses only.
Definition: shared_context.h:51
int x
Definition: utility.cc:65
Clause * clause(uint32 clId)
Definition: shared_context.h:127
virtual void doCleanUp()=0
Gringo::IntervalSet< T >::const_iterator begin(Gringo::IntervalSet< T > const &x)
Definition: intervals.hh:311
bool physicalShare(ConstraintType t) const
Returns whether physical sharing is enabled for constraints of type t.
Definition: shared_context.h:461
Var_t::Type VarType
Definition: literal.h:63
virtual void doExtendModel(ValueVec &m, LitVec &open)=0
Clause * next
Definition: shared_context.h:76
void toggle(FLAG f)
Definition: shared_context.h:222
SatPreprocessor()
Definition: shared_context.h:84
Definition: pod_vector.h:36
void diff(const ProblemStats &o)
Definition: shared_context.h:178
void extendModel(ValueVec &m, LitVec &open)
Extends the model in m with values for any eliminated variables.
Definition: shared_context.cpp:433
void setInQ(bool b)
Definition: shared_context.h:65
uint32 numEdges(Literal p) const
Definition: shared_context.cpp:176
bool marked() const
Definition: shared_context.h:63
Definition: constraint.h:51
An array of literals that can be shared between threads.
Definition: clause.h:33
Value var
Definition: output.cc:70
ShortMode
How to handle short learnt clauses.
Definition: solver_strategies.h:364
uint32 size() const
Definition: shared_context.h:58
bool physicalShareProblem() const
Returns whether pyhiscal sharing of problem constraints is enabled.
Definition: shared_context.h:463
Clause * linkRemoved(Clause *next)
Definition: shared_context.h:68
void freezeSeen()
Definition: shared_context.cpp:348
Definition: shared_context.h:232
bool seedSolvers() const
Returns whether this object seeds the RNG of new solvers.
Definition: shared_context.h:456
bool addClause(const LitVec &cl)
Adds a clause to the preprocessor.
Definition: shared_context.h:100
DistrPtr distributor
Definition: shared_context.h:647
Configuration * ConfigPtr
Definition: shared_context.h:401
uint32 numUnary() const
Returns the number of unary constraints.
Definition: shared_context.h:518
Definition: solver_strategies.h:338
Literal & operator[](uint32 x)
Definition: shared_context.h:64
Definition: shared_context.h:195
A literal is a variable or its negation.
Definition: literal.h:80
Solver * solver(uint32 id) const
Returns the solver with the given id.
Definition: shared_context.h:485
(Positive) Body-Atom-Dependency Graph.
Definition: dependency_graph.h:58
bool has(FLAG f) const
Definition: shared_context.h:219
uint32 concurrency() const
Returns the number of solvers that can share this object.
Definition: shared_context.h:458
void unmark(Var v)
Definition: shared_context.h:578
LparseOutputter & out
Definition: output.cc:685
bool frozen() const
Returns true if var is excluded from variable elimination.
Definition: shared_context.h:212
uint64 abstraction() const
Definition: shared_context.h:61
virtual bool doPreprocess()=0
Definition: shared_context.h:232
static uint32 initSet(uint32 sz)
Definition: shared_context.h:368
Clause * next() const
Definition: shared_context.h:62
clasp's Solver class.
Definition: solver.h:82
int end
Definition: literals.cc:62
Policy(uint32 a_sz=0, uint32 a_lbd=0, uint32 a_type=0)
Definition: shared_context.h:362