Skip to main content

powerio_matrix/synth/
mod.rs

1//! Synthetic MATPOWER style cases. Stress tests the matrix builders beyond
2//! the vendored matpower test set.
3
4mod lattice;
5mod pegase_like;
6mod tree;
7
8pub use lattice::generate_lattice;
9pub use pegase_like::generate_pegase_like;
10pub use tree::generate_tree;
11
12use serde::{Deserialize, Serialize};
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
15pub enum Topology {
16    Tree,
17    Lattice2D,
18    PegaseLike,
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct SynthSpec {
23    pub topology: Topology,
24    pub n: usize,
25    /// Branch series resistance to reactance ratio.
26    pub r_over_x: f64,
27    /// Mean reactance per branch (p.u.).
28    pub mean_x: f64,
29    /// Random seed; identical seed → identical case.
30    pub seed: u64,
31}
32
33impl Default for SynthSpec {
34    fn default() -> Self {
35        Self {
36            topology: Topology::Tree,
37            n: 64,
38            r_over_x: 0.1,
39            mean_x: 0.05,
40            seed: 0x00C0_FFEE,
41        }
42    }
43}
44
45pub fn generate(spec: &SynthSpec) -> crate::network::Network {
46    match spec.topology {
47        Topology::Tree => generate_tree(spec),
48        Topology::Lattice2D => generate_lattice(spec),
49        Topology::PegaseLike => generate_pegase_like(spec),
50    }
51}