From 0e735f4db5e2ae2c9e7a31fdd3a44e49b5d13e53 Mon Sep 17 00:00:00 2001 From: Andrew Golovashevich Date: Tue, 24 Feb 2026 21:49:03 +0300 Subject: [PATCH] [lab3] Fixes after refactoring --- lab3/src/algo/update_state.rs | 3 ++- lab3/src/gui/graph.rs | 12 +++++----- lab3/src/main.rs | 2 +- utility/src/gui/graph_lengths_table/ui.rs | 29 +++++++++++------------ 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lab3/src/algo/update_state.rs b/lab3/src/algo/update_state.rs index aea0e79..20c3004 100644 --- a/lab3/src/algo/update_state.rs +++ b/lab3/src/algo/update_state.rs @@ -23,8 +23,9 @@ impl AntsSimulationState<'_> { match weighted_random(rng, &outbound_weights, |e| e.2) { None => {} Some((ei, nvi, _)) => { - self.ferments[*ei] += self._calculate_weight(*ei); + self.ferments[*ei] += self._calculate_ferment(*ei); ant.current_vertex = *nvi; + ant.allowed_vertices.remove(nvi); } } } diff --git a/lab3/src/gui/graph.rs b/lab3/src/gui/graph.rs index f691204..fa1d758 100644 --- a/lab3/src/gui/graph.rs +++ b/lab3/src/gui/graph.rs @@ -28,13 +28,13 @@ pub(crate) fn graph_with_controls( } fn draw_ants(ui: &mut Ui, vertex_locations: &mut [(f32, f32)], data: &mut AntsSimulationState) { - let mut cap: f64 = 0.000000000001; + let mut cap: f64 = data.cfg.q * (data.graph.vertex_count() as f64); - for w in data.graph.edges.iter_indexes().map(|i| data.ferments[i]) { - if w > cap { - cap = w - } - } + // for w in data.graph.edges.iter_indexes().map(|i| data.ferments[i]) { + // if w > cap { + // cap = w + // } + // } render_graph( ui, diff --git a/lab3/src/main.rs b/lab3/src/main.rs index 5611235..8a3b2ab 100644 --- a/lab3/src/main.rs +++ b/lab3/src/main.rs @@ -55,7 +55,7 @@ impl eframe::App for gui::AntsVisualisationApp { ants_per_vertex: *ants_per_vertex, vertex_locations: gui::gen_vertex_locations( &mut rng(), - (*graph).vertex_count(), + graph.vertices.capacity(), ), }; unsafe { diff --git a/utility/src/gui/graph_lengths_table/ui.rs b/utility/src/gui/graph_lengths_table/ui.rs index c9b79bd..00fc6a4 100644 --- a/utility/src/gui/graph_lengths_table/ui.rs +++ b/utility/src/gui/graph_lengths_table/ui.rs @@ -77,21 +77,6 @@ struct RowsIterators<'u, It: VerticesIterator> { row_id: usize, } -impl<'u, It: VerticesIterator> RowsIterators<'u, It> { - fn next<'s>(&'s mut self) -> Option>> { - match self.vertices.next() { - None => return None, - Some(v) => { - self.row_id += 1; - return Some(Row { - vertex: v, - row_id: self.row_id, - update: &mut self.update, - }); - } - } - } -} impl<'u, It: VerticesIterator> _ConstMutSwitchUiTableRowsIterator for RowsIterators<'u, It> { @@ -156,6 +141,20 @@ struct TitleCell<'v, 'uu, 'u: 'uu, V: Vertex> { update: &'uu mut ::Ref<'u, UpdatePending>, } impl _ConstMutSwitchUiCallback for TitleCell<'_, '_, '_, V> { + fn render(self, ctx: &mut impl ConstMutSwitchUi) { + ctx.horizontal(TitleCellH { + row_id: self.row_id, + vertex: self.vertex, + update: self.update, + }) + } +} +struct TitleCellH<'v, 'uu, 'u: 'uu, V: Vertex> { + row_id: usize, + vertex: &'v mut V, + update: &'uu mut ::Ref<'u, UpdatePending>, +} +impl _ConstMutSwitchUiCallback for TitleCellH<'_, '_, '_, V> { fn render(self, ctx: &mut impl ConstMutSwitchUi) { ctx.label(self.row_id.to_string().as_str()); ctx.button("-", self.update, |s| {