42 desc[
static_cast<std::underlying_type<gate_t>::type
>(id)] = d;
57 std::string result=
"digraph circuit{\n graph [rankdir=UD] ;\n";
66 result += std::to_string(i) +
" [label=";
70 result +=
"\"" +
desc[i] +
"\"";
88 result +=
"\"" +
desc[i] +
"\"";
91 result +=
"\"Π" +
desc[i] +
"\"";
98 result+=
",shape=\"double\"";
105 for(i=0; i<
wires.size(); ++i) {
107 std::unordered_map<gate_t, unsigned> number_gates;
108 for(
auto s:
wires[i]) {
109 if(number_gates.find(s)!=number_gates.end()) {
110 number_gates[s] = number_gates[s]+1;
117 for(
auto [s,n]: number_gates)
121 result += std::to_string(i)+
" -> "+
to_string(t);
123 result +=
" [label=\"R\"];\n";
125 result +=
" [label=\"L\"];\n";
129 result += std::to_string(i)+
" -> "+
to_string(s);
135 result +=
" [label=\"" + std::to_string(n) +
"\"];\n";
147 char cfilename[] =
"/tmp/provsqlXXXXXX";
148 fd = mkstemp(cfilename);
150 std::string filename=cfilename, outfilename=filename+
".out";
152 std::ofstream ofs(filename.c_str());
158 std::string cmdline=
"graph-easy --as=boxart --output="+outfilename+
" "+filename;
160 int retvalue = system(cmdline.c_str());
163 if(unlink(filename.c_str())) {
171 std::ifstream ifs(outfilename.c_str());
172 std::string str((std::istreambuf_iterator<char>(ifs)),
173 std::istreambuf_iterator<char>());
176 if(unlink(outfilename.c_str())) {
gate_t
Strongly-typed gate identifier.
std::string to_string(gate_t g)
Convert a gate_t to its decimal string representation.
Provenance circuit variant that renders to GraphViz DOT format.
DotGate
Gate types for a DOT visualisation circuit.
@ PROJECT
Projection gate.
@ OMINUS
Semiring monus (⊖), full.
@ OMINUSL
Monus, left child only.
@ OMINUSR
Monus, right child only.
@ DELTA
δ-semiring operator
@ IN
Input (variable) gate.
@ UNDETERMINED
Placeholder gate not yet assigned a type.
@ OTIMES
Semiring times (⊗)
Exception type thrown by circuit operations on invalid input.
std::vector< gate_t > & getWires(gate_t g)
Return a mutable reference to the child-wire list of gate g.
DotGate getGateType(gate_t g) const
Return the type of gate g.
virtual gate_t setGate(const uuid &u, gateType type)
Create or update the gate associated with UUID u.
std::vector< DotGate > gates
Gate type for each gate.
std::vector< std::vector< gate_t > > wires
Child wire lists for each gate.
virtual gate_t addGate()
Allocate a new gate with a default-initialised type.
virtual std::string toString(gate_t g) const override
Return a textual description of gate g for debugging.
gate_t addGate() override
Allocate a new gate with a default-initialised type.
std::set< gate_t > inputs
Input gate IDs (rendered as leaf nodes)
gate_t setGate(const uuid &u, DotGate type) override
Create or update the gate associated with UUID u.
std::string render() const
Render the entire circuit as a GraphViz DOT digraph string.
std::vector< std::string > desc
Per-gate label strings (indexed by gate ID)
int provsql_verbose
Verbosity level; controlled by the provsql.verbose_level GUC.
Core types, constants, and utilities shared across ProvSQL.