Esempio n. 1
0
func (lc *LitCounts) Max(g *guess.Guess) *cnf.Lit {
	var (
		bestI int
		bestV int
	)

	bestV = -1
	for i, v := range lc.counts {
		if int(v) > bestV {
			if i < len(lc.counts)/2 { // negative polarity
				if p, _ := g.Get(uint(i + 1)); p == guess.Unassigned {
					bestV = int(v)
					bestI = i
				}
			} else { // positive polarity
				if p, _ := g.Get(uint(i - (len(lc.counts) / 2) + 1)); p == guess.Unassigned {
					bestV = int(v)
					bestI = i
				}
			}
		}
	}
	if bestV == -1 {
		return &cnf.Lit{0, 0}
	} else if bestI < len(lc.counts)/2 {
		return &cnf.Lit{uint(bestI + 1), guess.Neg}
	} else {
		return &cnf.Lit{uint(bestI + 1 - (len(lc.counts) / 2)), guess.Pos}
	}
	panic("LitCount.Max is horribly broken\n")
}
Esempio n. 2
0
// View db as a queue. From the first 15/16 newest clauses, delete anything with
// more than 42 literals. From the last 1/16, delete anything with more than 8.
// This is a simplification of Berkmin. We'd need to add the notion of clause
// activity in order to do it properly. We'd also need restarts.
// Call it a TODO
func berkmin(cdb *DB, g *guess.Guess, m *Manager) {
	var (
		beginning = (g.NAssigned() / 16) * 15
		count     = 0
		tmp       *Entry
	)
	for e := cdb.Learned; e != nil; e = e.Next {
		count++
		if count > beginning {
			if len(e.Clause.Lits) > 8 {
				tmp = e.Prev
				cdb.DelEntry(e)
				e = tmp
			}
		} else {
			if len(e.Clause.Lits) > 42 {
				tmp = e.Prev
				cdb.DelEntry(e)
				e = tmp
			}
		}
	}
}