61 lines
1.8 KiB
Rust
61 lines
1.8 KiB
Rust
use crate::algo::GeneticSimulationConfig;
|
|
use bgtu_ai_utility::gui::const_mut_switch::{
|
|
ConstMutSwitchUi, RefType, _ConstMutSwitchUiCallback,
|
|
};
|
|
use bgtu_ai_utility::gui::graph_lengths_table::{draw_lengths_table, Graph};
|
|
use bgtu_ai_utility::UpdatePending;
|
|
|
|
|
|
pub(crate) fn input<Ctx: ConstMutSwitchUi>(
|
|
ctx: &mut Ctx,
|
|
mut config: <Ctx::RefType as RefType>::Ref<'_, GeneticSimulationConfig>,
|
|
graph: &mut impl Graph<RefType = Ctx::RefType>,
|
|
mut population_size: <Ctx::RefType as RefType>::Ref<'_, usize>,
|
|
mut generations_count: <Ctx::RefType as RefType>::Ref<'_, usize>,
|
|
mut vertex_update: <Ctx::RefType as RefType>::Ref<'_, UpdatePending>,
|
|
mut launch: <Ctx::RefType as RefType>::Ref<'_, bool>,
|
|
) {
|
|
ctx.labeled_slider("Population size", 1..=100, 1.0, &mut population_size);
|
|
|
|
ctx.space();
|
|
|
|
ctx.labeled_slider("Generations", 1..=100, 1.0, &mut generations_count);
|
|
|
|
ctx.space();
|
|
|
|
ctx.labeled_slider(
|
|
"Mutation chance",
|
|
0.0..=1.0,
|
|
0.001,
|
|
&mut Ctx::RefType::_get(
|
|
&mut config,
|
|
|config| &config.mutation_chance,
|
|
|config| &mut config.mutation_chance,
|
|
),
|
|
);
|
|
|
|
ctx.space();
|
|
|
|
ctx.space();
|
|
|
|
ctx.horizontal(ControlsRow {
|
|
update: &mut vertex_update,
|
|
run: &mut launch,
|
|
});
|
|
|
|
draw_lengths_table(ctx, graph, vertex_update)
|
|
}
|
|
|
|
struct ControlsRow<'uu, 'u, 'rr, 'r, RT: RefType> {
|
|
update: &'uu mut RT::Ref<'u, UpdatePending>,
|
|
run: &'rr mut RT::Ref<'r, bool>,
|
|
}
|
|
|
|
impl<RT: RefType> _ConstMutSwitchUiCallback<RT> for ControlsRow<'_, '_, '_, '_, RT> {
|
|
fn render(self, ctx: &mut impl ConstMutSwitchUi<RefType = RT>) {
|
|
ctx.button("Add vertex", self.update, |d| *d = UpdatePending::Add);
|
|
ctx.separator();
|
|
ctx.button("Run", self.run, |d| *d = true);
|
|
}
|
|
}
|