Skip to content

Commit

Permalink
Remove external dependency in heuristic research crate
Browse files Browse the repository at this point in the history
  • Loading branch information
reinterpretcat committed Nov 28, 2024
1 parent 5b8723e commit 069338a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 0 additions & 1 deletion experiments/heuristic-research/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ plotters = "0.3.7"
plotters-canvas = "0.3.0"
itertools = "0.13.0"
wasm-bindgen = "0.2.95"
console_error_panic_hook = "0.1.7"
web-sys = { version = "0.3.72", features = ["HtmlCanvasElement", "console"] }
15 changes: 13 additions & 2 deletions experiments/heuristic-research/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,21 @@ lazy_static! {
static ref EXPERIMENT_DATA: Mutex<ExperimentData> = Mutex::new(ExperimentData::default());
}

#[inline]
fn set_panic_hook_once() {
use std::sync::Once;
static SET_HOOK: Once = Once::new();
SET_HOOK.call_once(|| {
std::panic::set_hook(Box::new(|info| {
web_sys::console::error_1(&info.to_string().into());
}));
});
}

/// Runs 3D functions experiment.
#[wasm_bindgen]
pub fn run_function_experiment(function_name: &str, population_type: &str, x: Float, z: Float, generations: usize) {
console_error_panic_hook::set_once();
set_panic_hook_once();
let selection_size = 8;
let logger = Arc::new(|message: &str| {
web_sys::console::log_1(&message.into());
Expand All @@ -102,7 +113,7 @@ pub fn run_function_experiment(function_name: &str, population_type: &str, x: Fl
/// Runs VRP experiment.
#[wasm_bindgen]
pub fn run_vrp_experiment(format_type: &str, problem: &str, population_type: &str, generations: usize) {
console_error_panic_hook::set_once();
set_panic_hook_once();
let problem = problem.to_string();
let selection_size = 8;
let logger = Arc::new(|message: &str| {
Expand Down

0 comments on commit 069338a

Please sign in to comment.