Skip to content

Fix #572: [Model] GeneralizedHex#686

Open
GiggleLiu wants to merge 3 commits intomainfrom
issue-572-generalizedhex
Open

Fix #572: [Model] GeneralizedHex#686
GiggleLiu wants to merge 3 commits intomainfrom
issue-572-generalizedhex

Conversation

@GiggleLiu
Copy link
Contributor

@GiggleLiu GiggleLiu commented Mar 16, 2026

Summary

Add the GeneralizedHex graph model with a zero-variable memoized minimax evaluator, CLI creation support (--source/--sink and --random), focused unit coverage, the canonical example fixture, and the corresponding paper/reference updates.

Fixes #572

@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

❌ Patch coverage is 95.41667% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.03%. Comparing base (dfcc313) to head (2512ec8).

Files with missing lines Patch % Lines
src/models/graph/generalized_hex.rs 93.52% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #686      +/-   ##
==========================================
- Coverage   97.04%   97.03%   -0.02%     
==========================================
  Files         284      286       +2     
  Lines       38037    38277     +240     
==========================================
+ Hits        36914    37142     +228     
- Misses       1123     1135      +12     

☔ 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
Copy link
Contributor Author

Implementation Summary

Changes

  • Added GeneralizedHex as a graph model in src/models/graph/generalized_hex.rs and exported it through the graph/model preludes.
  • Added focused unit coverage in src/unit_tests/models/graph/generalized_hex.rs.
  • Extended CLI creation/help paths for GeneralizedHex, using --source and --sink for the terminal vertices.
  • Regenerated the example-db fixture and documented the model in the paper with supporting references.

Deviations from Plan

  • Implemented GeneralizedHex as a zero-variable SatisfactionProblem whose evaluate([]) runs memoized minimax over playable-vertex claim states. This preserves alternating-play semantics more directly than encoding move choices as static variables.
  • Corrected the issue's supplied YES example after independent minimax verification showed it is actually losing for the first player under optimal play. The paper/example now use a different winning instance.

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 graph game model, GeneralizedHex, to the problemreductions model registry and wires it through the CLI, examples/fixtures, and paper docs so it can be created, serialized, and evaluated like existing graph problems.

Changes:

  • Introduces the GeneralizedHex model (memoized minimax evaluator; dims() = []) with schema/variant registration and a canonical example.
  • Adds CLI support for pred create GeneralizedHex (including --source/--sink and --random generation) plus CLI tests.
  • Adds unit tests, example-db fixture entry, and paper documentation/references for the new model.

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/graph/generalized_hex.rs New GeneralizedHex model, schema registration, variants, and example-db hook
src/unit_tests/models/graph/generalized_hex.rs Unit tests covering construction, evaluation, solver behavior, and serde round-trip
src/models/graph/mod.rs Registers the new module/export and includes its canonical example spec
src/models/mod.rs Re-exports GeneralizedHex from the top-level models module
src/lib.rs Exposes GeneralizedHex in the crate prelude
problemreductions-cli/src/commands/create.rs Adds create + random-generation support for GeneralizedHex and CLI tests
problemreductions-cli/src/cli.rs Updates CLI help text to list GeneralizedHex flags and an example command
src/example_db/fixtures/examples.json Adds GeneralizedHex example fixture (and modifies other existing fixtures)
docs/paper/references.bib Adds citations relevant to Generalized Hex / Shannon switching game
docs/paper/reductions.typ Adds a paper section describing GeneralizedHex and its canonical instance

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

Comment on lines 409 to 415
if canonical == "LengthBoundedDisjointPaths" && field_name == "max_length" {
return "bound".to_string();
}
if canonical == "GeneralizedHex" && field_name == "target" {
return "sink".to_string();
}
field_name.replace('_', "-")
Comment on lines +253 to +260
if !config.is_empty() {
return false;
}
let playable_vertices = self.playable_vertices();
let vertex_to_state_index = self.vertex_to_state_index(&playable_vertices);
let mut state = vec![ClaimState::Unclaimed; playable_vertices.len()];
let mut memo = HashMap::new();
self.first_player_wins(&mut state, &vertex_to_state_index, &mut memo)
{"source":{"problem":"LongestCommonSubsequence","variant":{},"instance":{"strings":[[65,66,65,67],[66,65,67,65]]}},"target":{"problem":"ILP","variant":{"variable":"bool"},"instance":{"constraints":[{"cmp":"Le","rhs":1.0,"terms":[[0,1.0],[1,1.0]]},{"cmp":"Le","rhs":1.0,"terms":[[2,1.0]]},{"cmp":"Le","rhs":1.0,"terms":[[3,1.0],[4,1.0]]},{"cmp":"Le","rhs":1.0,"terms":[[5,1.0]]},{"cmp":"Le","rhs":1.0,"terms":[[2,1.0]]},{"cmp":"Le","rhs":1.0,"terms":[[0,1.0],[3,1.0]]},{"cmp":"Le","rhs":1.0,"terms":[[5,1.0]]},{"cmp":"Le","rhs":1.0,"terms":[[1,1.0],[4,1.0]]},{"cmp":"Le","rhs":1.0,"terms":[[0,1.0],[2,1.0]]},{"cmp":"Le","rhs":1.0,"terms":[[1,1.0],[2,1.0]]},{"cmp":"Le","rhs":1.0,"terms":[[1,1.0],[3,1.0]]},{"cmp":"Le","rhs":1.0,"terms":[[1,1.0],[5,1.0]]},{"cmp":"Le","rhs":1.0,"terms":[[4,1.0],[5,1.0]]}],"num_vars":6,"objective":[[0,1.0],[1,1.0],[2,1.0],[3,1.0],[4,1.0],[5,1.0]],"sense":"Maximize"}},"solutions":[{"source_config":[0,1,1,1],"target_config":[0,0,1,1,0,1]}]},
{"source":{"problem":"MaxCut","variant":{"graph":"SimpleGraph","weight":"i32"},"instance":{"edge_weights":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"graph":{"inner":{"edge_property":"undirected","edges":[[0,1,null],[0,4,null],[0,5,null],[1,2,null],[1,6,null],[2,3,null],[2,7,null],[3,4,null],[3,8,null],[4,9,null],[5,7,null],[5,8,null],[6,8,null],[6,9,null],[7,9,null]],"node_holes":[],"nodes":[null,null,null,null,null,null,null,null,null,null]}}}},"target":{"problem":"SpinGlass","variant":{"graph":"SimpleGraph","weight":"i32"},"instance":{"couplings":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"fields":[0,0,0,0,0,0,0,0,0,0],"graph":{"inner":{"edge_property":"undirected","edges":[[0,1,null],[0,4,null],[0,5,null],[1,2,null],[1,6,null],[2,3,null],[2,7,null],[3,4,null],[3,8,null],[4,9,null],[5,7,null],[5,8,null],[6,8,null],[6,9,null],[7,9,null]],"node_holes":[],"nodes":[null,null,null,null,null,null,null,null,null,null]}}}},"solutions":[{"source_config":[0,1,0,1,0,1,0,0,0,1],"target_config":[0,1,0,1,0,1,0,0,0,1]}]},
{"source":{"problem":"MaxCut","variant":{"graph":"SimpleGraph","weight":"i32"},"instance":{"edge_weights":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"graph":{"inner":{"edge_property":"undirected","edges":[[0,1,null],[0,4,null],[0,5,null],[1,2,null],[1,6,null],[2,3,null],[2,7,null],[3,4,null],[3,8,null],[4,9,null],[5,7,null],[5,8,null],[6,8,null],[6,9,null],[7,9,null]],"node_holes":[],"nodes":[null,null,null,null,null,null,null,null,null,null]}}}},"target":{"problem":"SpinGlass","variant":{"graph":"SimpleGraph","weight":"i32"},"instance":{"couplings":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"fields":[0,0,0,0,0,0,0,0,0,0],"graph":{"inner":{"edge_property":"undirected","edges":[[0,1,null],[0,4,null],[0,5,null],[1,2,null],[1,6,null],[2,3,null],[2,7,null],[3,4,null],[3,8,null],[4,9,null],[5,7,null],[5,8,null],[6,8,null],[6,9,null],[7,9,null]],"node_holes":[],"nodes":[null,null,null,null,null,null,null,null,null,null]}}}},"solutions":[{"source_config":[1,0,1,0,0,0,0,0,1,1],"target_config":[1,0,1,0,0,0,0,0,1,1]}]},
{"source":{"problem":"MaximumClique","variant":{"graph":"SimpleGraph","weight":"i32"},"instance":{"graph":{"inner":{"edge_property":"undirected","edges":[[0,1,null],[0,2,null],[0,3,null],[0,4,null],[1,2,null],[1,3,null],[1,5,null],[2,4,null],[2,5,null],[3,4,null],[3,5,null],[4,5,null]],"node_holes":[],"nodes":[null,null,null,null,null,null]}},"weights":[1,1,1,1,1,1]}},"target":{"problem":"ILP","variant":{"variable":"bool"},"instance":{"constraints":[{"cmp":"Le","rhs":1.0,"terms":[[0,1.0],[5,1.0]]},{"cmp":"Le","rhs":1.0,"terms":[[1,1.0],[4,1.0]]},{"cmp":"Le","rhs":1.0,"terms":[[2,1.0],[3,1.0]]}],"num_vars":6,"objective":[[0,1.0],[1,1.0],[2,1.0],[3,1.0],[4,1.0],[5,1.0]],"sense":"Maximize"}},"solutions":[{"source_config":[1,1,1,0,0,0],"target_config":[1,1,1,0,0,0]}]},
Comment on lines +1 to +5
//! Generalized Hex problem implementation.
//!
//! Generalized Hex asks whether the first player has a forced win in the
//! vertex-claiming Shannon switching game on an undirected graph.

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

2 participants