use std::collections::HashMap;
use allocative::Allocative;
use serde::{Deserialize, Serialize};
use crate::model::unit::Cost;
#[derive(Serialize, Deserialize, Default, Clone, Debug, Allocative)]
pub struct TraversalCost {
pub objective_cost: Cost,
pub total_cost: Cost,
pub cost_component: HashMap<String, Cost>,
}
impl TraversalCost {
pub fn insert(&mut self, name: &str, cost: Cost, weight: f64) {
let positive_cost = Cost::enforce_strictly_positive(cost);
self.total_cost += positive_cost;
self.objective_cost += positive_cost * weight;
self.cost_component
.entry(name.to_string())
.and_modify(|v| *v += positive_cost)
.or_insert(positive_cost);
}
}