Skip to content

Commit c1681c6

Browse files
RenatoGehkhosravipasha
authored andcommitted
Add test case for smooth edge case
1 parent 7709b06 commit c1681c6

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

test/transformations_test.jl

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ end
2020
vtr = zoo_vtree("random.vtree")
2121
slc = smooth(sdd)
2222
plc = propagate_constants(sdd, remove_unary=true)
23-
structplc = compile(StructLogicCircuit, vtr, plc)
23+
structplc = compile(StructLogicCircuit, vtr, plc)
2424
sstructplc = smooth(structplc)
2525

2626
@test !issmooth(sdd)
@@ -29,6 +29,35 @@ end
2929
@test respects_vtree(sstructplc, vtr)
3030

3131
@test prob_equiv(slc, sstructplc, 3)
32+
33+
# Case when not all literals appear in the LC. See:
34+
# https://github.com/Juice-jl/ProbabilisticCircuits.jl/issues/80
35+
cnf = IOBuffer(b"""c Encodes the following: ϕ = (1 ∨ ¬2) ∧ (3 ∨ ¬4) ∧ (1 ∨ ¬4)
36+
p cnf 4 3
37+
1 -2 0
38+
3 -4 0
39+
1 -4 0
40+
""")
41+
# Try out with different vtrees.
42+
for i 1:5
43+
sdd = compile(SddMgr(Vtree(4, :random)), read(cnf, LogicCircuit, FnfFormat()))
44+
lc = LogicCircuit(sdd)
45+
slc = smooth(lc)
46+
plc = propagate_constants(lc, remove_unary=true)
47+
structplc = compile(StructLogicCircuit, sdd.vtree, plc)
48+
sstructplc = smooth(structplc)
49+
50+
@test !issmooth(sdd)
51+
@test !issmooth(lc)
52+
@test issmooth(slc)
53+
@test issmooth(sstructplc)
54+
@test respects_vtree(sstructplc, sdd.vtree)
55+
56+
@test prob_equiv(slc, sstructplc, 3)
57+
58+
# Reset stream pointer
59+
seekstart(cnf)
60+
end
3261
end
3362

3463
@testset "Forget test" begin
@@ -78,15 +107,15 @@ end
78107

79108
@testset "conjoin test" begin
80109
c1 = zoo_sdd_random
81-
110+
82111
lit = Lit(num_variables(c1) + 1)
83112
@test c1 === conjoin(c1, lit)
84113

85114
lit1 = Lit(1)
86115
c2 = conjoin(c1, lit1)
87116
dict = canonical_literals(c2)
88117
@test haskey(dict, lit1)
89-
@test !haskey(dict, -lit1)
118+
@test !haskey(dict, -lit1)
90119
c3 = conjoin(c2, -lit1)
91120
@test isfalse(c3)
92121
c4 = conjoin(c2, lit1)
@@ -235,11 +264,11 @@ end
235264
c = compile(PlainLogicCircuit, Lit(3))
236265
d = compile(PlainLogicCircuit, Lit(4))
237266
e = compile(PlainLogicCircuit, -Lit(4))
238-
267+
239268
f = disjoin(conjoin(a, b), conjoin(c, d))
240269
candidates, variable_scope = split_candidates(f)
241270
@test length(candidates) == 0
242-
271+
243272
g = disjoin(conjoin(disjoin(conjoin(d, b), conjoin(e, b)), a))
244273
candidates, variable_scope = split_candidates(g)
245274
@test length(candidates) == 1
@@ -252,13 +281,13 @@ end
252281
b = compile(PlainLogicCircuit, Lit(2))
253282
c = compile(PlainLogicCircuit, Lit(3))
254283
d = compile(PlainLogicCircuit, Lit(4))
255-
284+
256285
e = conjoin(a, b, c)
257286
circuit = standardize_circuit(e)
258287
@test circuit.children[1].literal == Lit(1)
259288
@test circuit.children[2].children[1].children[1].literal == Lit(2)
260289
@test circuit.children[2].children[1].children[2].literal == Lit(3)
261-
290+
262291
e = disjoin(a, b)
263292
f = disjoin(c, d)
264293
g = disjoin(e, f)

0 commit comments

Comments
 (0)