24#include "catalog/pg_type.h"
25#include "utils/uuid.h"
26#include "executor/spi.h"
68 (
pg_uuid_t token,
const string &method,
const string &args)
80 void (*prev_sigint_handler)(int);
86 if(method==
"independent") {
89 }
else if(method==
"") {
103 if(method==
"monte-carlo") {
107 samples = stoi(args);
108 }
catch(
const std::invalid_argument &e) {
112 provsql_error(
"Invalid number of samples: '%s'", args.c_str());
115 }
else if(method==
"possible-worlds") {
117 provsql_warning(
"Argument '%s' ignored for method possible-worlds", args.c_str());
120 }
else if(method==
"weightmc") {
122 }
else if(method==
"compilation" || method==
"tree-decomposition" || method==
"") {
123 auto dd = c.
makeDD(gate, method, args);
126 provsql_error(
"Wrong method '%s' for probability evaluation", method.c_str());
134 signal (SIGINT, prev_sigint_handler);
142 PG_RETURN_FLOAT8(result);
149 Datum token = PG_GETARG_DATUM(0);
156 if(!PG_ARGISNULL(1)) {
157 text *t = PG_GETARG_TEXT_P(1);
158 method = string(VARDATA(t),VARSIZE(t)-VARHDRSZ);
161 if(!PG_ARGISNULL(2)) {
162 text *t = PG_GETARG_TEXT_P(2);
163 args = string(VARDATA(t),VARSIZE(t)-VARHDRSZ);
167 }
catch(
const std::exception &e) {
Boolean-expression (lineage formula) semiring.
Boolean provenance circuit with support for knowledge compilation.
BooleanCircuit getBooleanCircuit(pg_uuid_t token, gate_t &gate)
Build a BooleanCircuit from the mmap store rooted at token.
Build in-memory circuits from the mmap-backed persistent store.
gate_t
Strongly-typed gate identifier.
Semiring-agnostic in-memory provenance circuit.
Fix gettext macro conflicts between PostgreSQL and the C++ STL.
Boolean circuit for provenance formula evaluation.
double WeightMC(gate_t g, std::string opt) const
Compute the probability using the weightmc model counter.
double possibleWorlds(gate_t g) const
Compute the probability by exact enumeration of all possible worlds.
dDNNF makeDD(gate_t g, const std::string &method, const std::string &args) const
Dispatch to the appropriate d-DNNF construction method.
double monteCarlo(gate_t g, unsigned samples) const
Estimate the probability via Monte Carlo sampling.
void rewriteMultivaluedGates()
Rewrite all MULVAR/MULIN gate clusters into standard AND/OR/NOT circuits.
double independentEvaluation(gate_t g) const
Compute the probability exactly when inputs are independent.
Exception type thrown by circuit operations on invalid input.
virtual char const * what() const noexcept
Return the error message as a C-string.
double probabilityEvaluation() const
Compute the exact probability of the d-DNNF being true.
Constructs a d-DNNF from a Boolean circuit and its tree decomposition.
Provenance evaluation helpers for HAVING-clause circuits.
Datum probability_evaluate(PG_FUNCTION_ARGS)
PostgreSQL-callable wrapper for probability_evaluate().
static void provsql_sigint_handler(int)
SIGINT handler that sets the global interrupted flag.
static Datum probability_evaluate_internal(pg_uuid_t token, const string &method, const string &args)
Core implementation of probability evaluation for a circuit token.
bool provsql_interrupted
Global variable that becomes true if this particular backend received an interrupt signal.
#define provsql_error(fmt,...)
Report a fatal ProvSQL error and abort the current transaction.
#define provsql_warning(fmt,...)
Emit a ProvSQL warning message (execution continues).
Background worker and IPC primitives for mmap-backed circuit storage.
Shared-memory segment and inter-process pipe management.
Core types, constants, and utilities shared across ProvSQL.
C++ utility functions for UUID manipulation.