summaryrefslogtreecommitdiff
path: root/graph-checker/src
diff options
context:
space:
mode:
Diffstat (limited to 'graph-checker/src')
-rw-r--r--graph-checker/src/graph.rs1
-rw-r--r--graph-checker/src/gui.rs83
-rw-r--r--graph-checker/src/main.rs76
3 files changed, 130 insertions, 30 deletions
diff --git a/graph-checker/src/graph.rs b/graph-checker/src/graph.rs
index a4390d4..db27547 100644
--- a/graph-checker/src/graph.rs
+++ b/graph-checker/src/graph.rs
@@ -7,6 +7,7 @@ pub struct Graph {
pub matrix: Vec<Vec<u32>>,
}
+#[derive(Debug)]
pub struct GraphProfile {
g6: String,
stats: HashMap<String, bool>,
diff --git a/graph-checker/src/gui.rs b/graph-checker/src/gui.rs
new file mode 100644
index 0000000..2a363e2
--- /dev/null
+++ b/graph-checker/src/gui.rs
@@ -0,0 +1,83 @@
+use crate::compute;
+use crate::geng::GengIterator;
+use crate::graph;
+use eframe::egui;
+use std::sync::mpsc;
+use std::time::{Duration, Instant};
+use tokio;
+
+pub fn run_gui(rt: tokio::runtime::Runtime) {
+ let options = eframe::NativeOptions::default();
+ let _ = eframe::run_native(
+ "Graph checker",
+ options,
+ Box::new(|_cc| Ok(Box::new(Application::new(rt)))),
+ );
+}
+
+struct Application {
+ rt: tokio::runtime::Runtime,
+}
+
+impl Application {
+ fn new(rt: tokio::runtime::Runtime) -> Self {
+ Self { rt }
+ }
+}
+
+impl eframe::App for Application {
+ fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
+ let mut c = ComputeWindow::new(&self.rt);
+ egui::Window::new("Spawn tasks").show(ctx, |ui| {
+ c.update(ui);
+ });
+ }
+}
+
+struct ComputeWindow<'a> {
+ rt: &'a tokio::runtime::Runtime,
+ computed: Vec<graph::GraphProfile>,
+ rx: mpsc::Receiver<graph::GraphProfile>,
+ tx: mpsc::Sender<graph::GraphProfile>,
+}
+
+impl<'a> ComputeWindow<'a> {
+ fn new(rt: &'a tokio::runtime::Runtime) -> Self {
+ let (tx, rx) = mpsc::channel();
+ Self {
+ rt,
+ computed: Vec::new(),
+ rx,
+ tx,
+ }
+ }
+
+ fn update(&mut self, ui: &mut egui::Ui) {
+ if ui.button("Посчитать графы").clicked() {
+ let gi = GengIterator::new(7);
+ let _tasks: Vec<_> = gi
+ .map(|g| {
+ // let db = db.clone();
+ let tx = self.tx.clone();
+ self.rt.spawn(async move {
+ tx.send(compute::async_theorems1(g).await).unwrap();
+ })
+ })
+ .collect();
+ }
+
+ if let Ok(p) = self.rx.recv_timeout(Duration::from_millis(10)) {
+ self.computed.push(p);
+ }
+
+ ui.label(format!("Посчитано графов: {}", self.computed.len()));
+
+ // let start = Instant::now();
+ // let res = futures::future::join_all(tasks).await;
+ // let elapsed = start.elapsed();
+ // let time = elapsed.as_nanos();
+ // let res = res.iter().map(|e| e.as_ref().unwrap()).collect::<Vec<_>>();
+ // println!("len = {}", res.len());
+ // println!("Time elapsed: {}s", time as f64 / 1e9);
+ }
+}
diff --git a/graph-checker/src/main.rs b/graph-checker/src/main.rs
index a62143c..e73b23b 100644
--- a/graph-checker/src/main.rs
+++ b/graph-checker/src/main.rs
@@ -1,6 +1,6 @@
// use std::io::{self, BufRead};
use rayon::prelude::*;
-use sqlx::migrate::MigrateDatabase;
+use sqlx::{migrate::MigrateDatabase, Pool, Sqlite};
// use std::sync::{Arc, Mutex};
use std::time::Instant;
use tokio;
@@ -16,41 +16,55 @@ use crate::geng::GengIterator;
mod compute;
-#[tokio::main]
-async fn main() -> Result<(), sqlx::Error> {
+mod gui;
+
+fn main() -> Result<(), sqlx::Error> {
dotenv::dotenv().ok();
- let database_url =
- std::env::var("DATABASE_URL").expect("Expected DATABASE_URL in env");
- if !sqlx::Sqlite::database_exists(&database_url).await? {
- sqlx::Sqlite::create_database(&database_url).await?;
- }
- let db = sqlx::SqlitePool::connect(&database_url).await?;
- let _ = sqlx::query!(
- "CREATE TABLE IF NOT EXISTS graphs (g6 VARCHAR NOT NULL);"
- )
- .execute(&db)
- .await;
- // let mut counters = Arc::new(Mutex::new(Counters::new()));
+ let rt = tokio::runtime::Builder::new_multi_thread()
+ .enable_all()
+ .build()
+ .unwrap();
- // gi.par_bridge().for_each(|_| {});
+ let db = rt.block_on(async {
+ let database_url = std::env::var("DATABASE_URL")
+ .expect("Expected DATABASE_URL in env");
+ if !sqlx::Sqlite::database_exists(&database_url).await? {
+ sqlx::Sqlite::create_database(&database_url).await?;
+ }
+ let db = sqlx::SqlitePool::connect(&database_url).await?;
+ let _ = sqlx::query!(
+ "CREATE TABLE IF NOT EXISTS graphs (g6 VARCHAR NOT NULL);"
+ )
+ .execute(&db)
+ .await;
+ Ok::<Pool<Sqlite>, sqlx::Error>(db)
+ })?;
- let gi = GengIterator::new(9);
+ gui::run_gui(rt);
+ // let gui_task = tokio::spawn(gui::run_gui());
+ println!("next");
- let start = Instant::now();
- let tasks: Vec<_> = gi
- .map(|g| {
- // let db = db.clone();
- tokio::spawn(compute::async_theorems1(g))
- })
- .collect();
+ // let mut counters = Arc::new(Mutex::new(Counters::new()));
- let res = futures::future::join_all(tasks).await;
- let elapsed = start.elapsed();
- let time = elapsed.as_nanos();
- let res = res.iter().map(|e| e.as_ref().unwrap()).collect::<Vec<_>>();
- println!("len = {}", res.len());
- println!("Time elapsed: {}s", time as f64 / 1e9);
+ // gi.par_bridge().for_each(|_| {});
+
+ // let gi = GengIterator::new(7);
+ //
+ // let start = Instant::now();
+ // let tasks: Vec<_> = gi
+ // .map(|g| {
+ // // let db = db.clone();
+ // tokio::spawn(compute::async_theorems1(g))
+ // })
+ // .collect();
+ //
+ // let res = futures::future::join_all(tasks).await;
+ // let elapsed = start.elapsed();
+ // let time = elapsed.as_nanos();
+ // let res = res.iter().map(|e| e.as_ref().unwrap()).collect::<Vec<_>>();
+ // println!("len = {}", res.len());
+ // println!("Time elapsed: {}s", time as f64 / 1e9);
// let start = Instant::now();
// let res = gi
@@ -63,6 +77,8 @@ async fn main() -> Result<(), sqlx::Error> {
// println!("len = {}", res.len());
// println!("Time elapsed: {}s", time as f64 / 1e9);
+ // let _ = gui_task.await;
+
/*
println!("Total count of graphs: {}", counters.graphs);
println!("Count of 1-tough graphs: {}", counters.tough_1);