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`], [`SocwrOpfSolution`],
14//! [`McAcPfSolution`], [`McAcOpfSolution`], [`LinDist3FlowOpfSolution`], and
15//! [`AcScucSolution`].
16
17mod balanced;
18mod lindist3flow;
19mod multiconductor;
20mod scuc;
21mod socwr;
22
23pub use balanced::{
24    AcOpfSolution, AcPfSolution, DcOpfSolution, DcPfSolution, GeneratorDispatch,
25    ThreeWindingTransformerTerminalActivePower, ThreeWindingTransformerTerminalPower,
26};
27pub use lindist3flow::{LinDist3FlowOpfSolution, LinDist3FlowOpfValues};
28pub use multiconductor::{McAcOpfSolution, McAcPfSolution};
29pub use scuc::{
30    AcScucSolution, SCUC_DEVICE_OUTPUT_SERIES, SCUC_NETWORK_OUTPUT_SERIES, ScucDeviceOutputs,
31    ScucNetworkOutputs,
32};
33pub use socwr::{SocwrOpfDuals, SocwrOpfSolution, SocwrOpfValues};
34
35use serde::{Deserialize, Serialize};
36
37/// How the producing calculation ended.
38#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
39#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
40#[serde(rename_all = "snake_case", tag = "kind")]
41#[non_exhaustive]
42pub enum Termination {
43    /// The calculation converged to its stated tolerance.
44    Converged,
45    /// The iteration limit ended the calculation before convergence.
46    IterationLimit,
47    /// The solver proved the constraints admit no solution. The optimization
48    /// outcome an OPF consumer acts on differently from a numerical failure:
49    /// the case is overconstrained, and no retry or setting change fixes it.
50    Infeasible,
51    /// The solver proved the objective unbounded over the feasible set.
52    Unbounded,
53    /// The calculation failed.
54    Failed,
55    /// The source records a solved calculation without termination
56    /// information (DeepMind OPFData does).
57    #[default]
58    NotReported,
59}
60
61/// Numerical residuals of the solved equations, in the problem's power unit.
62/// A field is `None` when the producer did not report it.
63#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize)]
64#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
65#[non_exhaustive]
66pub struct Residuals {
67    /// Largest absolute active power balance mismatch, MW.
68    pub max_active_power_mismatch: Option<f64>,
69    /// Largest absolute reactive power balance mismatch, MVAr.
70    pub max_reactive_power_mismatch: Option<f64>,
71}
72
73/// The producer or solver identity a solution records, free text as the
74/// producer states it.
75pub type Producer = Option<String>;