#[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)]
pub enum InflowNonNegativityMethod {
None,
Truncation,
Penalty,
TruncationWithPenalty,
}
impl InflowNonNegativityMethod {
#[must_use]
pub fn has_slack_columns(&self) -> bool {
matches!(
self,
InflowNonNegativityMethod::Penalty | InflowNonNegativityMethod::TruncationWithPenalty
)
}
}
impl From<&cobre_io::config::InflowNonNegativityConfig> for InflowNonNegativityMethod {
fn from(cfg: &cobre_io::config::InflowNonNegativityConfig) -> Self {
match cfg.method {
cobre_io::config::InflowNonNegativityMethod::None => InflowNonNegativityMethod::None,
cobre_io::config::InflowNonNegativityMethod::Truncation => {
InflowNonNegativityMethod::Truncation
}
cobre_io::config::InflowNonNegativityMethod::Penalty => {
InflowNonNegativityMethod::Penalty
}
cobre_io::config::InflowNonNegativityMethod::TruncationWithPenalty => {
InflowNonNegativityMethod::TruncationWithPenalty
}
}
}
}
#[cfg(test)]
mod tests {
use super::InflowNonNegativityMethod;
use cobre_io::config::{InflowNonNegativityConfig, InflowNonNegativityMethod as CfgMethod};
#[test]
fn none_has_no_slack_columns() {
assert!(!InflowNonNegativityMethod::None.has_slack_columns());
}
#[test]
fn truncation_has_no_slack_columns() {
assert!(!InflowNonNegativityMethod::Truncation.has_slack_columns());
}
#[test]
fn penalty_has_slack_columns() {
assert!(InflowNonNegativityMethod::Penalty.has_slack_columns());
}
#[test]
fn test_inflow_method_conversion_none() {
let cfg = InflowNonNegativityConfig {
method: CfgMethod::None,
};
assert_eq!(
InflowNonNegativityMethod::from(&cfg),
InflowNonNegativityMethod::None
);
}
#[test]
fn test_inflow_method_conversion_penalty() {
let cfg = InflowNonNegativityConfig {
method: CfgMethod::Penalty,
};
assert_eq!(
InflowNonNegativityMethod::from(&cfg),
InflowNonNegativityMethod::Penalty
);
}
#[test]
fn test_inflow_method_conversion_truncation() {
let cfg = InflowNonNegativityConfig {
method: CfgMethod::Truncation,
};
assert_eq!(
InflowNonNegativityMethod::from(&cfg),
InflowNonNegativityMethod::Truncation
);
}
#[test]
fn truncation_with_penalty_has_slack_columns() {
assert!(InflowNonNegativityMethod::TruncationWithPenalty.has_slack_columns());
}
#[test]
fn test_inflow_method_conversion_truncation_with_penalty() {
let cfg = InflowNonNegativityConfig {
method: CfgMethod::TruncationWithPenalty,
};
assert_eq!(
InflowNonNegativityMethod::from(&cfg),
InflowNonNegativityMethod::TruncationWithPenalty
);
}
}