pub trait GraphConstraint:
Clone
+ Send
+ Sync
+ 'static {
const NAME: &'static str;
const DESCRIPTION: &'static str;
const ENERGY_MODE: EnergyMode;
const SUBCATEGORY: GraphSubcategory;
const ALIASES: &'static [&'static str] = _;
const REDUCES_FROM: Option<&'static str> = None;
// Required method
fn edge_constraint_spec() -> [bool; 4];
// Provided methods
fn is_edge_satisfied(u_selected: bool, v_selected: bool) -> bool { ... }
fn problem_info() -> ProblemInfo { ... }
fn category() -> ProblemCategory { ... }
}Expand description
Trait defining the constraint semantics for a binary graph problem.
Implement this trait to define a new graph problem type. The trait specifies how edges constrain the selection of vertices and what the optimization objective is.
§Example
pub struct IndependentSetConstraint;
impl GraphConstraint for IndependentSetConstraint {
const NAME: &'static str = "Independent Set";
const DESCRIPTION: &'static str = "Find maximum weight set of non-adjacent vertices";
const ENERGY_MODE: EnergyMode = EnergyMode::LargerSizeIsBetter;
const SUBCATEGORY: GraphSubcategory = GraphSubcategory::Independent;
fn edge_constraint_spec() -> [bool; 4] {
[true, true, true, false] // (0,0), (0,1), (1,0) OK; (1,1) invalid
}
}Required Associated Constants§
Sourceconst DESCRIPTION: &'static str
const DESCRIPTION: &'static str
Brief description of the problem.
Sourceconst ENERGY_MODE: EnergyMode
const ENERGY_MODE: EnergyMode
Whether to maximize or minimize the objective.
Sourceconst SUBCATEGORY: GraphSubcategory
const SUBCATEGORY: GraphSubcategory
The graph subcategory this problem belongs to.
Provided Associated Constants§
Sourceconst ALIASES: &'static [&'static str] = _
const ALIASES: &'static [&'static str] = _
Alternative names for this problem (default: empty).
Sourceconst REDUCES_FROM: Option<&'static str> = None
const REDUCES_FROM: Option<&'static str> = None
The problem this canonically reduces from (default: None).
Required Methods§
Sourcefn edge_constraint_spec() -> [bool; 4]
fn edge_constraint_spec() -> [bool; 4]
The edge constraint specification.
Returns a 4-element array representing which (u_selected, v_selected) combinations are valid for an edge (u, v):
- Index 0: (0, 0) - neither endpoint selected
- Index 1: (0, 1) - only v selected
- Index 2: (1, 0) - only u selected
- Index 3: (1, 1) - both endpoints selected
Provided Methods§
Sourcefn is_edge_satisfied(u_selected: bool, v_selected: bool) -> bool
fn is_edge_satisfied(u_selected: bool, v_selected: bool) -> bool
Check if an edge is satisfied given endpoint selection states.
Default implementation uses edge_constraint_spec().
Sourcefn problem_info() -> ProblemInfo
fn problem_info() -> ProblemInfo
Get the problem info for this constraint type.
Sourcefn category() -> ProblemCategory
fn category() -> ProblemCategory
Get the problem category.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.