update vendor

This commit is contained in:
Ettore Di Giacinto
2021-08-07 14:27:41 +02:00
parent 4d6cccb2fa
commit 77c4bf1fd1
8 changed files with 628 additions and 1 deletions

View File

@@ -127,6 +127,25 @@ func New(problem *Problem) *Solver {
return s
}
// newVar is used to indicate a new variable must be added to the solver.
// This can be used when new clauses are appended and these clauses contain vars that were unseen so far.
// If the var already existed, nothing will happen.
func (s *Solver) newVar(v Var) {
if cnfVar := int(v.Int()); cnfVar > s.nbVars {
// If the var already existed, do nothing
for i := s.nbVars; i < cnfVar; i++ {
s.model = append(s.model, 0)
s.activity = append(s.activity, 0.)
s.polarity = append(s.polarity, false)
s.reason = append(s.reason, nil)
s.trailBuf = append(s.trailBuf, 0)
}
s.varQueue = newQueue(s.activity)
s.addVarWatcherList(v)
s.nbVars = cnfVar
}
}
// sets initial activity for optimization variables, if any.
func (s *Solver) initOptimActivity() {
for i, lit := range s.minLits {
@@ -682,6 +701,7 @@ func (s *Solver) AppendClause(clause *Clause) {
i := 0
for i < clause.Len() {
lit := clause.Get(i)
s.newVar(lit.Var())
switch s.litStatus(lit) {
case Sat:
w := clause.Weight(i)

View File

@@ -71,6 +71,11 @@ func (v Var) Lit() Lit {
return Lit(v * 2)
}
// Int converts a Var to a CNF variable.
func (v Var) Int() int32 {
return int32(v + 1)
}
// SignedLit returns the Lit associated to v, negated if 'signed', positive else.
func (v Var) SignedLit(signed bool) Lit {
if signed {

View File

@@ -39,6 +39,16 @@ func (s *Solver) initWatcherList(clauses []*Clause) {
}
}
// Should be called when new vars are added to the problem (see Solver.newVar)
func (s *Solver) addVarWatcherList(v Var) {
cnfVar := int(v.Int())
for i := s.nbVars; i < cnfVar; i++ {
s.wl.wlistBin = append(s.wl.wlistBin, nil, nil)
s.wl.wlist = append(s.wl.wlist, nil, nil)
s.wl.wlistPb = append(s.wl.wlistPb, nil, nil)
}
}
// appendClause appends the clause without checking whether the clause is already satisfiable, unit, or unsatisfiable.
// To perform those checks, call s.AppendClause.
// clause is supposed to be a problem clause, not a learned one.