-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Description
Motivation
Problem types like KColoring, MaximumIndependentSet, MaxCut, etc. currently have new(num_vertices, edges) constructors that internally construct a SimpleGraph. This makes the problem "pretend to be a graph" and hides the graph topology type from the constructor signature.
Current pattern
// Graph construction is hidden inside the problem
let problem = MaximumIndependentSet::<SimpleGraph, i32>::new(4, vec![(0, 1), (1, 2)]);Proposed pattern
// Graph is an explicit input — topology type is clear
let graph = SimpleGraph::new(4, vec![(0, 1), (1, 2)]);
let problem = MaximumIndependentSet::new(graph, weights);Benefits:
- Graph topology type is reflected in the constructor signature
- Problems don't duplicate graph construction logic
from_graphbecomesnew, which is more idiomatic- Works naturally with non-SimpleGraph topologies (UnitDiskGraph, GridGraph, etc.)
Affected types (9 total)
All in src/models/graph/:
| Type | Current constructor |
|---|---|
MaximumIndependentSet |
new(num_vertices, edges) |
MinimumVertexCover |
new(num_vertices, edges) |
MinimumDominatingSet |
new(num_vertices, edges) |
MaximumClique |
new(num_vertices, edges) |
MaximalIS |
new(num_vertices, edges) |
KColoring |
new(num_vertices, edges) |
MaxCut |
new(num_vertices, edges_with_weights) |
MaximumMatching |
new(num_vertices, edges_with_weights) |
TravelingSalesman |
new(num_vertices, edges_with_weights) |
Each already has a from_graph(graph, ...) constructor that takes the graph directly. The refactoring would:
- Remove
new(num_vertices, edges) - Rename
from_graph→new - Update all call sites (tests, examples, reductions)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels