diff --git a/src/structured_prob_nodes.jl b/src/structured_prob_nodes.jl index 0cf8cc32..f20eb74d 100644 --- a/src/structured_prob_nodes.jl +++ b/src/structured_prob_nodes.jl @@ -135,6 +135,14 @@ function compile(::Type{<:StructProbCircuit}, vtree::Vtree, circuit::LogicCircui foldup_aggregate(circuit, f_con, f_lit, f_a, f_o, StructProbCircuit) end +function compile(::Type{<:StructProbCircuit}, sdd::Sdd)::StructProbCircuit + lc = LogicCircuit(sdd) + plc = propagate_constants(lc, remove_unary=true) + structplc = compile(StructLogicCircuit, vtree(sdd), plc) + sstructplc = smooth(structplc) + compile(StructProbCircuit, sstructplc) +end + function fully_factorized_circuit(::Type{<:ProbCircuit}, vtree::Vtree) ff_logic_circuit = fully_factorized_circuit(PlainStructLogicCircuit, vtree) compile(StructProbCircuit, vtree, ff_logic_circuit) diff --git a/test/structured_prob_nodes_tests.jl b/test/structured_prob_nodes_tests.jl index 3f49afe7..762a7a90 100644 --- a/test/structured_prob_nodes_tests.jl +++ b/test/structured_prob_nodes_tests.jl @@ -120,5 +120,26 @@ using DataFrames: DataFrame @test num_parameters_node(r1) == num_parameters_node(r) @test isempty(intersect(linearize(r1),linearize(r))) + # Convert tests + function apply_test_cnf(n_vars::Int, cnf_path::String) + for i in 1:10 + vtree = Vtree(n_vars, :random) + sdd = compile(SddMgr(vtree), zoo_cnf(cnf_path)) + @test num_variables(sdd) == n_vars + psdd = compile(StructProbCircuit, sdd) + @test num_variables(psdd) == n_vars + @test issmooth(psdd) + @test isdecomposable(psdd) + @test isdeterministic(psdd) + @test respects_vtree(psdd, vtree) + data = DataFrame(convert(BitMatrix, rand(Bool, 100, n_vars))) + @test all(sdd(data) .== (EVI(psdd, data) .!= -Inf)) + end + nothing + end + apply_test_cnf(17, "easy/C17_mince.cnf") + apply_test_cnf(14, "easy/majority_mince.cnf") + apply_test_cnf(21, "easy/b1_mince.cnf") + apply_test_cnf(20, "easy/cm152a_mince.cnf") +end -end \ No newline at end of file