use tracing::trace;
use super::{Features, cost_as_u64};
use crate::{ArrayIndex, Result};
pub(super) struct Scenario {
pub dataset: crate::dataset::Dataset,
#[allow(dead_code)]
features: Features,
#[allow(dead_code)]
cost_function: crate::CostFunction,
}
impl Scenario {
pub(super) fn new<P: AsRef<std::path::Path>>(
store_path: P,
cost_function: crate::cost::CostFunction,
cache_size: u64,
) -> Result<Self> {
trace!("Opening scenario with: {:?}", store_path.as_ref());
let features = Features::new(&store_path)?;
let dataset = crate::dataset::Dataset::open(store_path, cost_function.clone(), cache_size)?;
Ok(Self {
dataset,
features,
cost_function,
})
}
pub(super) fn get_3x3(&self, position: &ArrayIndex) -> Vec<(ArrayIndex, f32)> {
self.dataset.get_3x3(position)
}
pub(super) fn successors(&self, position: &ArrayIndex) -> Vec<(ArrayIndex, u64)> {
let neighbors = self.get_3x3(position);
let neighbors = neighbors
.into_iter()
.map(|(p, c)| (p, cost_as_u64(c))) .collect();
trace!("Adjusting neighbors' types: {:?}", neighbors);
neighbors
}
}