Skip to content

Commit

Permalink
feat: enable projected compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
uulm-janbaudisch committed Nov 22, 2024
1 parent 8be283f commit cfe855d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
13 changes: 11 additions & 2 deletions d4-oxide/examples/ddnnf-compiler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Parser;
use d4_oxide::compile_ddnnf;
use d4_oxide::{compile_ddnnf, compile_ddnnf_proj};

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
Expand All @@ -11,9 +11,18 @@ struct Args {
/// Output file to write d-DNNF to.
#[arg(short, long)]
output: String,

/// Whether to do projected compilation.
#[arg(short, long)]
projected: bool,
}

fn main() {
let args = Args::parse();
compile_ddnnf(args.input, args.output);

if args.projected {
compile_ddnnf_proj(args.input, args.output);
} else {
compile_ddnnf(args.input, args.output);
}
}
1 change: 1 addition & 0 deletions d4-oxide/include/Adapter.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "rust/cxx.h"

void compile_ddnnf(rust::String input, rust::String output);
void compile_ddnnf_proj(rust::String input, rust::String output);
18 changes: 14 additions & 4 deletions d4-oxide/src/Adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,25 @@
#include "src/config/ConfigConverter.hpp"
#include "src/methods/MethodManager.hpp"

void compile_ddnnf(rust::String input, rust::String output) {
void run(d4::Config config) {
std::ostringstream out;
d4::MethodManager *methodManager = d4::MethodManager::makeMethodManager(config, out);
methodManager->run(config);
delete methodManager;
}

void compile_ddnnf(rust::String input, rust::String output) {
d4::Config config = d4::Config::default_values();
config.method = "ddnnf-compiler";
config.input = std::string(input);
config.dump_ddnnf = std::string(output);
run(config);
}

d4::MethodManager *methodManager = d4::MethodManager::makeMethodManager(config, out);
methodManager->run(config);
delete methodManager;
void compile_ddnnf_proj(rust::String input, rust::String output) {
d4::Config config = d4::Config::default_values();
config.method = "proj-ddnnf-compiler";
config.input = std::string(input);
config.dump_ddnnf = std::string(output);
run(config);
}
8 changes: 8 additions & 0 deletions d4-oxide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod ffi {
include!("Adapter.h");

fn compile_ddnnf(input: String, output: String);
fn compile_ddnnf_proj(input: String, output: String);
}
}

Expand All @@ -13,3 +14,10 @@ mod ffi {
pub fn compile_ddnnf(input: String, output: String) {
ffi::compile_ddnnf(input, output);
}

/// Compiles the projected CNF from the input file into a d-DNNF and saves it in the output file.
///
/// This is equivalent to running `d4 -i input -m proj-ddnnf-compiler --dump-ddnnf output`.
pub fn compile_ddnnf_proj(input: String, output: String) {
ffi::compile_ddnnf_proj(input, output);
}

0 comments on commit cfe855d

Please sign in to comment.