16#if PG_VERSION_NUM >= 160000
19#include "catalog/pg_type.h"
20#include "utils/uuid.h"
35#include <unordered_map>
51 pg_uuid_t *token = DatumGetUUIDP(PG_GETARG_DATUM(0));
54 if(!PG_ARGISNULL(1)) {
55 text *t = PG_GETARG_TEXT_P(1);
56 compiler = string(VARDATA(t), VARSIZE(t)-VARHDRSZ);
67 std::unordered_map<std::string, int> uuid2var;
70 static_cast<int>(
static_cast<std::underlying_type<gate_t>::type
>(in)) + 1;
71 auto var_of_uuid = [&uuid2var](
const std::string &u) ->
int {
72 auto it = uuid2var.find(u);
73 return it == uuid2var.end() ? -1 : it->second;
84 dDNNF d = (compiler ==
"inversion-free")
87 string nnf = d.
toNNF(var_of_uuid);
89 text *result = (text *) palloc(VARHDRSZ + nnf.size());
90 SET_VARSIZE(result, VARHDRSZ + nnf.size());
91 memcpy((
void *) VARDATA(result), nnf.c_str(), nnf.size());
92 PG_RETURN_TEXT_P(result);
93 }
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.
Fix macro conflicts between PostgreSQL headers and the C++ STL/Boost.
Boolean circuit for provenance formula evaluation.
const std::set< gate_t > & getInputs() const
Return the set of input (IN) gate IDs.
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.
uuid getUUID(gate_t g) const
Return the UUID string associated with gate g.
A d-DNNF circuit supporting exact probabilistic and game-theoretic evaluation.
std::string toNNF(const std::function< int(const std::string &)> &var_of_uuid={}) const
Serialise the d-DNNF in the c2d / d4 ".nnf" text format.
Datum compile_to_ddnnf(PG_FUNCTION_ARGS)
PostgreSQL-callable entry point.
Decomposable Deterministic Negation Normal Form circuit.
#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.