Skip to content

Commit 8e5b748

Browse files
committed
Add warning for assets that are not a multiple of the unit size
1 parent 79bf6f6 commit 8e5b748

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/input/asset.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ use crate::process::ProcessMap;
77
use crate::region::RegionID;
88
use crate::units::Capacity;
99
use anyhow::{Context, Result, ensure};
10+
use float_cmp::approx_eq;
1011
use indexmap::IndexSet;
1112
use itertools::Itertools;
13+
use log::warn;
1214
use serde::Deserialize;
1315
use std::path::Path;
1416
use std::rc::Rc;
@@ -103,6 +105,24 @@ where
103105
asset.agent_id,
104106
);
105107

108+
// Check that capacity is approximately a multiple of the process unit size
109+
// If not, raise a warning
110+
if let Some(unit_size) = process.unit_size {
111+
let ratio = (asset.capacity / unit_size).value();
112+
if !approx_eq!(f64, ratio, ratio.ceil()) {
113+
let n_units = ratio.ceil();
114+
warn!(
115+
"Asset capacity {} for process {} is not a multiple of unit size {}. \
116+
Asset will be divided into {} units with combined capacity of {}.",
117+
asset.capacity,
118+
asset.process_id,
119+
unit_size,
120+
n_units,
121+
unit_size.value() * n_units
122+
);
123+
}
124+
}
125+
106126
Asset::new_future_with_max_decommission(
107127
agent_id.clone(),
108128
Rc::clone(process),

0 commit comments

Comments
 (0)