Skip to content

Fix #447: [Model] BoyceCoddNormalFormViolation#685

Open
GiggleLiu wants to merge 4 commits intomainfrom
issue-447-boycecnoddnormalformviolation
Open

Fix #447: [Model] BoyceCoddNormalFormViolation#685
GiggleLiu wants to merge 4 commits intomainfrom
issue-447-boycecnoddnormalformviolation

Conversation

@GiggleLiu
Copy link
Contributor

Summary

Add the BoyceCoddNormalFormViolation satisfaction problem model (Garey & Johnson A4 SR29). Given attributes, functional dependencies, and a target subset, determines whether the subset violates Boyce-Codd Normal Form.

Fixes #447

@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.06%. Comparing base (dfcc313) to head (ead280f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #685      +/-   ##
==========================================
+ Coverage   97.04%   97.06%   +0.01%     
==========================================
  Files         284      286       +2     
  Lines       38037    38259     +222     
==========================================
+ Hits        36914    37135     +221     
- Misses       1123     1124       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add the Boyce-Codd Normal Form Violation satisfaction problem model
(Garey & Johnson A4 SR29). Given attributes, functional dependencies,
and a target subset, determines whether a BCNF violation exists.

- Model: src/models/misc/boyce_codd_normal_form_violation.rs
- Tests: 20 unit tests covering evaluation, solver, serialization, edge cases
- CLI: create support with --n, --sets (lhs:rhs format), --target
- Paper: problem-def entry in docs/paper/reductions.typ
- Example-db: canonical example with violation witness X={2}
@GiggleLiu
Copy link
Contributor Author

Implementation Summary

Changes

  • src/models/misc/boyce_codd_normal_form_violation.rs — New satisfaction problem model with struct, constructor validation, closure computation, evaluate(), declare_variants!
  • src/unit_tests/models/misc/boyce_codd_normal_form_violation.rs — 20 unit tests: creation, evaluation (violation/non-violation/cyclic-keys/multi-step/out-of-target FDs), solver, serialization, constructor panics, normalization
  • src/models/misc/mod.rs — Module registration
  • problemreductions-cli/src/commands/create.rs — CLI create support with --n, --sets (FD format: lhs:rhs;...), --target
  • docs/paper/reductions.typ — Display name + problem-def entry
  • src/example_db/fixtures/examples.json — Regenerated with canonical BCNF example

Deviations from Plan

  • None

Open Questions

  • None

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new satisfaction problem model for Boyce–Codd Normal Form Violation (G&J A4 SR29) and wires it into the library, CLI instance creation, example database fixtures, and the reductions paper.

Changes:

  • Introduces BoyceCoddNormalFormViolation model with schema registration, variant declaration, and example-db spec.
  • Adds comprehensive unit tests covering evaluation behavior, validation, solver integration, and serialization.
  • Integrates the model into the CLI pred create flow and the curated example fixtures/docs.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/models/misc/boyce_codd_normal_form_violation.rs New model implementation + schema registration + variants + example-db spec + test module hook
src/models/misc/mod.rs Exposes the new model and includes its canonical example spec
problemreductions-cli/src/commands/create.rs Adds CLI construction/parsing for BoyceCoddNormalFormViolation
src/unit_tests/models/misc/boyce_codd_normal_form_violation.rs Unit tests for correctness, validation, solver behavior, and serde roundtrip
src/example_db/fixtures/examples.json Adds canonical model example fixture entry (samples + satisfying solutions)
docs/paper/reductions.typ Adds name mapping and formal problem definition to the paper

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

#problem-def("BoyceCoddNormalFormViolation")[
*Instance:* A set $A$ of attribute names, a collection $F$ of functional dependencies on $A$, and a subset $A' subset.eq A$.

*Question:* Is there a subset $X subset.eq A'$ and two attributes $y, z in A' without X$ such that $y in X^+$ but $z in.not X^+$, where $X^+$ is the closure of $X$ under $F$?
Comment on lines 26 to +29
mod subset_sum;

pub use bin_packing::BinPacking;
pub use boyce_codd_normal_form_violation::BoyceCoddNormalFormViolation;
Comment on lines +928 to +946
let fds: Vec<(Vec<usize>, Vec<usize>)> = sets_str
.split(';')
.map(|fd_str| {
let parts: Vec<&str> = fd_str.split(':').collect();
anyhow::ensure!(
parts.len() == 2,
"Each FD must be lhs:rhs, got '{}'",
fd_str
);
let lhs: Vec<usize> = util::parse_comma_list(parts[0])?;
let rhs: Vec<usize> = util::parse_comma_list(parts[1])?;
Ok((lhs, rhs))
})
.collect::<Result<_>>()?;
let target: Vec<usize> = util::parse_comma_list(target_str)?;
(
ser(BoyceCoddNormalFormViolation::new(n, fds, target))?,
resolved_variant.clone(),
)
Comment on lines +72 to +83
/// Create a new Boyce-Codd Normal Form Violation instance.
///
/// # Panics
///
/// Panics if any attribute index in `functional_deps` or `target_subset` is
/// out of range (≥ `num_attributes`), if `target_subset` is empty, or if any
/// functional dependency has an empty LHS.
pub fn new(
num_attributes: usize,
functional_deps: Vec<(Vec<usize>, Vec<usize>)>,
target_subset: Vec<usize>,
) -> Self {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Model] BoyceCoddNormalFormViolation

2 participants