Skip to main content

powerio_matrix/synth/
mod.rs

1//! Deterministic synthetic network generators.
2//!
3//! Compatibility facade for the historical `powerio_matrix::synth` API.
4//! The implementation lives in `powerio-synth`, while these public types
5//! remain defined in this crate so downstream code retains its original type
6//! identity, constructor signatures, defaults, and Serde representation.
7
8use powerio_tx::BalancedNetwork;
9use serde::{Deserialize, Serialize};
10
11/// Topology produced by a synthetic network generator.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
13pub enum Topology {
14    Tree,
15    Lattice2D,
16    PegaseLike,
17}
18
19/// Parameters for a deterministic synthetic network.
20#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct SynthSpec {
22    pub topology: Topology,
23    pub n: usize,
24    /// Branch series resistance to reactance ratio.
25    pub r_over_x: f64,
26    /// Mean reactance per branch (p.u.).
27    pub mean_x: f64,
28    /// Random seed; identical seed produces an identical case.
29    pub seed: u64,
30}
31
32impl Default for SynthSpec {
33    fn default() -> Self {
34        Self {
35            topology: Topology::Tree,
36            n: 64,
37            r_over_x: 0.1,
38            mean_x: 0.05,
39            seed: 0x00C0_FFEE,
40        }
41    }
42}
43
44fn implementation_spec(
45    spec: &SynthSpec,
46    topology: powerio_synth::Topology,
47) -> powerio_synth::SynthSpec {
48    powerio_synth::SynthSpec {
49        topology,
50        n: spec.n,
51        r_over_x: spec.r_over_x,
52        mean_x: spec.mean_x,
53        seed: spec.seed,
54    }
55}
56
57/// Generate a deterministic network using the requested topology.
58pub fn generate(spec: &SynthSpec) -> BalancedNetwork {
59    match spec.topology {
60        Topology::Tree => generate_tree(spec),
61        Topology::Lattice2D => generate_lattice(spec),
62        Topology::PegaseLike => generate_pegase_like(spec),
63    }
64}
65
66/// Generate a tree-shaped network.
67pub fn generate_tree(spec: &SynthSpec) -> BalancedNetwork {
68    powerio_synth::generate_tree(&implementation_spec(spec, powerio_synth::Topology::Tree))
69}
70
71/// Generate a two-dimensional lattice network.
72pub fn generate_lattice(spec: &SynthSpec) -> BalancedNetwork {
73    powerio_synth::generate_lattice(&implementation_spec(
74        spec,
75        powerio_synth::Topology::Lattice2D,
76    ))
77}
78
79/// Generate a PEGASE-like synthetic network.
80pub fn generate_pegase_like(spec: &SynthSpec) -> BalancedNetwork {
81    powerio_synth::generate_pegase_like(&implementation_spec(
82        spec,
83        powerio_synth::Topology::PegaseLike,
84    ))
85}