Skip to content

Fix #295: Add DirectedTwoCommodityIntegralFlow model#660

Merged
zazabap merged 7 commits intomainfrom
issue-295-directed-two-commodity-integral-flow
Mar 16, 2026
Merged

Fix #295: Add DirectedTwoCommodityIntegralFlow model#660
zazabap merged 7 commits intomainfrom
issue-295-directed-two-commodity-integral-flow

Conversation

@GiggleLiu
Copy link
Contributor

Summary

Add the Directed Two-Commodity Integral Flow problem model (Garey & Johnson A2 ND38) -- a satisfaction problem asking whether two integral flow functions can simultaneously satisfy joint arc capacity, flow conservation, and requirement constraints on a directed graph.

Fixes #295

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.00%. Comparing base (a4c3516) to head (2dfd9a2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #660      +/-   ##
==========================================
+ Coverage   96.97%   97.00%   +0.02%     
==========================================
  Files         277      279       +2     
  Lines       37161    37433     +272     
==========================================
+ Hits        36038    36311     +273     
+ Misses       1123     1122       -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.

GiggleLiu and others added 2 commits March 16, 2026 18:27
@GiggleLiu
Copy link
Contributor Author

Implementation Summary

Changes

  • src/models/graph/directed_two_commodity_integral_flow.rs — New satisfaction problem model: struct with 8 fields (graph, capacities, 4 terminals, 2 requirements), Problem impl with Metric = bool, SatisfactionProblem marker, declare_variants! with complexity (max_capacity + 1)^(2 * num_arcs), ProblemSchemaEntry registration, canonical model example
  • src/unit_tests/models/graph/directed_two_commodity_integral_flow.rs — 12 unit tests: creation, evaluation (satisfying/unsatisfying), capacity violation, conservation violation, solver YES/NO, serialization, paper example, higher capacity, accessors, problem name
  • src/models/graph/mod.rs — Module registration + canonical_model_example_specs
  • src/models/mod.rs — Re-export DirectedTwoCommodityIntegralFlow
  • src/lib.rs — Added to prelude
  • src/unit_tests/trait_consistency.rs — Added check_problem_trait entry
  • problemreductions-cli/src/cli.rs — 7 new CLI flags (capacities, source_1, sink_1, source_2, sink_2, requirement_1, requirement_2) + help table entry
  • problemreductions-cli/src/commands/create.rs — Match arm for pred create DirectedTwoCommodityIntegralFlow with usage hint + all_data_flags_empty update
  • docs/paper/reductions.typ — Display name + problem-def with formal definition, background, example with CeTZ directed graph diagram
  • docs/paper/references.bib — Added Even, Itai, Shamir (1976) reference
  • src/example_db/fixtures/examples.json — Regenerated (33 model examples)
  • docs/src/reductions/problem_schemas.json — Regenerated (42 schemas)
  • docs/src/reductions/reduction_graph.json — Regenerated

Deviations from Plan

  • Simplified flow conservation logic: removed redundant second conservation check. The problem definition exempts all four terminals from conservation for both commodities, so a single loop with a terminals.contains(&v) check suffices.

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 NP-complete graph satisfaction model, DirectedTwoCommodityIntegralFlow (G&J A2 ND38), and wires it into exports, CLI instance creation, examples, and documentation generation artifacts.

Changes:

  • Introduces DirectedTwoCommodityIntegralFlow model with feasibility evaluation, schema registration, variant declaration, and example-db fixture.
  • Adds unit tests covering creation, evaluation (yes/no), brute-force solving, and serialization.
  • Integrates the model into the CLI (pred create), library re-exports/prelude, and generated docs JSON / paper definition.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/models/graph/directed_two_commodity_integral_flow.rs New model implementation, schema registration, variant declaration, and example-db spec
src/models/graph/mod.rs Registers the new graph model module, re-export, and example spec wiring
src/models/mod.rs Re-exports the new model from the top-level models module
src/lib.rs Adds the model to the public prelude exports
src/unit_tests/models/graph/directed_two_commodity_integral_flow.rs New model unit tests (feasibility, solver behavior, serde)
src/unit_tests/trait_consistency.rs Adds trait consistency coverage for the new problem type
problemreductions-cli/src/cli.rs Adds CLI flags documentation and new CreateArgs fields for the model
problemreductions-cli/src/commands/create.rs Adds pred create DirectedTwoCommodityIntegralFlow construction + example string
src/example_db/fixtures/examples.json Adds an example-db fixture instance and solutions for the model
docs/src/reductions/problem_schemas.json Adds generated schema entry for the new model
docs/src/reductions/reduction_graph.json Adds generated reduction graph node entry (and index shifts)
docs/paper/reductions.typ Adds paper definition + illustrative figure for the new model
docs/paper/references.bib Adds Even–Itai–Shamir (1976) reference

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

net_flow_in -= config[offset + a] as i64;
}
}
if (net_flow_in as u64) < req {
ProblemSchemaEntry {
name: "DirectedTwoCommodityIntegralFlow",
display_name: "Directed Two-Commodity Integral Flow",
aliases: &[],
Comment on lines +211 to +225
for v in 0..n {
if terminals.contains(&v) {
continue;
}
let mut flow_in: i64 = 0;
let mut flow_out: i64 = 0;
for (a, &(u, w)) in arcs.iter().enumerate() {
if w == v {
flow_in += config[offset + a] as i64;
}
if u == v {
flow_out += config[offset + a] as i64;
}
}
if flow_in != flow_out {
@GiggleLiu
Copy link
Contributor Author

Review Pipeline Report

Check Result
Copilot comments 3 fixed
Issue/human comments 4 checked, 3 fixed
Structural review 18/18 passed
CI green
Agentic test passed
Needs human decision none
Board Review pool -> Under review -> Final review

Remaining issues for final review

  • None.

Generated by review-pipeline.

@GiggleLiu
Copy link
Contributor Author

Review Pipeline Report

Check Result
Copilot comments 3 fixed
Issue/human comments 4 checked, 3 fixed
Structural review 18/18 passed
CI green
Agentic test passed after follow-up fixes
Needs human decision none
Board Review pool -> Under review -> Final review

Remaining issues for final review

  • None.

Final follow-up fixes after the first pass:

  • added a brute-force hint to the default pred solve error for DirectedTwoCommodityIntegralFlow
  • added D2CIF examples and config-ordering guidance to README.md and docs/src/cli.md
  • corrected the make cli installation wording in the docs

Generated by review-pipeline.

zazabap and others added 2 commits March 16, 2026 14:31
Merge main into branch, resolving conflicts to include both
DirectedTwoCommodityIntegralFlow and main's new models
(SteinerTree, SetBasis, LengthBoundedDisjointPaths,
UndirectedTwoCommodityIntegralFlow). Regenerated JSON fixtures.
Added test for wrong-length config to cover the early return
in is_feasible(). Reverted README.md to main.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… requirements)

Both DirectedTwoCommodityIntegralFlow and UndirectedTwoCommodityIntegralFlow
share the same CLI fields. The merge with main created duplicates.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@zazabap zazabap self-requested a review March 16, 2026 14:40
@zazabap
Copy link
Collaborator

zazabap commented Mar 16, 2026

Final Review — Approved

Aspect Result
Comments All addressed (3 Copilot fixes by review pipeline, 1 coverage test added)
Usefulness Useful — GJ ND38, cornerstone of integral multicommodity flow NP-completeness
Safety Safe (README reverted, no unrelated changes)
Completeness Complete (18/18 structural checks, paper entry, CLI tests, trait consistency)
Quality 82% — clean implementation, CI all green, proper references

Fixes applied during final review:

  • Resolved merge conflicts with main (SteinerTree, SetBasis, LengthBoundedDisjointPaths, UndirectedTwoCommodityIntegralFlow)
  • Added coverage test for wrong-config-length early return
  • Reverted unrelated README.md changes
  • Removed duplicate CLI fields from merge (shared with UndirectedTwoCommodityIntegralFlow)

Copy link
Collaborator

@zazabap zazabap left a comment

Choose a reason for hiding this comment

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

Final review passed — all CI green, quality 82%.

@zazabap zazabap merged commit 47ea067 into main Mar 16, 2026
3 checks passed
Copy link
Collaborator

@zazabap zazabap left a comment

Choose a reason for hiding this comment

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

Final review passed.

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] DirectedTwoCommodityIntegralFlow

3 participants