use crate::problem::traits::Problem;
use crate::solution_set::traits::SolutionSet;
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CaseParameter {
pub key: String,
pub value: String,
}
impl CaseParameter {
pub fn new(key: impl Into<String>, value: impl Into<String>) -> Self {
Self {
key: key.into(),
value: value.into(),
}
}
}
impl fmt::Display for CaseParameter {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}={}", self.key, self.value)
}
}
pub trait ExperimentalCase<T, Q, P>: Send + Sync
where
T: Clone + Send + 'static,
Q: Clone + Default + Send + 'static + Copy + Into<f64>,
P: Problem<T, Q> + Sync,
{
fn algorithm_name(&self) -> &str;
fn case_name(&self) -> String {
self.algorithm_name().to_string()
}
fn parameters(&self) -> Vec<CaseParameter>;
fn parameters_as_text(&self) -> String {
self.parameters()
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<_>>()
.join(", ")
}
fn run(&self, problem: &P) -> Result<Box<dyn SolutionSet<T, Q>>, String>;
}