-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
no improvement, will come back in the future to see what I can do, co…
…mment, and clean up
- Loading branch information
Showing
2 changed files
with
47 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,65 @@ | ||
use crate::solver::Solver; | ||
use crate::sudoku::Sudoku; | ||
use std::fs::File; | ||
use std::io::Read; | ||
use std::path::Path; | ||
use std::thread::{JoinHandle, self}; | ||
use crate::solver::Solver; | ||
use crate::sudoku::Sudoku; | ||
pub(crate) struct SudokuTester{ | ||
pub response: Vec<String> | ||
use std::thread::{self, JoinHandle}; | ||
pub(crate) struct SudokuTester { | ||
pub response: Vec<String>, | ||
} | ||
|
||
impl SudokuTester { | ||
|
||
pub fn get_sudoku(&self,sudokus: &str) -> Vec<String>{ | ||
|
||
let sudokus_vec: Vec<String> = { | ||
let untreated = sudokus.split("\n"); | ||
let mut treated:Vec<String> = Vec::new(); | ||
for each in untreated{ | ||
treated.push(each.to_owned().trim_end().to_owned()); | ||
} | ||
treated | ||
}; | ||
sudokus_vec | ||
} | ||
fn treat_file(&mut self)-> String{ | ||
pub fn get_sudoku(&self, sudokus: &str) -> Vec<String> { | ||
let sudokus_vec: Vec<String> = { | ||
let untreated = sudokus.split("\n"); | ||
let mut treated: Vec<String> = Vec::new(); | ||
for each in untreated { | ||
treated.push(each.to_owned().trim_end().to_owned()); | ||
} | ||
treated | ||
}; | ||
sudokus_vec | ||
} | ||
fn treat_file(&mut self) -> String { | ||
let path = Path::new("data.txt"); | ||
let mut file = File::open(path).unwrap(); | ||
let mut bufreader = String::new(); | ||
let mut bufreader = String::new(); | ||
let ok = file.read_to_string(&mut bufreader); | ||
if let Ok(_ok) = ok{ | ||
return bufreader;} | ||
if let Ok(_ok) = ok { | ||
return bufreader; | ||
} | ||
"None".to_owned() | ||
} | ||
} | ||
|
||
pub(crate)fn test_performance(&mut self){ | ||
pub(crate) fn test_performance(&mut self) { | ||
let mut results: Vec<String> = Vec::new(); | ||
let treated = self.treat_file(); | ||
let unsolved = self.get_sudoku(&treated); | ||
let mut handles: Vec<JoinHandle<_>> = Vec::with_capacity(1000); | ||
for (i ,sud) in unsolved.into_iter().enumerate(){ | ||
let mut sudoku = Sudoku::new(sud,3usize); | ||
if (i+1)%5000 == 0{ | ||
for handle in handles{ | ||
let mut handles: Vec<JoinHandle<_>> = Vec::with_capacity(1000); | ||
for (i, sud) in unsolved.into_iter().enumerate() { | ||
let mut sudoku = Sudoku::new(sud, 3usize); | ||
if (i + 1) % 5000 == 0 { | ||
for handle in handles { | ||
let answer = handle.join().unwrap(); | ||
results.push(answer); | ||
} | ||
handles = Vec::new(); | ||
} | ||
|
||
let handle = thread::spawn(move || -> String{ | ||
let handle = thread::spawn(move || -> String { | ||
let answer = sudoku.solver(None); | ||
if let Some(answer) = answer{ | ||
if let Some(answer) = answer { | ||
return answer[0].clone(); | ||
} | ||
return "".to_owned() | ||
return "".to_owned(); | ||
}); | ||
handles.push(handle); | ||
} | ||
for handle in handles{ | ||
let answer = handle.join().unwrap(); | ||
results.push(answer); | ||
} | ||
} | ||
for handle in handles { | ||
let answer = handle.join().unwrap(); | ||
results.push(answer); | ||
} | ||
|
||
self.response = results; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
} |