Skip to main content

powerio_prob/solution/
mod.rs

1//! The public calculation solutions.
2//!
3//! A solution contains values keyed by stable element identity, termination
4//! information, an objective where the problem has one, and numerical
5//! residuals — never a solver's variable ordering, factorization, cache, or
6//! internal status objects. Each solution shares the immutable instance it
7//! solves through shared ownership, just as each instance shares its network:
8//! one instance can carry zero, one, or several solutions from different
9//! equations, solvers, settings, or initial points, and
10//! `solution.clone()` duplicates neither its instance nor its network.
11//!
12//! The registered solutions include [`DcPfSolution`], [`AcPfSolution`],
13//! [`DcOpfSolution`], [`AcOpfSolution`], [`AcOtsSolution`], [`SocwrOpfSolution`],
14//! [`McAcPfSolution`], [`McAcOpfSolution`], [`LinDist3FlowOpfSolution`],
15//! [`LinDist3FlowPfSolution`], and [`AcScucSolution`].
16
17mod balanced;
18mod lindist3flow;
19mod multiconductor;
20mod ots;
21mod scuc;
22mod socwr;
23
24pub use balanced::{
25    AcOpfSolution, AcPfSolution, DcOpfSolution, DcPfSolution, GeneratorDispatch,
26    ThreeWindingTransformerTerminalActivePower, ThreeWindingTransformerTerminalPower,
27};
28pub use lindist3flow::{
29    LinDist3FlowLimitCheck, LinDist3FlowLimitKind, LinDist3FlowOpfSolution, LinDist3FlowOpfValues,
30    LinDist3FlowPfSolution, evaluate_lindist3flow_pf_limits,
31};
32pub use multiconductor::{McAcOpfSolution, McAcPfSolution};
33pub use ots::AcOtsSolution;
34pub use scuc::{
35    AcScucSolution, SCUC_DEVICE_OUTPUT_SERIES, SCUC_NETWORK_OUTPUT_SERIES, ScucDeviceOutputs,
36    ScucNetworkOutputs,
37};
38pub use socwr::{SocwrOpfDuals, SocwrOpfSolution, SocwrOpfValues};
39
40use serde::{Deserialize, Serialize};
41
42/// How the producing calculation ended.
43#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
44#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
45#[serde(rename_all = "snake_case", tag = "kind")]
46#[non_exhaustive]
47pub enum Termination {
48    /// The calculation converged to its stated tolerance.
49    Converged,
50    /// The iteration limit ended the calculation before convergence.
51    IterationLimit,
52    /// The solver proved the constraints admit no solution. The optimization
53    /// outcome an OPF consumer acts on differently from a numerical failure:
54    /// the case is overconstrained, and no retry or setting change fixes it.
55    Infeasible,
56    /// The solver proved the objective unbounded over the feasible set.
57    Unbounded,
58    /// The calculation failed.
59    Failed,
60    /// The source records a solved calculation without termination
61    /// information (DeepMind OPFData does).
62    #[default]
63    NotReported,
64}
65
66/// Numerical residuals of the solved equations, in the problem's power unit.
67/// A field is `None` when the producer did not report it.
68#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize)]
69#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
70#[non_exhaustive]
71pub struct Residuals {
72    /// Largest absolute active power balance mismatch, MW.
73    pub max_active_power_mismatch: Option<f64>,
74    /// Largest absolute reactive power balance mismatch, MVAr.
75    pub max_reactive_power_mismatch: Option<f64>,
76}
77
78/// The producer or solver identity a solution records, free text as the
79/// producer states it.
80pub type Producer = Option<String>;