[lab3] Fixes after refactoring

This commit is contained in:
Andrew Golovashevich 2026-02-24 21:49:03 +03:00
parent 2b601e8d9a
commit 0e735f4db5
4 changed files with 23 additions and 23 deletions

View File

@ -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);
}
}
}

View File

@ -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,

View File

@ -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 {

View File

@ -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<Row<'s, 'u, It::Vertex<'s>>> {
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<It::RefType>
for RowsIterators<'u, It>
{
@ -156,6 +141,20 @@ struct TitleCell<'v, 'uu, 'u: 'uu, V: Vertex> {
update: &'uu mut <V::RefType as RefType>::Ref<'u, UpdatePending>,
}
impl<V: Vertex> _ConstMutSwitchUiCallback<V::RefType> for TitleCell<'_, '_, '_, V> {
fn render(self, ctx: &mut impl ConstMutSwitchUi<RefType = V::RefType>) {
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 <V::RefType as RefType>::Ref<'u, UpdatePending>,
}
impl<V: Vertex> _ConstMutSwitchUiCallback<V::RefType> for TitleCellH<'_, '_, '_, V> {
fn render(self, ctx: &mut impl ConstMutSwitchUi<RefType = V::RefType>) {
ctx.label(self.row_id.to_string().as_str());
ctx.button("-", self.update, |s| {