Skip to main content

impl_variant_reduction

Macro impl_variant_reduction 

Source
macro_rules! impl_variant_reduction {
    ($problem:ident,
     < $($src_param:ty),+ > => < $($dst_param:ty),+ >,
     fields: [$($field:ident),+],
     $(aggregate: $aggregate:ident,)?
     |$src:ident| $body:expr) => { ... };
}
Expand description

Generates an explicit same-model variant ReduceTo implementation.

Variant reductions convert a problem from one variant to another (e.g., MIS<KingsSubgraph, i64> -> MIS<UnitDiskGraph, i64>). The solution mapping is identity – vertex/element indices are preserved.

The problem name is specified once, followed by <SourceParams> => <TargetParams>. This works with any number of type parameters.

§Example

impl_variant_reduction!(
    MaximumIndependentSet,
    <KingsSubgraph, i64> => <UnitDiskGraph, i64>,
    fields: [num_vertices, num_edges],
    |src| MaximumIndependentSet::new(
        SimpleGraph::new(src.num_vertices(), Graph::edges(src.graph())),
        src.weights())
);