Skip to content

Commit

Permalink
Fix the strashCode; add benchmark
Browse files Browse the repository at this point in the history
Thanks to Evan Cordell who spotted a problem with the strash code colliding.
Interesting, as it has a strong impact on the logic/c performance
(but none on solving).

See #17
  • Loading branch information
scott-cotton committed Aug 25, 2021
1 parent a1a5030 commit 3a1a4d9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion logic/c.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,5 +376,5 @@ func (p *C) grow() {
}

func strashCode(a, b z.Lit) uint32 {
return uint32((a << 13) * b)
return uint32(^(a << 13) * b)
}
31 changes: 31 additions & 0 deletions logic/c_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

"github.com/go-air/gini"
"github.com/go-air/gini/gen"
"github.com/go-air/gini/logic"
"github.com/go-air/gini/z"
)
Expand Down Expand Up @@ -149,3 +150,33 @@ func ExampleC_equiv() {
}
//Output: unsat
}

type cAdder struct {
c *logic.C
f z.Lit
buf []z.Lit
}

func (a *cAdder) Add(m z.Lit) {
if m != z.LitNull {
a.buf = append(a.buf, m)
return
}
clause := a.c.F
for _, m := range a.buf {
clause = a.c.Or(clause, m)
}
a.buf = a.buf[:0]
a.f = a.c.And(a.f, clause)
}

func BenchmarkStrash(b *testing.B) {

for i := 0; i < b.N; i++ {
circuit := logic.NewC()
ca := &cAdder{
c: circuit,
f: circuit.T}
gen.Rand3Cnf(ca, 100, 300)
}
}

0 comments on commit 3a1a4d9

Please # to comment.