use crate::transition::*;
use core::f64::consts::E;
use routers_network::{Entry, Metadata, Network};
const PRECISION: f64 = 1_000.0f64;
const OFFSET: f64 = E;
pub trait Strategy<Ctx> {
type Cost: Into<f64>;
const ZETA: f64;
const BETA: f64;
fn calculate(&self, context: Ctx) -> Option<Self::Cost>;
#[inline(always)]
fn cost(&self, ctx: Ctx) -> u32 {
let multiplier = 1.0 / Self::ZETA;
let cost = -self.calculate(ctx).map_or(f64::INFINITY, |v| v.into()) / Self::BETA;
let shifted = ((multiplier * cost.exp()) - OFFSET).max(0.);
(PRECISION * shifted) as u32
}
}
pub trait Costing<Emission, Transition, E, M, N>
where
E: Entry,
M: Metadata,
N: Network<E, M>,
Transition: TransitionStrategy<E, M, N>,
Emission: EmissionStrategy,
{
fn emission(&self, context: EmissionContext) -> u32;
fn transition(&self, context: TransitionContext<E, M, N>) -> u32;
}