powerio_prob/instance/
constraints.rs1use serde::{Deserialize, Serialize};
9
10#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
13#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
14#[serde(rename_all = "snake_case", tag = "select", content = "identities")]
15#[non_exhaustive]
16pub enum ConstraintSelection {
17 #[default]
19 All,
20 None,
22 Only(Vec<String>),
24}
25
26impl ConstraintSelection {
27 #[must_use]
29 pub fn selects(&self, identity: &str) -> bool {
30 match self {
31 Self::All => true,
32 Self::None => false,
33 Self::Only(identities) => identities.iter().any(|selected| selected == identity),
34 }
35 }
36}
37
38#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
40#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
41#[non_exhaustive]
42pub struct ActiveConstraints {
43 pub generator_capability: ConstraintSelection,
45 pub voltage_bounds: ConstraintSelection,
47 pub thermal_limits: ConstraintSelection,
49 pub angle_bounds: ConstraintSelection,
51}
52
53#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
55#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
56#[non_exhaustive]
57pub struct MulticonductorActiveConstraints {
58 pub terminal_voltage_bounds: ConstraintSelection,
60 pub conductor_limits: ConstraintSelection,
62 pub generator_capability: ConstraintSelection,
64}
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69
70 #[test]
71 fn selections_answer_by_identity() {
72 assert!(ConstraintSelection::All.selects("branches:3"));
73 assert!(!ConstraintSelection::None.selects("branches:3"));
74 let only = ConstraintSelection::Only(vec!["branches:3".to_owned()]);
75 assert!(only.selects("branches:3"));
76 assert!(!only.selects("branches:4"));
77 }
78}