1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
// use std::io::{self, BufRead};
use rayon::prelude::*;
use sqlx::migrate::MigrateDatabase;
// use std::sync::{Arc, Mutex};
use std::time::Instant;
use tokio;
mod graph;
use crate::graph::Graph;
mod theorems;
// use crate::theorems::{basic, forbidden, toughness};
mod geng;
use crate::geng::GengIterator;
mod compute;
#[tokio::main]
async 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()));
// 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: Vec<_> = gi.par_bridge().map(compute::apply_theorems).collect();
// let res: Vec<_> =
// gi.par_bridge().map(compute::dominating_numbers).collect();
let res: Vec<_> = gi.map(compute::dominating_numbers).collect();
for pair in &res {
if let Some(cardinality) = pair.1 {
if pair.2 != 0 {
println!("{} {:?} {}", pair.0, cardinality, pair.2);
}
}
}
// for (a, b) in &res {
// println!("{a} {b:?}");
// }
// 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
// .par_bridge()
// .map(compute::apply_theorems)
// .collect::<Vec<_>>();
//
// let elapsed = start.elapsed();
// let time = elapsed.as_nanos();
// println!("len = {}", res.len());
// println!("Time elapsed: {}s", time as f64 / 1e9);
/*
println!("Total count of graphs: {}", counters.graphs);
println!("Count of 1-tough graphs: {}", counters.tough_1);
println!("Count of 2-tough graphs: {}", counters.tough_2);
println!(
"Count of Dirac's Hamiltonian graphs: {}",
counters.dirac_hamiltonian
);
println!(
"Count of Ore's Hamiltonian graphs: {}",
counters.ore_hamiltonian
);
println!(
"Count of Posa's Hamiltonian graphs: {}",
counters.posa_hamiltonian
);
println!(
"Count of Bondy-Chvatal Hamiltonian graphs: {}",
counters.bch_hamiltonian
);
println!(
"Count of Theorem 15 Hamiltonian graphs: {}",
counters.t15_hamiltonian
);
println!(
"Count of Theorem 25 Hamiltonian graphs: {}",
counters.t25_hamiltonian
);
*/
Ok(())
}
|