GraphConstraint

Trait GraphConstraint 

Source
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§

Source

const NAME: &'static str

The canonical name of this problem.

Source

const DESCRIPTION: &'static str

Brief description of the problem.

Source

const ENERGY_MODE: EnergyMode

Whether to maximize or minimize the objective.

Source

const SUBCATEGORY: GraphSubcategory

The graph subcategory this problem belongs to.

Provided Associated Constants§

Source

const ALIASES: &'static [&'static str] = _

Alternative names for this problem (default: empty).

Source

const REDUCES_FROM: Option<&'static str> = None

The problem this canonically reduces from (default: None).

Required Methods§

Source

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§

Source

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().

Source

fn problem_info() -> ProblemInfo

Get the problem info for this constraint type.

Source

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.

Implementors§

Source§

impl GraphConstraint for CliqueConstraint

Source§

const NAME: &'static str = "Clique"

Source§

const DESCRIPTION: &'static str = "Find a maximum clique (complete subgraph)"

Source§

const ENERGY_MODE: EnergyMode = EnergyMode::LargerSizeIsBetter

Source§

const SUBCATEGORY: GraphSubcategory = GraphSubcategory::Independent

Source§

const ALIASES: &'static [&'static str]

Source§

const REDUCES_FROM: Option<&'static str>

Source§

impl GraphConstraint for IndependentSetConstraint

Source§

const NAME: &'static str = "Independent Set"

Source§

const DESCRIPTION: &'static str = "Find a maximum weight set of non-adjacent vertices"

Source§

const ENERGY_MODE: EnergyMode = EnergyMode::LargerSizeIsBetter

Source§

const SUBCATEGORY: GraphSubcategory = GraphSubcategory::Independent

Source§

const ALIASES: &'static [&'static str]

Source§

const REDUCES_FROM: Option<&'static str>

Source§

impl GraphConstraint for VertexCoverConstraint

Source§

const NAME: &'static str = "Vertex Cover"

Source§

const DESCRIPTION: &'static str = "Find a minimum weight set of vertices covering all edges"

Source§

const ENERGY_MODE: EnergyMode = EnergyMode::SmallerSizeIsBetter

Source§

const SUBCATEGORY: GraphSubcategory = GraphSubcategory::Covering

Source§

const ALIASES: &'static [&'static str]

Source§

const REDUCES_FROM: Option<&'static str>