use crate::transition::*;
use routers_network::{Entry, Metadata, Network};
const PRECISION: f64 = 100.0f64;
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 {
const EPSILON: f64 = 1e-6;
let v = self
.calculate(ctx)
.map_or(0.0, |v| v.into())
.clamp(EPSILON, 1.0);
let cost = (1.0 / v).powf(Self::BETA);
(PRECISION * Self::ZETA * cost) 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;
}