Esempio n. 1
0
// We'll use a modified MOMS rule that only looks at binary clauses
func moms(db *db.DB, a *assignment.Assignment) (l *cnf.Lit) {
	var (
		counts   = make([]int, a.Guess().Len())
		eCount   int
		vals     [2]uint
		g        = a.Guess()
		biggest  = 0
		biggestI = -1
	)

	// Count up the total lits in binary clauses
	for e := db.Learned; e != nil; e = e.Next {
		eCount = 0
		for _, l := range e.Clause.Lits {
			if v, _ := g.Get(l.Val); v == guess.Unassigned {
				eCount++
				if eCount > 2 {
					break
				}
				vals[eCount-1] = l.Val
			}
		}
		if eCount <= 2 {
			for i := 0; i < eCount; i++ {
				counts[vals[i]-1]++
			}
		}
	}

	// Search for the biggest
	for i, v := range counts {
		if v > biggest {
			biggest = v
			biggestI = i
		}
	}

	if biggestI == -1 {
		return random(db, a)
	} else {
		return &cnf.Lit{uint(biggestI + 1), byte((rand.Int() % 2) + 1)}
	}
	panic("MOMS is broken")
}
Esempio n. 2
0
func DpllTimeout(cdb *db.DB, a *assignment.Assignment, b *Brancher, m *db.Manager, adapt *Adapter, timeout <-chan time.Time) *guess.Guess {

	nVar := a.Guess().Len()
	aStack := make([]dpllStackNode, nVar)
	top := -1

	for {

		top++
		aStack[top].l = b.Decide(cdb, a)
		aStack[top].Flipped = false
		a.PushAssign(aStack[top].l.Val, aStack[top].l.Pol)

		for {
			select {
			case <-timeout:
				return nil
			default:
			}

			status := cdb.Bcp(a.Guess(), *aStack[top].l, m)
			if status == db.Conflict {
				// BackTrack
				for aStack[top].Flipped == true {
					top--
					a.PopAssign()
				}
				if top < 0 {
					return nil
				}
				// Flip the assignment
				a.PopAssign()
				aStack[top].l.Flip()
				aStack[top].Flipped = true
				a.PushAssign(aStack[top].l.Val, aStack[top].l.Pol)
				// Reconfigure if neccessary
				if adapt != nil {
					adapt.Reconfigure(cdb, b, m)
				}

			} else if status == db.Sat {
				return a.Guess()
			} else {
				break
			}
		}
	}
	panic("Dpll is broken")
}
Esempio n. 3
0
func vsids(db *db.DB, a *assignment.Assignment) (l *cnf.Lit) {
	l = db.Counts.Max(a.Guess())
	return
}