[lab3] Fixes after refactoring
This commit is contained in:
parent
2b601e8d9a
commit
0e735f4db5
@ -23,8 +23,9 @@ impl AntsSimulationState<'_> {
|
|||||||
match weighted_random(rng, &outbound_weights, |e| e.2) {
|
match weighted_random(rng, &outbound_weights, |e| e.2) {
|
||||||
None => {}
|
None => {}
|
||||||
Some((ei, nvi, _)) => {
|
Some((ei, nvi, _)) => {
|
||||||
self.ferments[*ei] += self._calculate_weight(*ei);
|
self.ferments[*ei] += self._calculate_ferment(*ei);
|
||||||
ant.current_vertex = *nvi;
|
ant.current_vertex = *nvi;
|
||||||
|
ant.allowed_vertices.remove(nvi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,13 +28,13 @@ pub(crate) fn graph_with_controls(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn draw_ants(ui: &mut Ui, vertex_locations: &mut [(f32, f32)], data: &mut AntsSimulationState) {
|
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]) {
|
// for w in data.graph.edges.iter_indexes().map(|i| data.ferments[i]) {
|
||||||
if w > cap {
|
// if w > cap {
|
||||||
cap = w
|
// cap = w
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
render_graph(
|
render_graph(
|
||||||
ui,
|
ui,
|
||||||
|
|||||||
@ -55,7 +55,7 @@ impl eframe::App for gui::AntsVisualisationApp {
|
|||||||
ants_per_vertex: *ants_per_vertex,
|
ants_per_vertex: *ants_per_vertex,
|
||||||
vertex_locations: gui::gen_vertex_locations(
|
vertex_locations: gui::gen_vertex_locations(
|
||||||
&mut rng(),
|
&mut rng(),
|
||||||
(*graph).vertex_count(),
|
graph.vertices.capacity(),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|||||||
@ -77,21 +77,6 @@ struct RowsIterators<'u, It: VerticesIterator> {
|
|||||||
row_id: usize,
|
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>
|
impl<'u, It: VerticesIterator> _ConstMutSwitchUiTableRowsIterator<It::RefType>
|
||||||
for RowsIterators<'u, It>
|
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>,
|
update: &'uu mut <V::RefType as RefType>::Ref<'u, UpdatePending>,
|
||||||
}
|
}
|
||||||
impl<V: Vertex> _ConstMutSwitchUiCallback<V::RefType> for TitleCell<'_, '_, '_, V> {
|
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>) {
|
fn render(self, ctx: &mut impl ConstMutSwitchUi<RefType = V::RefType>) {
|
||||||
ctx.label(self.row_id.to_string().as_str());
|
ctx.label(self.row_id.to_string().as_str());
|
||||||
ctx.button("-", self.update, |s| {
|
ctx.button("-", self.update, |s| {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user