Fix #449: [Model] ConjunctiveBooleanQuery#689
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #689 +/- ##
==========================================
+ Coverage 97.34% 97.36% +0.01%
==========================================
Files 331 333 +2
Lines 42556 42760 +204
==========================================
+ Hits 41428 41634 +206
+ Misses 1128 1126 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Implementation SummaryChanges
Deviations from Plan
Open Questions
|
There was a problem hiding this comment.
Pull request overview
Adds a new Conjunctive Boolean Query (CBQ) satisfaction problem model to the misc model set, including CLI instance construction support, example-db fixtures, tests, and paper documentation updates.
Changes:
- Introduces
ConjunctiveBooleanQuerymodel (+ schema registration, variants, example-db spec, and tests). - Extends
pred createto construct CBQ instances from--domain-size,--relations, and--conjuncts-spec. - Updates example-db fixtures and the paper (definition section + references) to include CBQ.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/models/misc/conjunctive_boolean_query.rs | New CBQ model type, schema entry, evaluation logic, variants, and example-db builder. |
| src/models/misc/mod.rs | Wires CBQ module + re-exports (including CbqRelation, QueryArg) and example-db specs. |
| src/models/mod.rs | Re-exports CBQ types at the top-level models module. |
| src/lib.rs | Exposes CBQ types in the public prelude. |
| src/unit_tests/models/misc/conjunctive_boolean_query.rs | Adds unit tests for evaluation, brute-force solving, and serialization. |
| problemreductions-cli/src/cli.rs | Adds pred create flags for CBQ. |
| problemreductions-cli/src/commands/create.rs | Implements CBQ parsing/creation in the CLI. |
| src/example_db/fixtures/examples.json | Adds a canonical CBQ model fixture entry (and includes an unrelated witness tweak). |
| docs/paper/reductions.typ | Adds CBQ definition section with a worked example loaded from fixtures. |
| docs/paper/references.bib | Adds CBQ-related references (Chandra & Merlin, Gottlob et al., Kolaitis & Vardi). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
docs/paper/references.bib
Outdated
| @article{chandra1977, | ||
| author = {Ashok K. Chandra and Philip M. Merlin}, | ||
| title = {Optimal Implementation of Conjunctive Queries in Relational Data Bases}, | ||
| journal = {Proceedings of the 9th Annual ACM Symposium on Theory of Computing (STOC)}, | ||
| pages = {77--90}, | ||
| year = {1977}, | ||
| doi = {10.1145/800105.803397} | ||
| } | ||
|
|
||
| @article{gottlob2002, | ||
| author = {Georg Gottlob and Nicola Leone and Francesco Scarcello}, | ||
| title = {Hypertree Decompositions and Tractable Queries}, | ||
| journal = {Journal of Computer and System Sciences}, | ||
| volume = {64}, | ||
| number = {3}, | ||
| pages = {579--627}, | ||
| year = {2002}, | ||
| doi = {10.1006/jcss.2001.1809} | ||
| } | ||
|
|
||
| @incollection{kolaitis1998, | ||
| author = {Phokion G. Kolaitis and Moshe Y. Vardi}, | ||
| title = {Conjunctive-Query Containment and Constraint Satisfaction}, | ||
| booktitle = {Proceedings of the 17th ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems (PODS)}, | ||
| pages = {205--213}, | ||
| year = {1998}, | ||
| doi = {10.1145/275487.275511} | ||
| } |
| // Parse relations: "arity:t1,t2|t3,t4;arity:t5,t6,t7|t8,t9,t10" | ||
| let relations: Vec<CbqRelation> = relations_str | ||
| .split(';') | ||
| .map(|rel_str| { | ||
| let rel_str = rel_str.trim(); | ||
| let (arity_str, tuples_str) = rel_str.split_once(':').ok_or_else(|| { | ||
| anyhow::anyhow!( | ||
| "Invalid relation format: expected 'arity:tuples', got '{rel_str}'" | ||
| ) | ||
| })?; | ||
| let arity: usize = arity_str | ||
| .trim() | ||
| .parse() | ||
| .map_err(|e| anyhow::anyhow!("Invalid arity '{arity_str}': {e}"))?; | ||
| let tuples: Vec<Vec<usize>> = tuples_str | ||
| .split('|') | ||
| .map(|t| { | ||
| t.trim() | ||
| .split(',') | ||
| .map(|v| { | ||
| v.trim() | ||
| .parse::<usize>() | ||
| .map_err(|e| anyhow::anyhow!("Invalid tuple value: {e}")) | ||
| }) | ||
| .collect::<Result<Vec<_>>>() | ||
| }) | ||
| .collect::<Result<Vec<_>>>()?; | ||
| Ok(CbqRelation { arity, tuples }) | ||
| }) | ||
| .collect::<Result<Vec<_>>>()?; | ||
| // Parse conjuncts: "rel_idx:arg1,arg2;rel_idx:arg1,arg2,arg3" | ||
| let mut num_vars_inferred: usize = 0; | ||
| let conjuncts: Vec<(usize, Vec<QueryArg>)> = conjuncts_str | ||
| .split(';') | ||
| .map(|conj_str| { | ||
| let conj_str = conj_str.trim(); | ||
| let (idx_str, args_str) = conj_str.split_once(':').ok_or_else(|| { | ||
| anyhow::anyhow!( | ||
| "Invalid conjunct format: expected 'rel_idx:args', got '{conj_str}'" | ||
| ) | ||
| })?; | ||
| let rel_idx: usize = idx_str.trim().parse().map_err(|e| { | ||
| anyhow::anyhow!("Invalid relation index '{idx_str}': {e}") | ||
| })?; | ||
| let query_args: Vec<QueryArg> = args_str | ||
| .split(',') | ||
| .map(|a| { | ||
| let a = a.trim(); | ||
| if let Some(rest) = a.strip_prefix('v') { | ||
| let v: usize = rest.parse().map_err(|e| { | ||
| anyhow::anyhow!("Invalid variable index '{rest}': {e}") | ||
| })?; | ||
| if v + 1 > num_vars_inferred { | ||
| num_vars_inferred = v + 1; | ||
| } | ||
| Ok(QueryArg::Variable(v)) | ||
| } else if let Some(rest) = a.strip_prefix('c') { | ||
| let c: usize = rest.parse().map_err(|e| { | ||
| anyhow::anyhow!("Invalid constant value '{rest}': {e}") | ||
| })?; | ||
| Ok(QueryArg::Constant(c)) | ||
| } else { | ||
| Err(anyhow::anyhow!( | ||
| "Invalid query arg '{a}': expected vN (variable) or cN (constant)" | ||
| )) | ||
| } | ||
| }) | ||
| .collect::<Result<Vec<_>>>()?; | ||
| Ok((rel_idx, query_args)) | ||
| }) | ||
| .collect::<Result<Vec<_>>>()?; | ||
| ( | ||
| ser(ConjunctiveBooleanQuery::new( | ||
| domain_size, | ||
| relations, | ||
| num_vars_inferred, | ||
| conjuncts, | ||
| ))?, |
| let tuples: Vec<Vec<usize>> = tuples_str | ||
| .split('|') | ||
| .map(|t| { | ||
| t.trim() | ||
| .split(',') | ||
| .map(|v| { | ||
| v.trim() | ||
| .parse::<usize>() | ||
| .map_err(|e| anyhow::anyhow!("Invalid tuple value: {e}")) | ||
| }) | ||
| .collect::<Result<Vec<_>>>() | ||
| }) | ||
| .collect::<Result<Vec<_>>>()?; |
| let tuple: Vec<usize> = args | ||
| .iter() | ||
| .map(|arg| match arg { | ||
| QueryArg::Variable(i) => config[*i], | ||
| QueryArg::Constant(c) => *c, | ||
| }) | ||
| .collect(); | ||
| self.relations[*rel_idx].tuples.contains(&tuple) |
Agentic Review ReportStructural Check
Build: Semantic Review:
Issue Compliance (#449): 10/10 checks passed — name, definition, type (satisfaction), schema, getters, complexity, and example all match. Whitelist Note: Deterministic whitelist check failed due to a minor unrelated change in Quality CheckDesign Principles:
HCI (CLI):
Test Quality: 9 test functions covering creation, positive/negative evaluation, boundary conditions (out-of-range, wrong-length), solver integration (satisfiable + unsatisfiable), serialization round-trip, and exhaustive verification via Issues Found:
Agentic Feature Tests
11 PASS, 2 FAIL, 1 WARNING Issues Found:
Generated by review-pipeline |
Resolve conflicts: keep ConjunctiveBooleanQuery alongside newly added models (RectilinearPictureCompression, StringToStringCorrection, etc.). Adapt ModelExampleSpec to the new API (instance/optimal_config/optimal_value fields instead of build closure). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Fix BibTeX entry types: chandra1977 @Article -> @inproceedings, kolaitis1998 @incollection -> @inproceedings - Support empty relations in CLI parsing (e.g., "2:" produces empty relation) - Pre-validate CLI input before calling ConjunctiveBooleanQuery::new(): tuple arity, domain bounds, relation indices, conjunct arity, constant bounds — returns user-facing errors instead of panicking Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Resolve conflicts: keep ConjunctiveBooleanQuery alongside newly added PartiallyOrderedKnapsack model. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Final review notes:
All local checks pass ( |
zazabap
left a comment
There was a problem hiding this comment.
Final review passed. All agentic test failures (6c, 6d) fixed, BibTeX corrected, CLI validation hardened. LGTM.
Summary
Add the Conjunctive Boolean Query (CBQ) problem model — a classical NP-complete satisfaction problem from database theory (Garey & Johnson A4 SR31). Given a finite domain, relations, and an existentially quantified conjunctive query, determine whether the query is satisfiable.
Fixes #449