mahf-opt / mahf

A framework for modular construction and evaluation of metaheuristics.
GNU General Public License v3.0
10 stars 0 forks source link

Add a derive macro for `CustomState` #174

Open Saethox opened 1 year ago

Saethox commented 1 year ago
#[derive(CustomState)]
pub struct MyCustomState(f64);

should implement CustomState and better_any::Tid (or an equivalent). It should also handle a single lifetime and multiple generics correctly.

Saethox commented 1 year ago

A shortcut for exposing Component parameters would also be handy. Maybe something like this is possible with some proc-macro magic:

Annotate component fields with some attribute, which generates a SomeComponentMutationRate(f64) custom state struct:

#[derive(ExposedParameter)]
pub struct SomeComponent {
    #[expose(rename = "mutation_rate")]
    pub f64: rm,
}

The struct can then be referred to in Component methods using some Param![] macro:


fn execute(problem: &P, state: &mut State<P>) -> ExecResult<()> {
    let mutation_rate = state.get_value::<Param![SomeComponent::mutation_rate]>();
    ...
}

Maybe it's even possible to use Param![Self::mutation_rate] in SomeComponent.