17#if PG_VERSION_NUM >= 160000
20#include "catalog/pg_type.h"
21#include "utils/jsonb.h"
22#include "utils/fmgrprotos.h"
23#include "utils/uuid.h"
56 pg_uuid_t *token = DatumGetUUIDP(PG_GETARG_DATUM(0));
59 if(!PG_ARGISNULL(1)) {
60 text *t = PG_GETARG_TEXT_P(1);
61 compiler = string(VARDATA(t), VARSIZE(t)-VARHDRSZ);
74 auto t0 = std::chrono::steady_clock::now();
78 dDNNF d = (compiler ==
"inversion-free")
81 auto t1 = std::chrono::steady_clock::now();
83 std::chrono::duration<double, std::milli>(t1 - t0).count();
91 unsigned treewidth = 0;
100 std::ostringstream out;
102 out <<
"\"compiler\":\"";
103 for(
char ch : compiler)
104 out << (ch ==
'"' || ch ==
'\\' ? std::string(
"\\") + ch : std::string(1, ch));
106 out <<
",\"nodes\":" << s.
nodes;
107 out <<
",\"edges\":" << s.
edges;
111 out <<
",\"inputs\":" << s.
inputs;
112 out <<
",\"smooth\":" << (s.
smooth ?
"true" :
"false");
113 out <<
",\"depth\":" << s.
depth;
114 out <<
",\"treewidth\":";
115 if(has_tw) out << treewidth;
else out <<
"null";
116 out <<
",\"compile_ms\":" << compile_ms;
119 Datum json_datum = DirectFunctionCall1(
120 jsonb_in, CStringGetDatum(pstrdup(out.str().c_str())));
121 PG_RETURN_DATUM(json_datum);
122 }
catch(
const std::exception &e) {
Boolean provenance circuit with support for knowledge compilation.
BooleanCircuit getBooleanCircuit(GenericCircuit &gc, pg_uuid_t token, gate_t &gate, std::unordered_map< gate_t, gate_t > &gc_to_bc)
Build a BooleanCircuit from an already-loaded GenericCircuit.
Build in-memory circuits from the mmap-backed persistent store.
dDNNF buildInversionFreeDDNNF(pg_uuid_t token)
Compile a query certified inversion-free to its structured d-DNNF.
gate_t
Strongly-typed gate identifier.
Tree decomposition of a Boolean circuit for knowledge compilation.
Fix macro conflicts between PostgreSQL headers and the C++ STL/Boost.
Boolean circuit for provenance formula evaluation.
void rewriteMultivaluedGates()
Rewrite all MULVAR/MULIN gate clusters into standard AND/OR/NOT circuits.
dDNNF makeDDByName(gate_t g, const std::string &name) const
Build a dDNNF from a single compiler/route name.
Tree decomposition of a Boolean circuit's primal graph.
unsigned getTreewidth() const
Return the treewidth of this decomposition.
A d-DNNF circuit supporting exact probabilistic and game-theoretic evaluation.
Stats nodeStats() const
Compute structural statistics over the gates reachable from root.
Decomposable Deterministic Negation Normal Form circuit.
Datum ddnnf_stats(PG_FUNCTION_ARGS)
PostgreSQL-callable entry point.
#define provsql_error(fmt,...)
Report a fatal ProvSQL error and abort the current transaction.
Shared-memory segment and inter-process pipe management.
Core types, constants, and utilities shared across ProvSQL.
C++ utility functions for UUID manipulation.
Structural statistics of a compiled d-DNNF.
bool smooth
Every OR gate's children share their variable set.
int depth
Longest path (in gates) from the root.
std::size_t nodes
Total reachable gates.
std::size_t or_gates
OR (decision) gates.
std::size_t edges
Total wires among reachable gates.
std::size_t not_gates
NOT gates.
std::size_t inputs
IN (variable) leaves.
std::size_t and_gates
AND (decomposition) gates.