added progressbars

This commit is contained in:
2024-09-30 00:42:36 +02:00
parent 37cfe2eb2c
commit 69b35e6a38
15 changed files with 462 additions and 59 deletions
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "by-hand"
version = "0.1.0"
edition = "2021"
[dependencies]
indicatif = "0.17.8"
macroquad = "0.4.13"
+33
View File
@@ -0,0 +1,33 @@
use std::time::Instant;
use macroquad::{prelude::*, rand, ui::root_ui};
#[macroquad::main("by-hand")]
async fn main() {
println!("Hello, world!");
loop {
let start_update = Instant::now();
// update();
let update_elapsed = start_update.elapsed();
// Render
let start_render = Instant::now();
clear_background(WHITE);
// draw();
let render_elapsed = start_render.elapsed();
root_ui().label(
None,
format!("update: {:?}, render: {:?}", update_elapsed, render_elapsed).as_str(),
);
next_frame().await
}
}
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "dual-nums"
version = "0.1.0"
edition = "2021"
[dependencies]
nalgebra = "0.33.0"
num-dual = "0.9.1"
+15
View File
@@ -0,0 +1,15 @@
// use nalgebra::SVector;
// use num_dual::*;
// fn bar(x: DualSVec64<2>, y: DualSVec64<2>) -> DualSVec64<2> {
// x * x + y * y
// }
fn main() {
// // let result = bar(
// // DualSVec64::new(3.0, Derivative::some(SVector::from_vec(vec![1.0, 0.0]))),
// // DualSVec64::new(4.0, Derivative::some(SVector::from_vec(vec![0.0, 1.0]))),
// // );
// // println!("{:?}", result);
}
+19 -18
View File
@@ -71,26 +71,27 @@ impl<F: Field + Measure + Sum, const D: usize> StressMajorization<F, D> {
&mut self,
graph: &mut StableGraph<(N, Point<F, D>), E>,
) -> F {
graph
.node_indices()
.flat_map(|v| {
graph.node_indices().skip(v.index() + 1).map(move |w| {
let dist = nalgebra::distance(
&graph.node_weight(v).unwrap().1,
&graph.node_weight(w).unwrap().1,
);
// graph
// .node_indices()
// .flat_map(|v| {
// graph.node_indices().skip(v.index() + 1).map(move |w| {
// let dist = nalgebra::distance(
// &graph.node_weight(v).unwrap().1,
// &graph.node_weight(w).unwrap().1,
// );
if dist != F::zero() {
let dij = self.shortest_path_matrix[&v][&w];
// if dist != F::zero() {
// let dij = self.shortest_path_matrix[&v][&w];
let sp_diff = self.shortest_path_matrix[&v][&w] - dist;
dij.simd_sqrt().abs() * sp_diff * sp_diff
} else {
F::zero()
}
})
})
.sum()
// let sp_diff = self.shortest_path_matrix[&v][&w] - dist;
// dij.simd_sqrt().abs() * sp_diff * sp_diff
// } else {
// F::zero()
// }
// })
// })
// .sum()
F::default()
}
}
+1
View File
@@ -15,3 +15,4 @@ petgraph-gen = "0.1.3"
fdg = { git = "https://github.com/grantshandy/fdg" }
asd = { path = "../../" }
rayon = "1.10.0"
indicatif = "0.17.8"
+51
View File
@@ -0,0 +1,51 @@
use std::collections::HashMap;
struct Graph {
edges_from: Vec<u32>,
edges_to: Vec<u32>,
}
impl Graph {
fn new() -> Self {
Self {
edges_from: Vec::new(),
edges_to: Vec::new(),
}
}
fn new_with_capacity(capacity: usize) -> Self {
Self {
edges_from: Vec::with_capacity(capacity),
edges_to: Vec::with_capacity(capacity),
}
}
fn add_edge(&mut self, from: u32, to: u32) {
self.edges_from.push(from);
self.edges_to.push(to);
}
}
pub fn update(
graph: &Graph,
xs: &Vec<f32>,
ys: &Vec<f32>,
desired_distance_matrix: &HashMap<usize, HashMap<usize, f32>>,
) -> f32 {
desired_distance_matrix
.iter()
.flat_map(|(&i, targets)| {
targets
.iter()
.map(move |(&j, &target_distance)| (i, j, target_distance))
})
.map(|(i, j, target_distance)| {
let dx = xs[j] - xs[i];
let dy = ys[j] - ys[i];
let distance_sqrd = dx * dx + dy * dy;
let error = distance_sqrd - target_distance * target_distance;
error * error
})
.sum()
}
+20 -3
View File
@@ -1,12 +1,21 @@
use std::{collections::HashMap, env, ops::AddAssign, time::Instant};
use std::{
collections::HashMap,
env,
io::{BufRead, BufReader},
ops::AddAssign,
time::Instant,
};
use asd::{gfa::Entry, parser};
use indicatif::ProgressIterator;
use macroquad::{prelude::*, rand, ui::root_ui};
use nalgebra::{Point2, SVector};
use petgraph::{algo::dijkstra, graph::NodeIndex, stable_graph::StableGraph};
use rayon::prelude::*;
mod gd;
#[macroquad::main("graphs_1")]
async fn main() {
println!("Hello, world!");
@@ -127,8 +136,16 @@ fn load_graph() -> StableGraph<(String, Point2<f32>), ()> {
let mut graph = StableGraph::new();
let file = std::fs::File::open(env::args().nth(1).expect("missing gfa file argument")).unwrap();
let entries = parser::parse_source(file).unwrap();
let filename = env::args().nth(1).expect("missing gfa file argument");
let file_lines_count = BufReader::new(std::fs::File::open(&filename).expect("file not found"))
.lines()
.progress_with(indicatif::ProgressBar::new_spinner())
.count() as u64;
let file = std::fs::File::open(filename).unwrap();
let entries = parser::parse_source(file, file_lines_count).unwrap();
let mut index_map = HashMap::new();